mirror of
https://github.com/boostorg/website-v2.git
synced 2026-02-26 05:12:11 +00:00
📝 Retrieve open issues from DB and not from GH API
This commit is contained in:
@@ -1,15 +1,32 @@
|
||||
from unittest.mock import patch
|
||||
from model_bakery import baker
|
||||
|
||||
|
||||
def test_library_list(library, tp):
|
||||
"""GET /libraries/"""
|
||||
res = tp.get("libraries")
|
||||
tp.response_200(res)
|
||||
|
||||
|
||||
def test_library_detail(library, tp):
|
||||
"""GET /libraries/{repo}/"""
|
||||
url = tp.reverse("library-detail", library.slug)
|
||||
response = tp.get(url)
|
||||
tp.response_200(response)
|
||||
|
||||
with patch("libraries.views.LibraryDetail.get_open_issues_count") as count_mock:
|
||||
count_mock.return_value = 21
|
||||
res = tp.get(url)
|
||||
tp.response_200(res)
|
||||
|
||||
def test_library_detail_issues_context(tp, library):
|
||||
"""
|
||||
GET /libraries/{repo}/
|
||||
Test that the custom context vars appear as expected
|
||||
"""
|
||||
# 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)
|
||||
baker.make("libraries.Issue", library=library, is_open=False)
|
||||
baker.make("libraries.Issue", library=lib2, is_open=True)
|
||||
url = tp.reverse("library-detail", library.slug)
|
||||
response = tp.get(url)
|
||||
tp.response_200(response)
|
||||
assert "open_issues_count" in response.context
|
||||
# Verify that the count only includes the one open issue for this library
|
||||
assert response.context["open_issues_count"] == 1
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from django.views.generic import DetailView, ListView
|
||||
|
||||
from .github import repo_issues
|
||||
from .models import Category, Library
|
||||
from .models import Category, Issue, Library
|
||||
|
||||
|
||||
class CategoryMixin:
|
||||
@@ -64,10 +63,4 @@ class LibraryDetail(CategoryMixin, DetailView):
|
||||
return self.render_to_response(context)
|
||||
|
||||
def get_open_issues_count(self, obj):
|
||||
try:
|
||||
issues = repo_issues(
|
||||
obj.github_owner, obj.github_repo, state="open", issues_only=True
|
||||
)
|
||||
return len(issues)
|
||||
except Exception:
|
||||
return 0
|
||||
return Issue.objects.filter(library=obj, is_open=True).count()
|
||||
|
||||
Reference in New Issue
Block a user