From ac615dbf099dd1b5815225ac4fd5b616faeea0f6 Mon Sep 17 00:00:00 2001 From: David Wallace Date: Mon, 22 Apr 2024 14:31:18 +0200 Subject: [PATCH 1/2] fix: rename to catalog_section #977 Signed-off-by: David Wallace --- rdmo/projects/progress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rdmo/projects/progress.py b/rdmo/projects/progress.py index 3984955844..98171a88ab 100644 --- a/rdmo/projects/progress.py +++ b/rdmo/projects/progress.py @@ -53,7 +53,7 @@ def compute_navigation(section, project, snapshot=None): 'id': catalog_section.id, 'uri': catalog_section.uri, 'title': catalog_section.title, - 'first': catalog_section.elements[0].id if section.elements else None + 'first': catalog_section.elements[0].id if catalog_section.elements else None } if catalog_section.id == section.id: navigation_section['pages'] = [] From 74949f486e63531ca5b2b9f811112578d6de7424 Mon Sep 17 00:00:00 2001 From: David Wallace Date: Mon, 22 Apr 2024 14:32:23 +0200 Subject: [PATCH 2/2] tests: add initial tests for project navigation #977 Signed-off-by: David Wallace --- .../tests/test_viewset_project_navigation.py | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 rdmo/projects/tests/test_viewset_project_navigation.py diff --git a/rdmo/projects/tests/test_viewset_project_navigation.py b/rdmo/projects/tests/test_viewset_project_navigation.py new file mode 100644 index 0000000000..eb0c5a977d --- /dev/null +++ b/rdmo/projects/tests/test_viewset_project_navigation.py @@ -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