aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-05-28 13:28:19 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-05-28 13:28:19 +0100
commitdf8f55519b2e2ed0db5e3175041c8d4321c830b8 (patch)
tree06ce0e8e64b0794ccf8e5350f1c3685196bffed4
parent38d0771eed7185fad90977a264a5dcc16aa2bb07 (diff)
user with permission can view OrganisationListView
-rw-r--r--ctrack/users/tests/test_functional.py24
-rw-r--r--ctrack/users/tests/test_views.py19
2 files changed, 42 insertions, 1 deletions
diff --git a/ctrack/users/tests/test_functional.py b/ctrack/users/tests/test_functional.py
index 4e1f532..da9d088 100644
--- a/ctrack/users/tests/test_functional.py
+++ b/ctrack/users/tests/test_functional.py
@@ -9,6 +9,7 @@ a regular user or a stakeholder user.
import time
import pytest
+from django.contrib.auth.models import Permission
from ctrack.users.models import User
@@ -80,3 +81,26 @@ def test_stakeholder_can_log_in_but_receieved_permisson_denied_when_off_piste(
assert "Sorry. You do not have permission to view this page." in [
x.text for x in browser.find_elements_by_tag_name("p")
]
+
+
+def test_stakeholder_user_with_permissions_can_view_page(
+ browser, live_server, stakeholder
+):
+ user = User.objects.create_user(username="toss", password="knob")
+ user.stakeholder = stakeholder
+ org_list_permission = Permission.objects.get(name="Can view organisation")
+
+ # Add the permission to view an Organisation, which is set on OrganisationListView
+ assert user.user_permissions.count() == 0
+ user.user_permissions.add(org_list_permission)
+ assert user.user_permissions.count() == 1
+ user.save()
+
+ browser.get(live_server + "/accounts/login")
+ browser.find_element_by_id("id_login").send_keys("toss")
+ browser.find_element_by_id("id_password").send_keys("knob")
+ browser.find_element_by_id("sign_in_button").submit()
+ time.sleep(1)
+ # Try to browser to Organisations list
+ browser.get(live_server + "/organisations")
+ assert "Organisations" in browser.title
diff --git a/ctrack/users/tests/test_views.py b/ctrack/users/tests/test_views.py
index fdd5633..8dc4825 100644
--- a/ctrack/users/tests/test_views.py
+++ b/ctrack/users/tests/test_views.py
@@ -146,7 +146,7 @@ def test_stakeholder_user_is_not_staff(django_user_model, stakeholder):
assert user.is_staff is False
-def test_regular_user_gets_301_when_trying_to_access_view_with_perm_set(
+def test_stakeholder_user_gets_301_when_trying_to_access_view_with_perm_set(
django_user_model, client, stakeholder
):
"""
@@ -163,3 +163,20 @@ def test_regular_user_gets_301_when_trying_to_access_view_with_perm_set(
assert (
response.status_code == 301
) # This page redirects to 403.html, hence why its a 301 (I think)
+
+
+@pytest.mark.skip("Explore why this does not pass - it passess in functional style")
+def test_staff_user_gets_200_when_trying_to_access_view_with_perm_set(
+ django_user_model, client, stakeholder
+):
+ user = django_user_model.objects.create_user(username="toss", password="knob")
+ user.stakeholder = stakeholder
+ 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()
+ logged_in = client.login(username="toss", password="knob")
+ assert logged_in is True
+ response = client.get("/organisations")
+ assert response.status_code == 200