2020-12-01 19:25:25 +01:00
|
|
|
from django.test import TestCase
|
2020-12-01 19:02:07 +01:00
|
|
|
from django.urls import reverse
|
|
|
|
from rest_framework import status
|
2020-12-01 19:25:25 +01:00
|
|
|
from rest_framework.test import APITestCase, APIClient
|
|
|
|
|
|
|
|
from smartpicasso.app.user.models import User
|
2020-11-30 22:10:22 +01:00
|
|
|
|
2020-12-01 19:02:07 +01:00
|
|
|
|
|
|
|
class UserApiTest(APITestCase):
|
|
|
|
client = APIClient()
|
|
|
|
|
|
|
|
def test_login_when_user_non_exist(self):
|
|
|
|
url = reverse('authenticate')
|
|
|
|
response = self.client.post(url, {'email': 'non-exist', 'password': '123'}, format='json')
|
|
|
|
assert response.status_code == 400
|
|
|
|
|
|
|
|
def test_login_when_user_exist(self):
|
|
|
|
User.objects.create_user(email='test@test.com', password='test')
|
|
|
|
url = reverse('authenticate')
|
|
|
|
response = self.client.post(url, {'email': 'test@test.com', 'password': 'test'}, format='json')
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
self.assertEqual(response.data['success'], 'True')
|
|
|
|
self.assertIn('token', response.data)
|
2020-12-01 19:25:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
class UserTest(TestCase):
|
|
|
|
|
|
|
|
def test_user_str(self):
|
|
|
|
email = 'test@test.com'
|
|
|
|
user = User.objects.create_user(email=email, password='test')
|
|
|
|
self.assertEqual(str(user), email)
|