From 1c6089b6749b9f06a65e70677ad92e66d0feca07 Mon Sep 17 00:00:00 2001 From: s460930 Date: Tue, 1 Dec 2020 19:02:07 +0100 Subject: [PATCH] SMART-30 tests for authenticate endpoint --- rest-app/smartpicasso/app/__init__.py | 0 rest-app/smartpicasso/app/user/tests.py | 22 ++++++++++++++++++++-- rest-app/smartpicasso/app/user/urls.py | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 rest-app/smartpicasso/app/__init__.py diff --git a/rest-app/smartpicasso/app/__init__.py b/rest-app/smartpicasso/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rest-app/smartpicasso/app/user/tests.py b/rest-app/smartpicasso/app/user/tests.py index 7ce503c..5e8f2b9 100644 --- a/rest-app/smartpicasso/app/user/tests.py +++ b/rest-app/smartpicasso/app/user/tests.py @@ -1,3 +1,21 @@ -from django.test import TestCase +from rest_framework.test import APITestCase, APIClient +from django.urls import reverse +from smartpicasso.app.user.models import User +from rest_framework import status -# Create your tests here. + +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) diff --git a/rest-app/smartpicasso/app/user/urls.py b/rest-app/smartpicasso/app/user/urls.py index 66bf079..f12a788 100644 --- a/rest-app/smartpicasso/app/user/urls.py +++ b/rest-app/smartpicasso/app/user/urls.py @@ -7,5 +7,5 @@ from django.conf.urls import url from smartpicasso.app.user.views import UserLoginView urlpatterns = [ - url(r'^authenticate', UserLoginView.as_view()) + url(r'^authenticate', UserLoginView.as_view(), name='authenticate') ]