Skip to content

Commit

Permalink
Added tests for _should_intercept and fixed bug with requests not bei…
Browse files Browse the repository at this point in the history
…ng recorded. Used @saintger code comment on issue jazzband/django-silk#25
  • Loading branch information
Kevin committed Jul 21, 2014
1 parent 82f76ef commit d400bdc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
3 changes: 1 addition & 2 deletions silk/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
29 changes: 28 additions & 1 deletion silk/tests/test_silky_middleware.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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)

0 comments on commit d400bdc

Please sign in to comment.