Beispiel #1
0
 def wrapped(self, *args, **kwargs):
     result = func(self, *args, **kwargs)
     if not RequestQueryCountConfig.enabled():
         return result
     cls.save_json('SUMMARY_PATH', cls.queries, False)
     cls.save_json('DETAIL_PATH', cls.queries, True)
     cls.queries = None
     return result
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     if not RequestQueryCountConfig.enabled():
         raise MiddlewareNotUsed()
     self.force_debug_cursor = False
     self.initial_queries = 0
     self.final_queries = None
     self.connection = connections[DEFAULT_DB_ALIAS]
Beispiel #3
0
        def wrapped(self, *args, **kwargs):
            if (not hasattr(cls, 'queries') or not
                    RequestQueryCountConfig.enabled()):
                return tear_down(self, *args, **kwargs)

            container = cls.get_testcase_container()

            test_method = getattr(self, self._testMethodName)

            exclusions = (
                getattr(self.__class__, "__querycount_exclude__", []) +
                getattr(test_method, "__querycount_exclude__", [])
            )

            all_queries = cls.queries
            current_queries = container.filter_by(exclusions)
            all_queries.add(self.id(), current_queries)

            return tear_down(self, *args, **kwargs)
Beispiel #4
0
 def test_default_enabled(self):
     self.assertTrue(RequestQueryCountConfig.enabled())
Beispiel #5
0
 def test_override_enabled(self):
     self.assertTrue(RequestQueryCountConfig.enabled())
Beispiel #6
0
 def test_override_disabled(self):
     self.assertFalse(RequestQueryCountConfig.enabled())
Beispiel #7
0
 def wrapped(self, *args, **kwargs):
     result = set_up(self, *args, **kwargs)
     if RequestQueryCountConfig.enabled():
         setattr(local, cls.LOCAL_TESTCASE_CONTAINER_NAME,
                 TestCaseQueryContainer())
     return result
Beispiel #8
0
 def wrapped(self, *args, **kwargs):
     result = func(self, *args, **kwargs)
     if not RequestQueryCountConfig.enabled():
         return result
     cls.queries = TestResultQueryContainer()
     return result