def test_record_traceback(self): callback = mock.Mock() with DBRecorder("default", callback): run_query("default", "SELECT 1") assert len(callback.mock_calls) == 1 assert "django_perf_rec/db.py" in str( callback.call_args_list[0][0][0].traceback)
def test_single_db_query_with_traceback(self): with pretend_not_under_pytest(): with pytest.raises(AssertionError) as excinfo: def capture_traceback(operation): return True with record( record_name="RecordTests.test_single_db_query", capture_traceback=capture_traceback, ): run_query("default", "SELECT 1337") msg = str(excinfo.value) assert ( "Performance record did not match for RecordTests.test_single_db_query" in msg) assert "+ traceback:" in msg assert "in test_single_db_query_with_traceback" in msg
def test_records_all(self): callback = mock.Mock() with AllDBRecorder(callback): run_query("replica", "SELECT 1") run_query("default", "SELECT 2") run_query("second", "SELECT 3") assert callback.mock_calls == [ mock.call(DBOp("replica", "SELECT #")), mock.call(DBOp("default", "SELECT #")), mock.call(DBOp("second", "SELECT #")), ]
def test_multiple_db_queries(self): with record(): run_query("default", "SELECT 1337") run_query("default", "SELECT 4949")
def test_single_db_query(self): with record(): run_query("default", "SELECT 1337")
def test_duplicate_name(): with record(): run_query("default", "SELECT 1337")
def test_secondary_default_not_recorded(self): callback = mock.Mock() with DBRecorder("second", callback): run_query("default", "SELECT 1") assert len(callback.mock_calls) == 0
def test_replica(self): callback = mock.Mock() with DBRecorder("replica", callback): run_query("replica", "SELECT 1") callback.assert_called_once_with(DBOp("replica", "SELECT #"))
def test_secondary(self): callback = mock.Mock() with DBRecorder("second", callback): run_query("second", "SELECT 1") callback.assert_called_once_with(DBOp("second", "SELECT #"))
def test_default(self, extract_stack): callback = mock.Mock() with DBRecorder("default", callback): run_query("default", "SELECT 1") callback.assert_called_once_with(DBOp("default", "SELECT #", None))
def test_single_db_query_with_filtering_positive(self): def capture_operation(operation): return True with record(capture_operation=capture_operation): run_query("default", "SELECT 1338")
def test_single_db_query_with_filtering_negative(self): def no_capture_operation(operation): return False with record(capture_operation=no_capture_operation): run_query("default", "SELECT 1337")
def test_build_name(record_build_name): run_query("default", "SELECT 1337")
def test_auto_name_with_request(record_auto_name_with_request): run_query("default", "SELECT 1337")
def test_auto_name(record_auto_name): run_query("default", "SELECT 1337")