Skip to content

Commit

Permalink
Runs linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Natan16 committed Dec 7, 2023
1 parent df7297c commit f00d64b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 3 additions & 7 deletions django_query_prefixer/middlewares/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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):
Expand Down
11 changes: 8 additions & 3 deletions tests/test_middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit f00d64b

Please sign in to comment.