예제 #1
0
    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)
예제 #2
0
    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
예제 #3
0
    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 #")),
        ]
예제 #4
0
 def test_multiple_db_queries(self):
     with record():
         run_query("default", "SELECT 1337")
         run_query("default", "SELECT 4949")
예제 #5
0
 def test_single_db_query(self):
     with record():
         run_query("default", "SELECT 1337")
def test_duplicate_name():
    with record():
        run_query("default", "SELECT 1337")
예제 #7
0
 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
예제 #8
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 #"))
예제 #9
0
 def test_secondary(self):
     callback = mock.Mock()
     with DBRecorder("second", callback):
         run_query("second", "SELECT 1")
     callback.assert_called_once_with(DBOp("second", "SELECT #"))
예제 #10
0
 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))
예제 #11
0
    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")
예제 #12
0
    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")
예제 #13
0
def test_build_name(record_build_name):
    run_query("default", "SELECT 1337")
예제 #14
0
def test_auto_name_with_request(record_auto_name_with_request):
    run_query("default", "SELECT 1337")
예제 #15
0
def test_auto_name(record_auto_name):
    run_query("default", "SELECT 1337")