diff --git a/seeVcam/authentication/tests/test_authentication_mechanism.py b/seeVcam/authentication/tests/test_authentication_mechanism.py index 630d2bd7..2d4617bd 100644 --- a/seeVcam/authentication/tests/test_authentication_mechanism.py +++ b/seeVcam/authentication/tests/test_authentication_mechanism.py @@ -1,8 +1,8 @@ from django.test import TestCase, Client from rest_framework import status -from authentication.models import SeevcamUser from django.conf import settings +from common.helpers.test_helper import create_user, create_company class AuthenticationTest(TestCase): @@ -10,12 +10,12 @@ class AuthenticationTest(TestCase): DASHBOARD_URL = '/dashboard/' def setUp(self): - self._create_dummy_user("giuseppe", "password") + self.user = create_user(create_company()) self.client = Client() def test_dashboard_cannot_be_access_by_unauthenticated_user(self): response = self.client.get(self.DASHBOARD_URL) - self.assertEqual(response.status_code, status.HTTP_301_MOVED_PERMANENTLY) + self.assertEqual(response.status_code, status.HTTP_302_FOUND) def test_dashboard_cannot_be_access_by_unauthenticated_user_redirect_to_login(self): response = self.client.get(self.DASHBOARD_URL, follow=True) @@ -32,11 +32,5 @@ def test_dashboard_can_be_access_by_a_authenticated_user(self): response = self.client.get(self.DASHBOARD_URL, follow=True) self.assertEqual(response.status_code, status.HTTP_200_OK) - # PRIVATE - def _create_dummy_user(self, username, password): - user = SeevcamUser.objects.create_user(username, password=password) - user.save() - return user - def _log_in_dummy_user(self, username, password): self.client.post(settings.LOGIN_URL, {'username': username, 'password': password}) diff --git a/seeVcam/authentication/tests/test_user_model.py b/seeVcam/authentication/tests/test_user_model.py index af095c63..97c77876 100644 --- a/seeVcam/authentication/tests/test_user_model.py +++ b/seeVcam/authentication/tests/test_user_model.py @@ -1,18 +1,13 @@ from django.test import TestCase from authentication.models import SeevcamUser +from common.helpers.test_helper import create_company class UserTest(TestCase): - def setUp(self): - pass def test_creation_of_a_seevcamuser(self): - user = SeevcamUser.objects.create_user('test_username', email=None, password='test_pwd', - job_title='test_job_title', first_name='test_first_name', - last_name='test_last_name', pk=1) + company = create_company() + user = SeevcamUser.objects.create_user("test@test.com", 'test_pwd', company) user.save() - user_from_db = SeevcamUser.objects.get(pk=1) - self.assertEqual('test_username', user_from_db.username) - self.assertEqual('test_job_title', user_from_db.job_title) - self.assertEqual('test_first_name', user_from_db.first_name) - self.assertEqual('test_last_name', user_from_db.last_name) + user_from_db = SeevcamUser.objects.get(pk=user.id) + self.assertEqual('test@test.com', user_from_db.email) diff --git a/seeVcam/questions/tests/test_catalogue_crud_view.py b/seeVcam/questions/tests/test_catalogue_crud_view.py index 45eb5701..56758ec0 100644 --- a/seeVcam/questions/tests/test_catalogue_crud_view.py +++ b/seeVcam/questions/tests/test_catalogue_crud_view.py @@ -5,6 +5,7 @@ from django.conf import settings from authentication.models import SeevcamUser +from common.helpers.test_helper import create_user from questions.models import QuestionCatalogue, Question @@ -106,8 +107,8 @@ def test_user_can_update_a_question_in_a_catalogue(self): # PRIVATE # ############################################################# - def _create_dummy_user(self, username, password): - user = SeevcamUser.objects.create_user(username, password=password) + def _create_dummy_user(self, username): + user = create_user(self.company, username, 'test') user.save() return user diff --git a/seeVcam/questions/tests/test_rest_views.py b/seeVcam/questions/tests/test_rest_views.py index 167855db..6fa63966 100644 --- a/seeVcam/questions/tests/test_rest_views.py +++ b/seeVcam/questions/tests/test_rest_views.py @@ -3,6 +3,7 @@ from unittest import skip from authentication.models import SeevcamUser +from common.helpers.test_helper import create_company, create_user from questions.models import QuestionCatalogue, Question @@ -18,9 +19,12 @@ def setUp(self): self.SEEVCAM_CATALOGUE_PATH = self.CATALOG_PATH + 'seevcam/' self.QUESTION_PATH_LIST = '/dashboard/questions/catalogue/{0}/list/' self.QUESTION_PATH_DETAILS = '/dashboard/questions/catalogue/{0}/list/{1}/' - self.user_1 = QuestionCatalogueViewTests._create_user('user_1') - self.user_2 = QuestionCatalogueViewTests._create_user('user_2') - self.admin = QuestionCatalogueViewTests._create_user('admin', True) + self.company = create_company() + + self.user_1 = self._create_user('user_1@test.com') + self.user_2 = self._create_user('user_2@test.com') + self.admin = self._create_user('admin@test.com', True) + QuestionCatalogueViewTests._create_catalogues(self.user_1, 10) QuestionCatalogueViewTests._create_catalogues(self.user_2, 5) QuestionCatalogueViewTests._create_catalogues(self.admin, 3, QuestionCatalogue.SEEVCAM_SCOPE) @@ -235,9 +239,8 @@ def test_a_user_cannot_delete_a_question_in_the_seevcam_catalgoue(self): # PRIVATE # ############################################################# - @staticmethod - def _create_user(username, admin=False): - user = SeevcamUser(username=username, email='tests@email.com') + def _create_user(self, email, admin=False): + user = create_user(self.company, email, 'test') user.is_staff = admin user.save() return user