mirror of
https://github.com/boostorg/website-v2.git
synced 2026-02-27 05:32:08 +00:00
🔧 Refactors libs-by-cat to use most recent Boost version
This commit is contained in:
@@ -23,6 +23,46 @@ def test_library_list_select_category(library, category, tp):
|
||||
"""POST /libraries/ to submit a category redirects to the libraries-by-category page"""
|
||||
res = tp.post("libraries", data={"categories": category.pk})
|
||||
tp.response_302(res)
|
||||
assert res.url == f"/libraries-by-category/{category.slug}/"
|
||||
|
||||
|
||||
def test_library_list_by_category(library_version, category, tp):
|
||||
"""
|
||||
GET /libraries-by-category/{category_slug}/
|
||||
A category with libraries
|
||||
"""
|
||||
library = library_version.library
|
||||
version = library_version.version
|
||||
library.categories.add(category)
|
||||
res = tp.get("libraries-by-category", category.slug)
|
||||
tp.response_200(res)
|
||||
assert "library_list" in res.context
|
||||
assert len(res.context["library_list"]) == 1
|
||||
assert library in res.context["library_list"]
|
||||
|
||||
|
||||
def test_library_list_by_category_no_results(library_version, category, tp):
|
||||
"""
|
||||
GET /libraries-by-category/{category_slug}/
|
||||
A category with no libraries
|
||||
"""
|
||||
library = library_version.library
|
||||
version = library_version.version
|
||||
res = tp.get("libraries-by-category", category.slug)
|
||||
tp.response_200(res)
|
||||
assert "library_list" in res.context
|
||||
assert len(res.context["library_list"]) == 0
|
||||
|
||||
|
||||
def test_library_list_by_category_no_results_for_active_version(library, category, tp):
|
||||
"""
|
||||
GET /libraries-by-category/{category_slug}/
|
||||
A category with a library, but the library isn't attached to the active Boost version
|
||||
"""
|
||||
res = tp.get("libraries-by-category", category.slug)
|
||||
tp.response_200(res)
|
||||
assert "library_list" in res.context
|
||||
assert len(res.context["library_list"]) == 0
|
||||
|
||||
|
||||
def test_libraries_by_category(tp, library, category):
|
||||
|
||||
@@ -50,6 +50,7 @@ class LibraryList(CategoryMixin, FormMixin, ListView):
|
||||
class LibraryByCategory(CategoryMixin, ListView):
|
||||
"""List all of our libraries in a certain category"""
|
||||
|
||||
form_class = LibraryForm
|
||||
paginate_by = 25
|
||||
template_name = "libraries/list.html"
|
||||
|
||||
@@ -66,11 +67,16 @@ class LibraryByCategory(CategoryMixin, ListView):
|
||||
|
||||
def get_queryset(self):
|
||||
category = self.kwargs.get("category")
|
||||
version = Version.objects.most_recent()
|
||||
|
||||
return (
|
||||
Library.objects.prefetch_related("categories")
|
||||
.filter(categories__slug=category)
|
||||
.filter(
|
||||
categories__slug=category,
|
||||
versions__library_version__version=version,
|
||||
)
|
||||
.order_by("name")
|
||||
.distinct()
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user