From 9307fc7676db68de4b3d25f795aa2a351f9d4843 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Sat, 30 May 2020 09:33:29 +0100 Subject: cleaned up tests --- ctrack/organisations/tests/test_views.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'ctrack/organisations/tests/test_views.py') 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 -- cgit v1.2.3