SMART-39 tests for UserLoginSerializer

This commit is contained in:
s460930 2020-12-01 23:25:45 +01:00
parent 18957651b8
commit 0415872173

View File

@ -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)