Skip to content

Commit

Permalink
tests: add initial tests for project navigation #977
Browse files Browse the repository at this point in the history
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
  • Loading branch information
MyPyDavid committed Apr 22, 2024
1 parent ac615db commit 74949f4
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions rdmo/projects/tests/test_viewset_project_navigation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import pytest

from django.urls import reverse

from ..models import Project

users = (
('owner', 'owner'),
('manager', 'manager'),
('author', 'author'),
('guest', 'guest'),
('api', 'api'),
('user', 'user'),
('site', 'site'),
('anonymous', None),
)

view_progress_permission_map = {
'owner': [1, 2, 3, 4, 5, 10],
'manager': [1, 3, 5, 7],
'author': [1, 3, 5, 8],
'guest': [1, 3, 5, 9],
'api': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
'site': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
}

change_progress_permission_map = {
'owner': [1, 2, 3, 4, 5, 10],
'manager': [1, 3, 5, 7],
'author': [1, 3, 5, 8],
'api': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
'site': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
}

urlnames = {
'navigation': 'v1-projects:project-navigation'
}

projects = [1, 2, 3, 4, 5]
sections = [1]


@pytest.mark.parametrize('username,password', users)
@pytest.mark.parametrize('project_id', projects)
def test_navigation_get(db, client, username, password, project_id):
client.login(username=username, password=password)

project = Project.objects.get(id=project_id)
sections = project.catalog.sections.order_by("section_catalogs").all()

if project_id in view_progress_permission_map.get(username, []):
catalog_elements = project.catalog.elements
for section in sections:
url = reverse(urlnames['navigation'], args=[project_id, section.id])
response = client.get(url)
assert response.status_code == 200
data = response.json()
assert isinstance(data, list)
assert len(catalog_elements) == len(data)

else:
if sections:
url = reverse(urlnames['navigation'], args=[project_id, sections[0].id])
response = client.get(url)
if password:
assert response.status_code == 404
else:
assert response.status_code == 401

0 comments on commit 74949f4

Please sign in to comment.