diff --git a/examples/miniapps/django/README.rst b/examples/miniapps/django/README.rst index 2ff42581..43917094 100644 --- a/examples/miniapps/django/README.rst +++ b/examples/miniapps/django/README.rst @@ -105,9 +105,9 @@ The output should be something like: githubnavigator/wsgi.py 4 4 0% manage.py 12 2 83% web/__init__.py 0 0 100% - web/apps.py 7 0 100% + web/apps.py 6 0 100% web/tests.py 28 0 100% web/urls.py 3 0 100% web/views.py 12 0 100% --------------------------------------------------- - TOTAL 121 10 92% + TOTAL 120 10 92% diff --git a/examples/miniapps/django/githubnavigator/asgi.py b/examples/miniapps/django/githubnavigator/asgi.py index b1f6edc7..9d473ae0 100644 --- a/examples/miniapps/django/githubnavigator/asgi.py +++ b/examples/miniapps/django/githubnavigator/asgi.py @@ -10,6 +10,6 @@ import os from django.core.asgi import get_asgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'githubnavigator.settings') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "githubnavigator.settings") application = get_asgi_application() diff --git a/examples/miniapps/django/githubnavigator/services.py b/examples/miniapps/django/githubnavigator/services.py index 9c6ff839..3e80a7ec 100644 --- a/examples/miniapps/django/githubnavigator/services.py +++ b/examples/miniapps/django/githubnavigator/services.py @@ -15,7 +15,7 @@ class SearchService: """Search for repositories and return formatted data.""" repositories = self._github_client.search_repositories( query=query, - **{'in': 'name'}, + **{"in": "name"}, ) return [ self._format_repo(repository) @@ -25,20 +25,20 @@ class SearchService: def _format_repo(self, repository: Repository): commits = repository.get_commits() return { - 'url': repository.html_url, - 'name': repository.name, - 'owner': { - 'login': repository.owner.login, - 'url': repository.owner.html_url, - 'avatar_url': repository.owner.avatar_url, + "url": repository.html_url, + "name": repository.name, + "owner": { + "login": repository.owner.login, + "url": repository.owner.html_url, + "avatar_url": repository.owner.avatar_url, }, - 'latest_commit': self._format_commit(commits[0]) if commits else {}, + "latest_commit": self._format_commit(commits[0]) if commits else {}, } def _format_commit(self, commit: Commit): return { - 'sha': commit.sha, - 'url': commit.html_url, - 'message': commit.commit.message, - 'author_name': commit.commit.author.name, + "sha": commit.sha, + "url": commit.html_url, + "message": commit.commit.message, + "author_name": commit.commit.author.name, } diff --git a/examples/miniapps/django/githubnavigator/settings.py b/examples/miniapps/django/githubnavigator/settings.py index 7c004048..e78900b7 100644 --- a/examples/miniapps/django/githubnavigator/settings.py +++ b/examples/miniapps/django/githubnavigator/settings.py @@ -20,7 +20,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = ')6*iyg26c9l!fvyvwd&3+vyf-dcw)e=5x2t(j)(*c29z@ykhi0' +SECRET_KEY = ")6*iyg26c9l!fvyvwd&3+vyf-dcw)e=5x2t(j)(*c29z@ykhi0" # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True @@ -31,54 +31,54 @@ ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ - 'web.apps.WebConfig', - 'bootstrap4', - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', + "web.apps.WebConfig", + "bootstrap4", + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", ] MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", ] -ROOT_URLCONF = 'githubnavigator.urls' +ROOT_URLCONF = "githubnavigator.urls" TEMPLATES = [ { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", ], }, }, ] -WSGI_APPLICATION = 'githubnavigator.wsgi.application' +WSGI_APPLICATION = "githubnavigator.wsgi.application" # Database # https://docs.djangoproject.com/en/3.0/ref/settings/#databases DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": os.path.join(BASE_DIR, "db.sqlite3"), } } @@ -88,16 +88,16 @@ DATABASES = { AUTH_PASSWORD_VALIDATORS = [ { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", }, ] @@ -105,9 +105,9 @@ AUTH_PASSWORD_VALIDATORS = [ # Internationalization # https://docs.djangoproject.com/en/3.0/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = "en-us" -TIME_ZONE = 'UTC' +TIME_ZONE = "UTC" USE_I18N = True @@ -119,13 +119,13 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.0/howto/static-files/ -STATIC_URL = '/static/' +STATIC_URL = "/static/" # Github client settings -GITHUB_TOKEN = os.getenv('GITHUB_TOKEN') +GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") GITHUB_REQUEST_TIMEOUT = 10 # Search settings DEFAULT_LIMIT = 5 -DEFAULT_QUERY = 'Dependency Injector' +DEFAULT_QUERY = "Dependency Injector" LIMIT_OPTIONS = [5, 10, 20] diff --git a/examples/miniapps/django/githubnavigator/urls.py b/examples/miniapps/django/githubnavigator/urls.py index 5e88d78f..9da435a1 100644 --- a/examples/miniapps/django/githubnavigator/urls.py +++ b/examples/miniapps/django/githubnavigator/urls.py @@ -17,6 +17,6 @@ from django.contrib import admin from django.urls import path, include urlpatterns = [ - path('', include('web.urls')), - path('admin/', admin.site.urls), + path("", include("web.urls")), + path("admin/", admin.site.urls), ] diff --git a/examples/miniapps/django/githubnavigator/wsgi.py b/examples/miniapps/django/githubnavigator/wsgi.py index a13cd5f9..a18485e5 100644 --- a/examples/miniapps/django/githubnavigator/wsgi.py +++ b/examples/miniapps/django/githubnavigator/wsgi.py @@ -11,6 +11,6 @@ import os from django.core.wsgi import get_wsgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'githubnavigator.settings') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "githubnavigator.settings") application = get_wsgi_application() diff --git a/examples/miniapps/django/manage.py b/examples/miniapps/django/manage.py index d3bb8330..b817fe61 100755 --- a/examples/miniapps/django/manage.py +++ b/examples/miniapps/django/manage.py @@ -5,7 +5,7 @@ import sys def main(): - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'githubnavigator.settings') + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "githubnavigator.settings") try: from django.core.management import execute_from_command_line except ImportError as exc: @@ -17,5 +17,5 @@ def main(): execute_from_command_line(sys.argv) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/examples/miniapps/django/web/apps.py b/examples/miniapps/django/web/apps.py index c52fbbe2..0363f24e 100644 --- a/examples/miniapps/django/web/apps.py +++ b/examples/miniapps/django/web/apps.py @@ -3,11 +3,10 @@ from django.apps import AppConfig from githubnavigator import container -from . import views class WebConfig(AppConfig): - name = 'web' + name = "web" def ready(self): - container.wire(modules=[views]) + container.wire(modules=[".views"]) diff --git a/examples/miniapps/django/web/templates/base.html b/examples/miniapps/django/web/templates/base.html index 8edd5984..f337f1d8 100644 --- a/examples/miniapps/django/web/templates/base.html +++ b/examples/miniapps/django/web/templates/base.html @@ -1,4 +1,4 @@ -{% extends 'bootstrap4/bootstrap4.html' %} +{% extends "bootstrap4/bootstrap4.html" %} {% load bootstrap4 %} diff --git a/examples/miniapps/django/web/tests.py b/examples/miniapps/django/web/tests.py index eddc5d22..54330315 100644 --- a/examples/miniapps/django/web/tests.py +++ b/examples/miniapps/django/web/tests.py @@ -15,49 +15,49 @@ class IndexTests(TestCase): github_client_mock = mock.Mock(spec=Github) github_client_mock.search_repositories.return_value = [ mock.Mock( - html_url='repo1-url', - name='repo1-name', + html_url="repo1-url", + name="repo1-name", owner=mock.Mock( - login='owner1-login', - html_url='owner1-url', - avatar_url='owner1-avatar-url', + 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', + html_url="repo2-url", + name="repo2-name", owner=mock.Mock( - login='owner2-login', - html_url='owner2-url', - avatar_url='owner2-avatar-url', + 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')) + response = self.client.get(reverse("index")) - self.assertContains(response, 'Results found: 2') + 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, "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') + 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')) + response = self.client.get(reverse("index")) - self.assertContains(response, 'Results found: 0') + self.assertContains(response, "Results found: 0") diff --git a/examples/miniapps/django/web/urls.py b/examples/miniapps/django/web/urls.py index de1d2f9f..16061aa2 100644 --- a/examples/miniapps/django/web/urls.py +++ b/examples/miniapps/django/web/urls.py @@ -5,5 +5,5 @@ from django.urls import path from . import views urlpatterns = [ - path('', views.index, name='index'), + path("", views.index, name="index"), ] diff --git a/examples/miniapps/django/web/views.py b/examples/miniapps/django/web/views.py index 6d8f11f5..16a66595 100644 --- a/examples/miniapps/django/web/views.py +++ b/examples/miniapps/django/web/views.py @@ -18,18 +18,18 @@ def index( default_limit: int = Provide[Container.config.DEFAULT_LIMIT.as_int()], limit_options: List[int] = Provide[Container.config.LIMIT_OPTIONS], ) -> HttpResponse: - query = request.GET.get('query', default_query) - limit = int(request.GET.get('limit', default_limit)) + 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', + template_name="index.html", context={ - 'query': query, - 'limit': limit, - 'limit_options': limit_options, - 'repositories': repositories, + "query": query, + "limit": limit, + "limit_options": limit_options, + "repositories": repositories, } )