+
Github Navigator
+
+
+
+
Results found: {{ repositories|length }}
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/examples/miniapps/django/web/tests.py b/examples/miniapps/django/web/tests.py
new file mode 100644
index 00000000..eddc5d22
--- /dev/null
+++ b/examples/miniapps/django/web/tests.py
@@ -0,0 +1,63 @@
+"""Tests module."""
+
+from unittest import mock
+
+from django.urls import reverse
+from django.test import TestCase
+from github import Github
+
+from githubnavigator import container
+
+
+class IndexTests(TestCase):
+
+ def test_index(self):
+ github_client_mock = mock.Mock(spec=Github)
+ github_client_mock.search_repositories.return_value = [
+ mock.Mock(
+ html_url='repo1-url',
+ name='repo1-name',
+ owner=mock.Mock(
+ login='owner1-login',
+ html_url='owner1-url',
+ avatar_url='owner1-avatar-url',
+ ),
+ get_commits=mock.Mock(return_value=[mock.Mock()]),
+ ),
+ mock.Mock(
+ html_url='repo2-url',
+ name='repo2-name',
+ owner=mock.Mock(
+ login='owner2-login',
+ html_url='owner2-url',
+ avatar_url='owner2-avatar-url',
+ ),
+ get_commits=mock.Mock(return_value=[mock.Mock()]),
+ ),
+ ]
+
+ with container.github_client.override(github_client_mock):
+ response = self.client.get(reverse('index'))
+
+ self.assertContains(response, 'Results found: 2')
+
+ self.assertContains(response, 'repo1-url')
+ self.assertContains(response, 'repo1-name')
+ self.assertContains(response, 'owner1-login')
+ self.assertContains(response, 'owner1-url')
+ self.assertContains(response, 'owner1-avatar-url')
+
+ self.assertContains(response, 'repo2-url')
+ self.assertContains(response, 'repo2-name')
+ self.assertContains(response, 'owner2-login')
+ self.assertContains(response, 'owner2-url')
+ self.assertContains(response, 'owner2-avatar-url')
+
+ def test_index_no_results(self):
+ github_client_mock = mock.Mock(spec=Github)
+ github_client_mock.search_repositories.return_value = []
+
+ with container.github_client.override(github_client_mock):
+ response = self.client.get(reverse('index'))
+
+ self.assertContains(response, 'Results found: 0')
diff --git a/examples/miniapps/django/web/urls.py b/examples/miniapps/django/web/urls.py
new file mode 100644
index 00000000..de1d2f9f
--- /dev/null
+++ b/examples/miniapps/django/web/urls.py
@@ -0,0 +1,9 @@
+"""URLs module."""
+
+from django.urls import path
+
+from . import views
+
+urlpatterns = [
+ path('', views.index, name='index'),
+]
diff --git a/examples/miniapps/django/web/views.py b/examples/miniapps/django/web/views.py
new file mode 100644
index 00000000..6448e535
--- /dev/null
+++ b/examples/miniapps/django/web/views.py
@@ -0,0 +1,34 @@
+"""Views module."""
+
+from typing import List
+
+from django.http import HttpRequest, HttpResponse
+from django.shortcuts import render
+from dependency_injector.wiring import Provide
+
+from githubnavigator.containers import Container
+from githubnavigator.services import SearchService
+
+
+def index(
+ request: HttpRequest,
+ search_service: SearchService = Provide[Container.search_service],
+ default_query: str = Provide[Container.config.DEFAULT_QUERY],
+ default_limit: int = Provide[Container.config.DEFAULT_LIMIT.as_int()],
+ limits: List[int] = Provide[Container.config.LIMITS],
+) -> HttpResponse:
+ query = request.GET.get('query', default_query)
+ limit = int(request.GET.get('limit', default_limit))
+
+ repositories = search_service.search_repositories(query, limit)
+
+ return render(
+ request,
+ template_name='index.html',
+ context={
+ 'query': query,
+ 'limit': limit,
+ 'limits': limits,
+ 'repositories': repositories,
+ }
+ )
diff --git a/examples/miniapps/flask/README.rst b/examples/miniapps/flask/README.rst
index 12bd3dcc..260a95d2 100644
--- a/examples/miniapps/flask/README.rst
+++ b/examples/miniapps/flask/README.rst
@@ -46,8 +46,7 @@ After that visit http://127.0.0.1:5000/ in your browser.
.. note::
-
- Github has a rate limit. When thre rate limit is exceed you will see an exception
+ Github has a rate limit. When the rate limit is exceed you will see an exception
``github.GithubException.RateLimitExceededException``. For unauthenticated requests, the rate
limit allows for up to 60 requests per hour. To extend the limit to 5000 requests per hour you
need to set personal access token.