Skip to content
Snippets Groups Projects
Commit fbf5fea5 authored by Carlos Vega's avatar Carlos Vega
Browse files

refactor as Piotr proposed

parent d0fd4b42
No related branches found
No related tags found
1 merge request!192Feature/add way to change password and PERMISSIONS
Pipeline #7577 canceled
......@@ -32,6 +32,18 @@ class LoggedInTestCase(TestCase):
username=username, email='jacob@bla', password=password)
self.client.login(username=username, password=password)
def login_as_staff():
self.client.logout()
self.client.login(username='staff', password=self.password)
def login_as_admin():
self.client.logout()
self.client.login(username='admin', password=self.password)
def login_as_super():
self.client.logout()
self.client.login(username='super', password=self.password)
class LoggedInWithWorkerTestCase(LoggedInTestCase):
def setUp(self):
......
......@@ -7,14 +7,12 @@ logger = logging.getLogger(__name__)
class ConfigurationViewTests(LoggedInTestCase):
def test_visit_details_request(self):
self.client.logout()
self.client.login(username='admin', password=self.password)
self.login_as_admin()
response = self.client.get(reverse('web.views.configuration'))
self.assertEqual(response.status_code, 200)
def test_visit_details_request_without_permissions(self):
self.client.logout()
self.client.login(username='staff', password=self.password)
self.login_as_staff()
response = self.client.get(reverse('web.views.configuration'))
self.assertEqual(response.status_code, 302)
......@@ -16,8 +16,7 @@ logger = logging.getLogger(__name__)
class WorkerViewTests(LoggedInTestCase):
def test_render_workers_list_request(self):
self.client.logout()
self.client.login(username='staff', password=self.password)
self.login_as_staff()
create_worker()
......@@ -25,8 +24,7 @@ class WorkerViewTests(LoggedInTestCase):
self.assertEqual(response.status_code, 200)
def test_render_worker_type_request(self):
self.client.logout()
self.client.login(username='staff', password=self.password)
self.login_as_staff()
create_worker()
......@@ -38,8 +36,7 @@ class WorkerViewTests(LoggedInTestCase):
self.assertEqual(response.status_code, 200)
def test_render_add_worker_request(self):
self.client.logout()
self.client.login(username='admin', password=self.password)
self.login_as_admin()
response = self.client.get(reverse('web.views.worker_add', kwargs={'worker_type': WORKER_STAFF}))
self.assertEqual(response.status_code, 200)
......@@ -49,8 +46,7 @@ class WorkerViewTests(LoggedInTestCase):
self.assertEqual(response.status_code, 302)
def test_render_add_worker_request_for_voucher_partner(self):
self.client.logout()
self.client.login(username='admin', password=self.password)
self.login_as_admin()
response = self.client.get(reverse('web.views.worker_add', kwargs={'worker_type': WORKER_VOUCHER_PARTNER}))
self.assertEqual(response.status_code, 200)
......@@ -59,8 +55,7 @@ class WorkerViewTests(LoggedInTestCase):
self.assertEqual(3, Worker.objects.all().count())
self.assertEqual(4, User.objects.all().count())
self.client.logout()
self.client.login(username='admin', password=self.password)
self.login_as_admin()
language = create_language()
location = create_location()
......@@ -115,8 +110,7 @@ class WorkerViewTests(LoggedInTestCase):
return form_data
def test_render_edit_worker_request(self):
self.client.logout()
self.client.login(username='admin', password=self.password)
self.login_as_admin()
worker = create_worker()
form_data = self.get_form_data(worker)
......@@ -130,35 +124,30 @@ class WorkerViewTests(LoggedInTestCase):
self.assertEqual(updated_worker.last_name, form_data["last_name"])
def test_edit_worker_superuser(self):
self.client.logout()
self.client.login(username='super', password=self.password)
self.login_as_super()
response = self.client.get(reverse('web.views.worker_edit', args=[self.super_worker.id]))
self.assertEqual(response.status_code, 200)
def test_edit_worker_without_permissions(self):
self.client.logout()
self.client.login(username='staff', password=self.password)
self.login_as_staff()
response = self.client.get(reverse('web.views.worker_edit', args=[self.staff_worker.id]))
self.assertEqual(response.status_code, 302)
def test_edit_worker_with_permissions(self):
self.client.logout()
self.client.login(username='admin', password=self.password)
self.login_as_admin()
response = self.client.get(reverse('web.views.worker_edit', args=[self.admin_worker.id]))
self.assertEqual(response.status_code, 200)
def test_render_add_availability_request(self):
self.client.logout()
self.client.login(username='admin', password=self.password)
self.login_as_admin()
response = self.client.get(reverse('web.views.worker_availability_add', args=[self.admin_worker.id]))
self.assertEqual(response.status_code, 200)
def test_render_edit_availability_request(self):
self.client.logout()
self.client.login(username='admin', password=self.password)
self.login_as_admin()
availability = create_availability(self.admin_worker)
......@@ -166,8 +155,7 @@ class WorkerViewTests(LoggedInTestCase):
self.assertEqual(response.status_code, 200)
def test_render_add_holiday_request(self):
self.client.logout()
self.client.login(username='admin', password=self.password)
self.login_as_admin()
response = self.client.get(reverse('web.views.worker_holiday_add', args=[self.admin_worker.id]))
self.assertEqual(response.status_code, 200)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment