<reponame>ExiaSR/hyperion<gh_stars>1-10
from django.test import TestCase
from django.contrib.auth.models import User


class AuthTestCase(TestCase):
    def test_signup(self):
        post_body_u1 = {
            "username": "test",
            "email": "<EMAIL>",
            "password": "<PASSWORD>",
        }
        response = self.client.post(
            '/auth/signup', post_body_u1, content_type='application/json')

        self.assertEqual(response.status_code, 201)
        # print(response.data)
        test_user = User.objects.get(username="test")
        self.assertTrue(test_user.check_password("<PASSWORD>"))
        self.assertFalse(test_user.is_active)
        self.assertEqual(test_user.username, "test")
        self.assertEqual(test_user.email, "<EMAIL>")

        # log in with right password, but not be verified by admin
        login = self.client.login(username='test', password='<PASSWORD>')
        self.assertFalse(login)

        # activate author
        test_user.is_active = True
        test_user.save()

        # log in with right password
        login = self.client.login(username='test', password='<PASSWORD>')
        self.assertTrue(login)

        #  log in with wrong password
        login = self.client.login(username='test', password='<PASSWORD>')
        self.assertFalse(login)

        # sign up with wrong format
        post_body_u2 = {
            "username": "test2",
            "email": "sfds",
            "password": "<PASSWORD>",
        }
        response = self.client.post(
            '/auth/signup', post_body_u2, content_type='application/json')
        self.assertEqual(response.status_code, 400)
        # print(response.data)

from django.test import TestCase
from django.contrib.auth.models import User


class AuthTestCase(TestCase):
    def test_signup(self):
        post_body_u1 = {
            "username": "test",
            "email": "<EMAIL>",
            "password": "<PASSWORD>",
        }
        response = self.client.post(
            '/auth/signup', post_body_u1, content_type='application/json')

        self.assertEqual(response.status_code, 201)
        # print(response.data)
        test_user = User.objects.get(username="test")
        self.assertTrue(test_user.check_password("<PASSWORD>"))
        self.assertFalse(test_user.is_active)
        self.assertEqual(test_user.username, "test")
        self.assertEqual(test_user.email, "<EMAIL>")

        # log in with right password, but not be verified by admin
        login = self.client.login(username='test', password='<PASSWORD>')
        self.assertFalse(login)

        # activate author
        test_user.is_active = True
        test_user.save()

        # log in with right password
        login = self.client.login(username='test', password='<PASSWORD>')
        self.assertTrue(login)

        #  log in with wrong password
        login = self.client.login(username='test', password='<PASSWORD>')
        self.assertFalse(login)

        # sign up with wrong format
        post_body_u2 = {
            "username": "test2",
            "email": "sfds",
            "password": "<PASSWORD>",
        }
        response = self.client.post(
            '/auth/signup', post_body_u2, content_type='application/json')
        self.assertEqual(response.status_code, 400)
        # print(response.data)
# print(response.data) # log in with right password, but not be verified by admin # activate author # log in with right password #  log in with wrong password # sign up with wrong format # print(response.data)