From d3238f50c29cd59e9bc629f2f302529bfc798d81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=88=C3=90=D0=92=D0=B8=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=20=D0=93=D0=BB=D0=B0=D0=B4=D0=BA=D0=B8=D1=85=C3=90?= Date: Thu, 19 Sep 2019 17:06:38 +0300 Subject: [PATCH] add login test --- apps/authorization/tests.py | 3 --- apps/authorization/tests/__init__.py | 0 apps/authorization/tests/tests.py | 26 ++++++++++++++++++++++++-- apps/establishment/tests.py | 28 ++++++---------------------- 4 files changed, 30 insertions(+), 27 deletions(-) delete mode 100644 apps/authorization/tests.py delete mode 100644 apps/authorization/tests/__init__.py diff --git a/apps/authorization/tests.py b/apps/authorization/tests.py deleted file mode 100644 index 7ce503c2..00000000 --- a/apps/authorization/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/apps/authorization/tests/__init__.py b/apps/authorization/tests/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/apps/authorization/tests/tests.py b/apps/authorization/tests/tests.py index 7ce503c2..839af828 100644 --- a/apps/authorization/tests/tests.py +++ b/apps/authorization/tests/tests.py @@ -1,3 +1,25 @@ -from django.test import TestCase - +from rest_framework.test import APITestCase +from account.models import User # Create your tests here. + + +class AuthorizationTests(APITestCase): + + def setUp(self): + self.username = 'sedragurda' + self.password = 'sedragurdaredips19' + self.email = 'sedragurda@desoz.com' + self.newsletter = True + self.user = User.objects.create_user(username=self.username, email=self.email, password=self.password) + self.tokkens = User.create_jwt_tokens(self.user) + + def LoginTests(self): + data ={ + 'username_or_email': self.username, + 'password': self.password, + 'remember': True + } + response = self.client.post('/api/auth/login/', data=data) + self.assertEqual(response.data['access_token'], self.tokkens.get('access_token')) + self.assertEqual(response.data['refresh_token'], self.tokkens.get('refresh_token')) + diff --git a/apps/establishment/tests.py b/apps/establishment/tests.py index b6d72564..29218fd7 100644 --- a/apps/establishment/tests.py +++ b/apps/establishment/tests.py @@ -1,4 +1,4 @@ -from rest_framework.test import APITestCase, APIClient +from rest_framework.test import APITestCase from account.models import User from rest_framework import status from http.cookies import SimpleCookie @@ -15,30 +15,14 @@ class BaseTestCase(APITestCase): self.user = User.objects.create_user(username=self.username, email=self.email, password=self.password) #get tokkens tokkens = User.create_jwt_tokens(self.user) - self.access_token = tokkens.get('access_token') - self.refresh_token = tokkens.get('refresh_token') - - # print('access_token: ' + self.access_token) + self.client.cookies = SimpleCookie({'access_token': tokkens.get('access_token'), + 'refresh_token': tokkens.get('refresh_token')}) - # def getAuthInfo(self): - # data ={ - # 'username_or_email': self.username, - # 'password': self.password, - # 'remember': True - # } - # response = self.client.post('/api/auth/login/', data=data) - # - # return { - # 'access_token': response.data['access_token'], - # 'refresh_token': response.data['refresh_token'] - # } class EmployeeTests(BaseTestCase): - def test_employee_create(self): - self.client.cookies = SimpleCookie({'access_token':self.access_token, - 'refresh_token': self.refresh_token}) - + def test_employee_list(self): response = self.client.get('/api/back/establishments/employees/', format='json') - self.assertEqual(response.status_code, status.HTTP_200_OK) \ No newline at end of file + self.assertEqual(response.status_code, status.HTTP_200_OK) +