diff --git a/libraries/tests/test_views.py b/libraries/tests/test_views.py new file mode 100644 index 00000000..19b0a966 --- /dev/null +++ b/libraries/tests/test_views.py @@ -0,0 +1,15 @@ +from unittest.mock import patch + + +def test_library_list(library, tp): + res = tp.get("libraries") + tp.response_200(res) + + +def test_library_detail(library, tp): + url = tp.reverse("library-detail", library.slug) + + 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) diff --git a/libraries/views.py b/libraries/views.py index c7ea2245..bfa82fea 100644 --- a/libraries/views.py +++ b/libraries/views.py @@ -1,5 +1,6 @@ from django.views.generic import DetailView, ListView +from .github import repo_issues from .models import Category, Library @@ -55,3 +56,18 @@ class LibraryDetail(CategoryMixin, DetailView): model = Library template_name = "libraries/detail.html" + + def get(self, request, *args, **kwargs): + self.object = self.get_object() + context = self.get_context_data(object=self.object) + context["open_issues_count"] = self.get_open_issues_count(self.object) + 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 diff --git a/templates/libraries/detail.html b/templates/libraries/detail.html index 5053a03c..6a0bcc9e 100644 --- a/templates/libraries/detail.html +++ b/templates/libraries/detail.html @@ -68,7 +68,7 @@