diff --git a/silk/middleware.py b/silk/middleware.py index 648e62aa..7601927f 100644 --- a/silk/middleware.py +++ b/silk/middleware.py @@ -32,8 +32,7 @@ def silky_reverse(name, *args, **kwargs): def _should_intercept(request): """we want to avoid recording any requests/sql queries etc that belong to Silky""" fpath = silky_reverse('summary') - path = '/'.join(fpath.split('/')[0:-1]) - silky = request.path.startswith(path) + silky = request.path.startswith(fpath) ignored = request.path in SilkyConfig().SILKY_IGNORE_PATHS return not (silky or ignored) diff --git a/silk/tests/test_silky_middleware.py b/silk/tests/test_silky_middleware.py index aab5a652..39631246 100644 --- a/silk/tests/test_silky_middleware.py +++ b/silk/tests/test_silky_middleware.py @@ -1,8 +1,9 @@ +from django.core.urlresolvers import reverse from django.test import TestCase from mock import patch, Mock from silk.config import SilkyConfig -from silk.middleware import SilkyMiddleware +from silk.middleware import SilkyMiddleware, _should_intercept from silk.models import Request @@ -94,3 +95,29 @@ def test_no_mappings(self): ] middleware._apply_dynamic_mappings() # Just checking no crash + +class TestShouldIntercept(TestCase): + def test_should_intercept_non_silk_request(self): + request = Request() + request.path = '/myapp/foo' + should_intercept = _should_intercept(request) + + self.assertTrue(should_intercept) + + def test_should_intercept_silk_request(self): + request = Request() + request.path = reverse('silk:summary') + should_intercept = _should_intercept(request) + + self.assertFalse(should_intercept) + + def test_should_intercept_ignore_paths(self): + SilkyConfig().SILKY_IGNORE_PATHS = [ + '/ignorethis' + ] + request = Request() + request.path = '/ignorethis' + should_intercept = _should_intercept(request) + + self.assertFalse(should_intercept) +