diff --git a/rest-app/smartpicasso/app/user/tests.py b/rest-app/smartpicasso/app/user/tests.py index a33d137..cc52c1c 100644 --- a/rest-app/smartpicasso/app/user/tests.py +++ b/rest-app/smartpicasso/app/user/tests.py @@ -4,6 +4,8 @@ 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 class UserApiTest(APITestCase): @@ -29,3 +31,18 @@ class UserTest(TestCase): email = 'test@test.com' user = User.objects.create_user(email=email, password='test') self.assertEqual(str(user), email) + + +class UserLoginSerializerTest(TestCase): + serializer = UserLoginSerializer() + + def test_validate_wrong_credentials(self): + data = {'email': 'test@test.com', 'password': '123'} + self.assertRaises(serializers.ValidationError, self.serializer.validate, data) + + def test_validate_success(self): + User.objects.create_user(email='test@test.com', password='test') + data = {'email': 'test@test.com', 'password': 'test'} + result = self.serializer.validate(data) + self.assertEqual(result['email'], 'test@test.com') + self.assertIn('token', result)