-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kevin
committed
Jun 10, 2014
1 parent
98814ba
commit 7e59a56
Showing
3 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import os | ||
import random | ||
|
||
from django.core.urlresolvers import reverse | ||
from django.test import TestCase | ||
|
||
from silk.views.sql_detail import SQLDetailView | ||
|
||
from silk.tests import MockSuite | ||
|
||
|
||
class TestViewSQLDetail(TestCase): | ||
def test_allowed_file_paths_nothing_specified(self): | ||
"""by default we dont display any source, and it should return correctly""" | ||
request = MockSuite().mock_request() | ||
query = MockSuite().mock_sql_queries(request=request, n=1)[0] | ||
response = self.client.get(reverse('silk:request_sql_detail', kwargs={'sql_id': query.id, 'request_id': request.id})) | ||
self.assertTrue(response.status_code == 200) | ||
|
||
def test_allowed_file_paths_available_source(self): | ||
"""if we request to view source that exists in the TB all should be fine""" | ||
request = MockSuite().mock_request() | ||
query = MockSuite().mock_sql_queries(request=request, n=1)[0] | ||
tb = query.traceback_ln_only | ||
_, files = SQLDetailView()._urlify(tb) | ||
file_path = random.choice(files) | ||
with open(file_path, 'r') as f: | ||
line_num = random.randint(0, len(f.read().split('\n'))) | ||
response = self.client.get(reverse('silk:request_sql_detail', | ||
kwargs={'sql_id': query.id, 'request_id': request.id}), | ||
data={ | ||
'line_num': line_num, | ||
'file_path': file_path | ||
}) | ||
self.assertTrue(response.status_code == 200) | ||
|
||
def test_allowed_file_paths_unavailable_source(self): | ||
"""if we request to view source that is not in the tracebackk we should get a 403""" | ||
request = MockSuite().mock_request() | ||
query = MockSuite().mock_sql_queries(request=request, n=1)[0] | ||
file_path = os.path.realpath(os.path.dirname(os.path.realpath(__file__)) + '/../../django_silky/settings.py') | ||
with open(file_path, 'r') as f: | ||
line_num = random.randint(0, len(f.read().split('\n'))) | ||
response = self.client.get(reverse('silk:request_sql_detail', | ||
kwargs={'sql_id': query.id, 'request_id': request.id}), | ||
data={ | ||
'line_num': line_num, | ||
'file_path': file_path | ||
}) | ||
self.assertTrue(response.status_code == 403) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters