From 041587217304425545447a3b6704b7a73cc332ff Mon Sep 17 00:00:00 2001 From: s460930 Date: Tue, 1 Dec 2020 23:25:45 +0100 Subject: [PATCH] SMART-39 tests for UserLoginSerializer --- rest-app/smartpicasso/app/user/tests.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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)