Skip to content

Commit

Permalink
Add user perm test during maintenance mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ezkat committed Sep 5, 2023
1 parent cd3c428 commit 28a83d1
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions resources/tests/test_resource_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ def _check_permissions_dict(api_client, resource, is_admin, is_manager, is_viewe

url = reverse('resource-detail', kwargs={'pk': resource.pk})
response = api_client.get(url)
print(response.data)
assert response.status_code == 200
permissions = response.data['user_permissions']

if can_create_reservations_for_other_users:
# exists and is True if user is staff for the resource
# OR the user is staff and the resource has reservable_by_all_staff set to True
Expand Down Expand Up @@ -1264,4 +1263,28 @@ def test_user_permissions_external_resources(api_client, resource_in_unit, user,
# can_create_reservations_for_other_users should be False for resource_in_unit3
_check_permissions_dict(api_client, resource_in_unit3, is_admin=False, is_manager=False,
is_viewer=False, can_make_reservations=True, can_ignore_opening_hours=False,
can_bypass_payment=False, can_create_reservations_for_other_users=False)
can_bypass_payment=False, can_create_reservations_for_other_users=False)

@pytest.mark.django_db
def test_user_permissions_in_resource_endpoint_during_maintenance_mode(
maintenance_mode, resource_in_unit,
user, api_client,
staff_user, staff_api_client):
resource_in_unit.unit.create_authorization(staff_user, 'manager')
url = reverse('resource-detail', kwargs={'pk': resource_in_unit.pk})


api_client.force_authenticate(user=user)
response = api_client.get(url)
assert response.status_code == 200
assert not any(
[permission for _, permission in response.data['user_permissions'].items()]
)

staff_api_client.force_authenticate(user=staff_user)
response = staff_api_client.get(url)
assert response.status_code == 200
assert not any(
[permission for _, permission in response.data['user_permissions'].items()]
)

0 comments on commit 28a83d1

Please sign in to comment.