Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

977 bug in progress when a section has no pages #978

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rdmo/projects/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = []
Expand Down
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
Loading