예제 #1
0
    def test_dynamic_decorator(self):
        middleware = SilkyMiddleware()
        SilkyConfig().SILKY_DYNAMIC_PROFILING = [
            {
                'module': 'tests.data.dynamic',
                'function': 'foo'
            }
        ]
        middleware._apply_dynamic_mappings()
        from .data.dynamic import foo

        mock = mock_data_collector()
        with patch('silk.profiling.profiler.DataCollector', return_value=mock) as mock_DataCollector:
            foo()  # Should be wrapped in a decorator
            self.assertTrue(mock_DataCollector.return_value.register_profile.call_count)
예제 #2
0
    def test_dynamic_decorator(self):
        middleware = SilkyMiddleware()
        SilkyConfig().SILKY_DYNAMIC_PROFILING = [{
            'module': 'tests.data.dynamic',
            'function': 'foo'
        }]
        middleware._apply_dynamic_mappings()
        from .data.dynamic import foo

        mock = mock_data_collector()
        with patch('silk.profiling.profiler.DataCollector',
                   return_value=mock) as mock_DataCollector:
            foo()  # Should be wrapped in a decorator
            self.assertTrue(
                mock_DataCollector.return_value.register_profile.call_count)
예제 #3
0
 def test_invalid_dynamic_mapping(self):
     middleware = SilkyMiddleware()
     SilkyConfig().SILKY_DYNAMIC_PROFILING = [{
         'dfgdf': 'tests.data.dynamic',
         'funcgdfgtion': 'bar'
     }]
     self.assertRaises(KeyError, middleware._apply_dynamic_mappings)
예제 #4
0
 def test_invalid_dynamic_decorator_function_name(self):
     middleware = SilkyMiddleware()
     SilkyConfig().SILKY_DYNAMIC_PROFILING = [{
         'module': 'tests.data.dynamic',
         'function': 'bar'
     }]
     self.assertRaises(AttributeError, middleware._apply_dynamic_mappings)
예제 #5
0
 def test_invalid_dynamic_decorator_module(self):
     middleware = SilkyMiddleware(fake_get_response)
     SilkyConfig().SILKY_DYNAMIC_PROFILING = [{
         'module': 'tests.data.dfsdf',
         'function': 'foo'
     }]
     self.assertRaises(AttributeError, middleware._apply_dynamic_mappings)
예제 #6
0
    def test_should_intercept_ignore_paths(self):
        SilkyConfig().SILKY_IGNORE_PATHS = ['/ignorethis']
        request = Request()
        request.path = '/ignorethis'
        should_intercept = SilkyMiddleware()._should_intercept(request)

        self.assertFalse(should_intercept)
예제 #7
0
    def test_dynamic_context_manager(self):
        middleware = SilkyMiddleware()
        SilkyConfig().SILKY_DYNAMIC_PROFILING = [{
            'module': 'tests.data.dynamic',
            'function': 'foo',
            'start_line': 1,
            'end_line': 2,
        }]
        middleware._apply_dynamic_mappings()
        from .data.dynamic import foo

        mock = mock_data_collector()
        with patch('silk.profiling.profiler.DataCollector',
                   return_value=mock) as mock_DataCollector:
            foo()
            self.assertTrue(
                mock_DataCollector.return_value.register_profile.call_count)
예제 #8
0
    def test_dynamic_context_manager(self):
        middleware = SilkyMiddleware()
        SilkyConfig().SILKY_DYNAMIC_PROFILING = [
            {
                'module': 'tests.data.dynamic',
                'function': 'foo',
                'start_line': 1,
                'end_line': 2,
            }
        ]
        middleware._apply_dynamic_mappings()
        from .data.dynamic import foo

        mock = mock_data_collector()
        with patch('silk.profiling.profiler.DataCollector', return_value=mock) as mock_DataCollector:
            foo()
            self.assertTrue(mock_DataCollector.return_value.register_profile.call_count)
예제 #9
0
 def test_invalid_dynamic_context_manager(self):
     middleware = SilkyMiddleware()
     SilkyConfig().SILKY_DYNAMIC_PROFILING = [{
         'module': 'tests.data.dynamic',
         'function': 'foo2',
         'start_line': 1,
         'end_line': 7,
     }]
     self.assertRaises(IndexError, middleware._apply_dynamic_mappings)
예제 #10
0
 def _execute_request(self):
     delete_all_models(Request)
     DataCollector().configure(Request.objects.create())
     response = self._mock_response()
     SilkyMiddleware(fake_get_response)._process_response('', response)
     self.assertTrue(response.status_code == 200)
     objs = Request.objects.all()
     self.assertEqual(objs.count(), 1)
     r = objs[0]
     return r
예제 #11
0
 def test_no_mappings(self):
     middleware = SilkyMiddleware()
     SilkyConfig().SILKY_DYNAMIC_PROFILING = []
     middleware._apply_dynamic_mappings()  # Just checking no crash
예제 #12
0
    def test_no_mappings(self):
        middleware = SilkyMiddleware()
        SilkyConfig().SILKY_DYNAMIC_PROFILING = [

        ]
        middleware._apply_dynamic_mappings()  # Just checking no crash
예제 #13
0
    def test_should_intercept_silk_request(self):
        request = Request()
        request.path = reverse('silk:summary')
        should_intercept = SilkyMiddleware()._should_intercept(request)

        self.assertFalse(should_intercept)
예제 #14
0
    def test_should_intercept_non_silk_request(self):
        request = Request()
        request.path = '/myapp/foo'
        should_intercept = SilkyMiddleware()._should_intercept(request)

        self.assertTrue(should_intercept)