From f00d64be09a53f562e427b01338d7c081ef90aae Mon Sep 17 00:00:00 2001 From: Natan16 Date: Thu, 7 Dec 2023 11:59:08 -0300 Subject: [PATCH] Runs linter --- django_query_prefixer/middlewares/__init__.py | 10 +++------- tests/test_middlewares.py | 11 ++++++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/django_query_prefixer/middlewares/__init__.py b/django_query_prefixer/middlewares/__init__.py index 512ad76..c979e04 100644 --- a/django_query_prefixer/middlewares/__init__.py +++ b/django_query_prefixer/middlewares/__init__.py @@ -1,10 +1,9 @@ -from django.urls import resolve from django_query_prefixer import set_prefix, remove_prefix class RequestRouteMiddleware: - def __init__(self, get_response): - self.get_response = get_response + def __init__(self, get_response): + self.get_response = get_response def __call__(self, request): response = self.get_response(request) @@ -14,10 +13,7 @@ def __call__(self, request): def process_view(self, request, view_func, view_args, view_kwargs): set_prefix(key="view_name", value=f"{view_func.__module__}.{view_func.__name__}") - set_prefix( - key="route", - value=escape_comment_markers(request.resolver_match.route.route) - ) + set_prefix(key="route", value=escape_comment_markers(request.resolver_match.route.route)) def request_route(get_response): diff --git a/tests/test_middlewares.py b/tests/test_middlewares.py index 868cd1b..f0445a0 100644 --- a/tests/test_middlewares.py +++ b/tests/test_middlewares.py @@ -10,15 +10,20 @@ def test_request_route_middleware(): request = mock.MagicMock() request.resolver_match.route.route = "/hello" + def hello_world(): pass - with mock.patch("django_query_prefixer.middlewares.set_prefix") as mock_set_prefix, \ - mock.patch("django_query_prefixer.middlewares.remove_prefix") as mock_remove_prefix: + with mock.patch("django_query_prefixer.middlewares.set_prefix") as mock_set_prefix, mock.patch( + "django_query_prefixer.middlewares.remove_prefix" + ) as mock_remove_prefix: middleware.process_view(request, hello_world, [], {}) assert middleware(request) == response - assert mock_set_prefix.call_args_list[0].kwargs == {"key": "view_name", "value": f"{hello_world.__module__}.hello_world"} + assert mock_set_prefix.call_args_list[0].kwargs == { + "key": "view_name", + "value": f"{hello_world.__module__}.hello_world", + } assert mock_set_prefix.call_args_list[1].kwargs == {"key": "route", "value": "/hello"} assert mock_remove_prefix.call_args_list[0].args[0] == "view_name" assert mock_remove_prefix.call_args_list[1].args[0] == "route"