🔧 Library detail URL uses most recent active Boost version

This commit is contained in:
Lacey Williams Henschel
2023-02-11 08:19:57 -08:00
parent 6f4d66b32d
commit da79803555
2 changed files with 39 additions and 7 deletions

View File

@@ -38,18 +38,33 @@ def test_libraries_by_category(tp, library, category):
assert res.context["category"] == category
def test_library_detail(library, tp):
"""GET /libraries/{repo}/"""
def test_library_detail(library_version, tp):
"""GET /libraries/{slug}/"""
library = library_version.library
url = tp.reverse("library-detail", library.slug)
response = tp.get(url)
tp.response_200(response)
def test_library_detail_context_get_closed_prs_count(tp, library):
def test_library_detail_404(library, tp):
"""GET /libraries/{slug}/"""
# 404 due to bad slug
url = tp.reverse("library-detail", "bananas")
response = tp.get(url)
tp.response_404(response)
# 404 due to no existing version
url = tp.reverse("library-detail", library.slug)
response = tp.get(url)
tp.response_404(response)
def test_library_detail_context_get_closed_prs_count(tp, library_version):
"""
GET /libraries/{repo}/
GET /libraries/{slug}/
Test that the custom closed_prs_count var appears as expected
"""
library = library_version.library
# Create open and closed PRs for this library, and another random PR
lib2 = baker.make("libraries.Library", slug="sample")
baker.make("libraries.PullRequest", library=library, is_open=True)
@@ -63,11 +78,12 @@ def test_library_detail_context_get_closed_prs_count(tp, library):
assert response.context["closed_prs_count"] == 1
def test_library_detail_context_get_open_issues_count(tp, library):
def test_library_detail_context_get_open_issues_count(tp, library_version):
"""
GET /libraries/{repo}/
GET /libraries/{slug}/
Test that the custom open_issues_count var appears as expected
"""
library = library_version.library
# Create open and closed issues for this library, and another random issue
lib2 = baker.make("libraries.Library", slug="sample")
baker.make("libraries.Issue", library=library, is_open=True)

View File

@@ -1,12 +1,13 @@
import structlog
from django.http import Http404
from django.shortcuts import redirect
from django.views.generic import DetailView, ListView
from django.views.generic.edit import FormMixin
from versions.models import Version
from .forms import LibraryForm
from .models import Category, Issue, Library, PullRequest
from .models import Category, Issue, Library, LibraryVersion, PullRequest
logger = structlog.get_logger()
@@ -79,6 +80,21 @@ class LibraryDetail(CategoryMixin, DetailView):
model = Library
template_name = "libraries/detail.html"
def get_object(self):
slug = self.kwargs.get("slug")
version = Version.objects.most_recent()
if not LibraryVersion.objects.filter(
version=version, library__slug=slug
).exists():
raise Http404("No library found matching the query")
try:
obj = self.get_queryset().get(slug=slug)
except queryset.model.DoesNotExist:
raise Http404("No library found matching the query")
return obj
def get(self, request, *args, **kwargs):
self.object = self.get_object()
context = self.get_context_data(object=self.object)