aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ctrack/organisations/tests/test_views.py21
-rw-r--r--ctrack/users/tests/test_credentials.py10
2 files changed, 26 insertions, 5 deletions
diff --git a/ctrack/organisations/tests/test_views.py b/ctrack/organisations/tests/test_views.py
index 8e8fff7..7f9da0a 100644
--- a/ctrack/organisations/tests/test_views.py
+++ b/ctrack/organisations/tests/test_views.py
@@ -1,6 +1,6 @@
import pytest
from django.contrib.auth import get_user_model
-from django.contrib.auth.models import Permission
+from django.contrib.auth.models import Group, Permission
from django.test import RequestFactory
from ctrack.organisations.tests.factories import OrganisationFactory
@@ -35,6 +35,25 @@ def test_organisation_list_view():
assert len(response.context_data["organisation_list"]) == 3
+def test_only_member_of_cct_user_group_can_view_org_list():
+
+ OrganisationFactory.create()
+ OrganisationFactory.create()
+ OrganisationFactory.create()
+
+ group = Group.objects.create(name="cct_user")
+
+ factory = RequestFactory()
+ user = get_user_model().objects.create_user(
+ username="testy", email="testy@test.com", password="test1020"
+ )
+ user.groups.add(group)
+ org_list_permission = Permission.objects.get(name="Can view organisation")
+ group.permissions.add(org_list_permission)
+ # They get this permisson via the cct_user group
+ assert user.has_perm("organisations.view_organisation")
+
+
def test_incident_report_create_view(stakeholder_user):
org = OrganisationFactory.create()
factory = RequestFactory()
diff --git a/ctrack/users/tests/test_credentials.py b/ctrack/users/tests/test_credentials.py
index a63ffe0..496eeaf 100644
--- a/ctrack/users/tests/test_credentials.py
+++ b/ctrack/users/tests/test_credentials.py
@@ -1,6 +1,6 @@
"""
-THIS TEST IS FROM REALPYTHON ARTICLE
-https://realpython.com/django-pytest-fixtures/
+THE INITIATIVE FOR THIS TEST IS FROM REALPYTHON ARTICLE
+https://realpython.com/Django-pytest-fixtures/
The permissions here are not optimal for this project yet.
TODO - make them so!
@@ -22,10 +22,12 @@ def user_A(db) -> Group:
return user
-def test_there_is_a_cct_user_group(db):
+def test_there_is_a_cct_user_group(db): # adding fixture here
group = Group.objects.create(name="cct_user")
assert Group.objects.get(name="cct_user")
- user = get_user_model().objects.create_user("INSPECTOR")
+ user = get_user_model().objects.create_user(
+ username="INSPECTOR", name="Mrs Inspector"
+ )
user.groups.add(group)
assert group in user.groups.all()