backend #2

Merged
s460930 merged 5 commits from backend into develop 2020-12-05 19:08:57 +01:00
Showing only changes of commit 0415872173 - Show all commits

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)