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

fixed tests

parent 9bb11e41
No related branches found
No related tags found
1 merge request!192Feature/add way to change password and PERMISSIONS
Pipeline #7554 passed
...@@ -4,8 +4,10 @@ from django.conf import settings ...@@ -4,8 +4,10 @@ from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.test import Client from django.test import Client
from django.test import TestCase from django.test import TestCase
from web.models import Worker
from web.decorators import PermissionDecorator
from functions import create_worker from functions import create_worker, create_user, add_permissions_to_worker
settings.MEDIA_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data') settings.MEDIA_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data')
...@@ -14,6 +16,15 @@ logger = logging.getLogger(__name__) ...@@ -14,6 +16,15 @@ logger = logging.getLogger(__name__)
class LoggedInTestCase(TestCase): class LoggedInTestCase(TestCase):
def setUp(self): def setUp(self):
self.password = 'abcd1234'
#superuser
self.super_worker = create_worker(user=User.objects.create_superuser(username='super', password=self.password, email='a@mail.com'))
#admin
self.admin_worker = Worker.get_by_user(create_user(username='admin', password=self.password))
add_permissions_to_worker(self.admin_worker, PermissionDecorator.codenames)
#staff
self.staff_worker = Worker.get_by_user(create_user(username='staff', password=self.password))
self.client = Client() self.client = Client()
username = 'piotr' username = 'piotr'
password = 'top_secret' password = 'top_secret'
......
...@@ -2,8 +2,19 @@ from django.urls import reverse ...@@ -2,8 +2,19 @@ from django.urls import reverse
from web.tests import LoggedInTestCase from web.tests import LoggedInTestCase
import logging
logger = logging.getLogger(__name__)
class ConfigurationViewTests(LoggedInTestCase): class ConfigurationViewTests(LoggedInTestCase):
def test_visit_details_request(self): def test_visit_details_request(self):
self.client.logout()
self.client.login(username='admin', password=self.password)
response = self.client.get(reverse('web.views.configuration')) response = self.client.get(reverse('web.views.configuration'))
self.assertEqual(response.status_code, 200) 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)
response = self.client.get(reverse('web.views.configuration'))
self.assertEqual(response.status_code, 302)
...@@ -7,7 +7,7 @@ from web.forms import WorkerForm ...@@ -7,7 +7,7 @@ from web.forms import WorkerForm
from web.models import Worker from web.models import Worker
from web.models.worker_study_role import WORKER_STAFF, ROLE_CHOICES_DOCTOR, WORKER_HEALTH_PARTNER, WORKER_VOUCHER_PARTNER from web.models.worker_study_role import WORKER_STAFF, ROLE_CHOICES_DOCTOR, WORKER_HEALTH_PARTNER, WORKER_VOUCHER_PARTNER
from web.tests import create_worker from web.tests import create_worker
from web.tests.functions import add_permissions_to_worker, create_user, create_language, create_location, create_availability, format_form_field from web.tests.functions import create_user, create_language, create_location, create_availability, format_form_field
from .. import LoggedInTestCase from .. import LoggedInTestCase
from web.models.constants import GLOBAL_STUDY_ID from web.models.constants import GLOBAL_STUDY_ID
...@@ -15,16 +15,6 @@ logger = logging.getLogger(__name__) ...@@ -15,16 +15,6 @@ logger = logging.getLogger(__name__)
class WorkerViewTests(LoggedInTestCase): class WorkerViewTests(LoggedInTestCase):
def setUp(self):
self.password = 'abcd1234'
#superuser
self.super_worker = create_worker(user=User.objects.create_superuser(username='super', password=self.password, email='a@mail.com'))
#admin
self.admin_worker = Worker.get_by_user(create_user(username='admin', password=self.password))
add_permissions_to_worker(self.admin_worker, ['change_worker', 'add_worker'])
#staff
self.staff_worker = Worker.get_by_user(create_user(username='staff', password=self.password))
def test_render_workers_list_request(self): def test_render_workers_list_request(self):
self.client.logout() self.client.logout()
self.client.login(username='staff', password=self.password) self.client.login(username='staff', password=self.password)
...@@ -66,7 +56,8 @@ class WorkerViewTests(LoggedInTestCase): ...@@ -66,7 +56,8 @@ class WorkerViewTests(LoggedInTestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
def test_render_worker_added_request(self): def test_render_worker_added_request(self):
self.assertEqual(3, User.objects.all().count()) self.assertEqual(3, Worker.objects.all().count())
self.assertEqual(4, User.objects.all().count())
self.client.logout() self.client.logout()
self.client.login(username='admin', password=self.password) self.client.login(username='admin', password=self.password)
...@@ -82,7 +73,7 @@ class WorkerViewTests(LoggedInTestCase): ...@@ -82,7 +73,7 @@ class WorkerViewTests(LoggedInTestCase):
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
self.assertEqual(4, Worker.objects.all().count()) self.assertEqual(4, Worker.objects.all().count())
self.assertEqual(4, User.objects.all().count()) self.assertEqual(5, User.objects.all().count())
def create_add_worker_form_data(self, language, location): def create_add_worker_form_data(self, language, location):
form_data = self.get_form_data(Worker()) form_data = self.get_form_data(Worker())
......
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