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

404 if tags don't have resources assigned #3117

Merged
merged 1 commit into from
Feb 23, 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
30 changes: 22 additions & 8 deletions pontoon/tags/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,37 @@
from django.urls import reverse

from pontoon.base.models import Priority
from pontoon.test.factories import TagFactory, TranslatedResourceFactory


@pytest.mark.django_db
def test_view_project_tag_locales(client, project_a, tag_a):
def test_view_project_tag_locales(client, locale_a, project_a, resource_a):
TranslatedResourceFactory.create(resource=resource_a, locale=locale_a)

tag = TagFactory.create(
slug="tag",
name="Tag",
)

url = reverse(
"pontoon.tags.project.tag",
kwargs=dict(project=project_a.slug, tag=tag_a.slug),
kwargs=dict(project=project_a.slug, tag=tag.slug),
)

# tag is not associated with project
project_a.tag_set.remove(tag_a)
# tag is not associated with a project
response = client.get(url)
assert response.status_code == 404

project_a.tag_set.add(tag_a)
tag_a.priority = Priority.NORMAL
tag_a.save()
tag.project = project_a
tag.save()

# tag is not associated with a resource
response = client.get(url)
assert response.status_code == 404

tag.resources.add(resource_a)
tag.save()

response = client.get(url)
assert response.status_code == 200

Expand All @@ -31,7 +45,7 @@ def test_view_project_tag_locales(client, project_a, tag_a):
assert response.context_data["project"] == project_a

res_tag = response.context_data["tag"]
assert res_tag == tag_a
assert res_tag == tag


@pytest.mark.django_db
Expand Down
4 changes: 3 additions & 1 deletion pontoon/tags/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def __init__(self, **kwargs):
self.project = kwargs.get("project")
self.locale = kwargs.get("locale")
self.slug = kwargs.get("slug")
self.tag = Tag.objects.filter(project=self.project, slug=self.slug).first()
self.tag = Tag.objects.filter(
project=self.project, slug=self.slug, resources__isnull=False
).first()

def get(self):
tags = (
Expand Down