Skip to content

Commit

Permalink
add back more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
albertyw committed Jan 16, 2024
1 parent 99abd29 commit 446bc8e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions project/tests/test_execute_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,38 @@ def test_called(self):

def test_count(self):
self.assertEqual(0, len(DataCollector().queries))


class TestCallRequest(TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
call_execute_sql(cls, Request())

def tearDown(self):
DataCollector().stop_python_profiler()

def test_called(self):
self.mock_sql._execute_sql.assert_called_once_with(*self.args, **self.kwargs)

def test_count(self):
self.assertEqual(1, len(DataCollector().queries))

def test_query(self):
query = list(DataCollector().queries.values())[0]
self.assertEqual(query['query'], self.query_string)


class TestCallSilky(TestCase):
def tearDown(self):
DataCollector().stop_python_profiler()

def test_no_effect(self):
DataCollector().configure()
sql, _ = mock_sql()
sql.query.model = NonCallableMagicMock(spec_set=['__module__'])
sql.query.model.__module__ = 'silk.models'
# No SQLQuery models should be created for silk requests for obvious reasons
with patch('silk.sql.DataCollector', return_value=Mock()) as mock_DataCollector:
execute_sql(sql)
self.assertFalse(mock_DataCollector().register_query.call_count)

0 comments on commit 446bc8e

Please sign in to comment.