Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for _should_intercept and fixed bug with requests not being ... #28

Merged
merged 1 commit into from
Jul 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)