aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/organisations/tests/test_views.py
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-05-30 09:33:29 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-05-30 09:33:29 +0100
commit9307fc7676db68de4b3d25f795aa2a351f9d4843 (patch)
tree61ca1e81e49837707e1c725af1ebbe395493b0cd /ctrack/organisations/tests/test_views.py
parent3aec120ae42cb29049c8ba3d8d52d2388e56bb36 (diff)
cleaned up tests
Diffstat (limited to '')
-rw-r--r--ctrack/organisations/tests/test_views.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/ctrack/organisations/tests/test_views.py b/ctrack/organisations/tests/test_views.py
index cebcda9..8e8fff7 100644
--- a/ctrack/organisations/tests/test_views.py
+++ b/ctrack/organisations/tests/test_views.py
@@ -1,5 +1,6 @@
import pytest
from django.contrib.auth import get_user_model
+from django.contrib.auth.models import Permission
from django.test import RequestFactory
from ctrack.organisations.tests.factories import OrganisationFactory
@@ -21,6 +22,12 @@ def test_organisation_list_view():
user = get_user_model().objects.create_user(
username="testy", email="testy@test.com", password="test1020"
)
+ # This user needs permission to acccess the list view
+ org_list_permission = Permission.objects.get(name="Can view organisation")
+ assert user.user_permissions.count() == 0
+ user.user_permissions.add(org_list_permission)
+ assert user.has_perm("organisations.view_organisation")
+ user.save()
request = factory.get("/organisations")
request.user = user
response = OrganisationListView.as_view()(request)
@@ -28,13 +35,10 @@ def test_organisation_list_view():
assert len(response.context_data["organisation_list"]) == 3
-def test_incident_report_create_view():
- user = get_user_model().objects.create_user(
- username="testy", email="testy@test.com", password="test1020"
- )
+def test_incident_report_create_view(stakeholder_user):
org = OrganisationFactory.create()
factory = RequestFactory()
request = factory.get(f"{org.name}/create-incident-report")
- request.user = user
+ request.user = stakeholder_user
response = IncidentReportCreateView.as_view()(request, org.slug)
assert response.status_code == 200