diff --git a/rest-app/db.sqlite3 b/rest-app/db.sqlite3 index 02b81c5..0aeefde 100644 Binary files a/rest-app/db.sqlite3 and b/rest-app/db.sqlite3 differ diff --git a/rest-app/smartpicasso/app/user/__pycache__/models.cpython-38.pyc b/rest-app/smartpicasso/app/user/__pycache__/models.cpython-38.pyc index 7a0885a..af42249 100644 Binary files a/rest-app/smartpicasso/app/user/__pycache__/models.cpython-38.pyc and b/rest-app/smartpicasso/app/user/__pycache__/models.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/app/user/tests.py b/rest-app/smartpicasso/app/user/tests.py index cc52c1c..9f664c1 100644 --- a/rest-app/smartpicasso/app/user/tests.py +++ b/rest-app/smartpicasso/app/user/tests.py @@ -1,11 +1,11 @@ from django.test import TestCase from django.urls import reverse +from rest_framework import serializers from rest_framework import status from rest_framework.test import APITestCase, APIClient -from smartpicasso.app.user.models import User -from smartpicasso.app.user.serializers import UserLoginSerializer -from rest_framework import serializers +from smartpicasso.app.user.models import User, UserManager +from smartpicasso.app.user.serializers import UserLoginSerializer, UserRegistrationSerializer class UserApiTest(APITestCase): @@ -46,3 +46,42 @@ class UserLoginSerializerTest(TestCase): result = self.serializer.validate(data) self.assertEqual(result['email'], 'test@test.com') self.assertIn('token', result) + + +class UserRegistrationSerializerTest(TestCase): + serializer = UserRegistrationSerializer() + + def test_create(self): + profile = {"first_name": "test", "last_name": "test"} + user = self.serializer.create({"email": "test@test.com", "password": "test", "profile": profile}) + + self.assertNotEqual(user, None) + self.assertEqual(user.email, "test@test.com") + + +class UserManagerTest(TestCase): + manager = User.objects + + def test_create_user_none_email(self): + email = None + self.assertRaises(ValueError, self.manager.create_user, email) + + def test_create_user(self): + user = self.manager.create_user("test@test.pl", "test") + self.assertNotEqual(user, None) + self.assertEqual(user.email, "test@test.pl") + self.assertEqual(user.is_active, True) + self.assertEqual(user.is_superuser, False) + self.assertEqual(user.is_staff, False) + + def test_create_superuser_none_password(self): + password = None + self.assertRaises(TypeError, self.manager.create_superuser, "super@test.pl", password) + + def test_create_superuser(self): + user = self.manager.create_superuser("super@test.pl", "test") + self.assertNotEqual(user, None) + self.assertEqual(user.email, "super@test.pl") + self.assertEqual(user.is_active, True) + self.assertEqual(user.is_superuser, True) + self.assertEqual(user.is_staff, True)