from django.test import TestCase
from django.test.client import Client

from users.models import User

class LoginPageTest(TestCase):
    def setUp(self):
        self.client = Client()
        self.user_email = "<EMAIL>"
        self.user_password = "<PASSWORD>"
        self.invalid_password = "<PASSWORD>

        self.user = User.objects.create_user(
                email = self.user_email,
                password = self.user_password,
                )

        # need to find more eloquent way to test redirect url.
        self.TEST_SERVER_URL = "http://testserver"

    # Default Set function, These are not Unit Test function
    def post_login_set(self, user_email="", user_password="", follow = False):
        response = self.client.post(
                   "/login/", {
                       "email" : user_email,
                       "password" : <PASSWORD>,
                       },
                       follow = follow
                   )
        return response

    # Test Code for Default Set function
    def test_post_login_set(self):
        self.post_login_set(self.user_email, self.user_password)

    def test_logout(self):
        self.post_login_set(self.user_email, self.user_password)
        response = self.client.post("/logout/", follow=True)
        self.assertRedirects(
            response,
            "/login/?next=/",
            301,
        )
        

from django.test import TestCase
from django.test.client import Client

from users.models import User

class LoginPageTest(TestCase):
    def setUp(self):
        self.client = Client()
        self.user_email = "<EMAIL>"
        self.user_password = "<PASSWORD>"
        self.invalid_password = "<PASSWORD>

        self.user = User.objects.create_user(
                email = self.user_email,
                password = self.user_password,
                )

        # need to find more eloquent way to test redirect url.
        self.TEST_SERVER_URL = "http://testserver"

    # Default Set function, These are not Unit Test function
    def post_login_set(self, user_email="", user_password="", follow = False):
        response = self.client.post(
                   "/login/", {
                       "email" : user_email,
                       "password" : <PASSWORD>,
                       },
                       follow = follow
                   )
        return response

    # Test Code for Default Set function
    def test_post_login_set(self):
        self.post_login_set(self.user_email, self.user_password)

    def test_logout(self):
        self.post_login_set(self.user_email, self.user_password)
        response = self.client.post("/logout/", follow=True)
        self.assertRedirects(
            response,
            "/login/?next=/",
            301,
        )
        

# need to find more eloquent way to test redirect url. # Default Set function, These are not Unit Test function # Test Code for Default Set function