Esempio n. 1
0
 def test_is_config_loaded_with_invalid_dict(self):
     with patch(
             'edx_django_utils.monitoring.code_owner.utils._PATH_TO_CODE_OWNER_MAPPINGS',
             _process_code_owner_mappings()):
         self.assertTrue(
             is_code_owner_mappings_configured(),
             "Although invalid, mappings should be configured.")
 def test_catch_all_instead_of_errors(self, mock_set_custom_attribute):
     with patch(
             'edx_django_utils.monitoring.code_owner.utils._PATH_TO_CODE_OWNER_MAPPINGS',
             _process_code_owner_mappings()
     ):
         request = RequestFactory().get('/bad/path/')
         self.middleware(request)
         self._assert_code_owner_custom_attributes(mock_set_custom_attribute, expected_code_owner='team-red')
Esempio n. 3
0
 def test_load_config_with_invalid_dict(self):
     with patch(
             'edx_django_utils.monitoring.code_owner.utils._PATH_TO_CODE_OWNER_MAPPINGS',
             _process_code_owner_mappings()):
         self.assertTrue(
             is_code_owner_mappings_configured(),
             "Although invalid, mappings should be configured.")
         with self.assertRaises(AssertionError):
             get_code_owner_from_module('xblock')
 def test_no_resolver_for_path_and_no_transaction(self, mock_set_custom_attribute):
     with patch(
             'edx_django_utils.monitoring.code_owner.utils._PATH_TO_CODE_OWNER_MAPPINGS',
             _process_code_owner_mappings()
     ):
         request = RequestFactory().get('/bad/path/')
         self.middleware(request)
         self._assert_code_owner_custom_attributes(
             mock_set_custom_attribute, has_path_error=True, has_transaction_error=True
         )
 def test_code_owner_transaction_mapping_error(self, mock_newrelic_agent, mock_set_custom_attribute):
     mock_newrelic_agent.current_transaction = Mock(side_effect=Exception('forced exception'))
     with patch(
             'edx_django_utils.monitoring.code_owner.utils._PATH_TO_CODE_OWNER_MAPPINGS',
             _process_code_owner_mappings()
     ):
         request = RequestFactory().get('/bad/path/')
         self.middleware(request)
         self._assert_code_owner_custom_attributes(
             mock_set_custom_attribute, has_path_error=True, has_transaction_error=True
         )
 def test_load_config_with_invalid_dict(self, mock_set_custom_attribute):
     with patch(
             'edx_django_utils.monitoring.code_owner.utils._PATH_TO_CODE_OWNER_MAPPINGS',
             _process_code_owner_mappings()
     ):
         request = RequestFactory().get('/test/')
         self.middleware(request)
         expected_path_module = self._REQUEST_PATH_TO_MODULE_PATH['/test/']
         self._assert_code_owner_custom_attributes(
             mock_set_custom_attribute, path_module=expected_path_module,
             has_path_error=True, has_transaction_error=True
         )
 def test_code_owner_path_mapping_with_catch_all(
     self, request_path, expected_owner, mock_set_custom_attribute
 ):
     with patch(
             'edx_django_utils.monitoring.code_owner.utils._PATH_TO_CODE_OWNER_MAPPINGS',
             _process_code_owner_mappings()
     ):
         request = RequestFactory().get(request_path)
         self.middleware(request)
         expected_path_module = self._REQUEST_PATH_TO_MODULE_PATH[request_path]
         self._assert_code_owner_custom_attributes(
             mock_set_custom_attribute, expected_code_owner=expected_owner, path_module=expected_path_module
         )
 def test_code_owner_transaction_mapping__with_catch_all(
     self, transaction_name, expected_owner, mock_newrelic_agent, mock_set_custom_attribute
 ):
     mock_newrelic_agent.current_transaction().name = transaction_name
     with patch(
             'edx_django_utils.monitoring.code_owner.utils._PATH_TO_CODE_OWNER_MAPPINGS',
             _process_code_owner_mappings()
     ):
         request = RequestFactory().get('/bad/path/')
         self.middleware(request)
         self._assert_code_owner_custom_attributes(
             mock_set_custom_attribute, expected_code_owner=expected_owner, transaction_name=transaction_name
         )
Esempio n. 9
0
 def test_mapping_performance(self):
     code_owner_mappings = {'team-red': []}
     # create a long list of mappings that are nearly identical
     for n in range(1, 200):
         path = 'openedx.core.djangoapps.{}'.format(n)
         code_owner_mappings['team-red'].append(path)
     with override_settings(CODE_OWNER_MAPPINGS=code_owner_mappings):
         with patch(
                 'edx_django_utils.monitoring.code_owner.utils._PATH_TO_CODE_OWNER_MAPPINGS',
                 _process_code_owner_mappings()):
             call_iterations = 100
             time = timeit.timeit(
                 # test a module name that matches nearly to the end, but doesn't actually match
                 lambda: get_code_owner_from_module(
                     'openedx.core.djangoapps.XXX.views'),
                 number=call_iterations)
             average_time = time / call_iterations
             self.assertLess(
                 average_time, 0.0005,
                 'Mapping takes {}s which is too slow.'.format(
                     average_time))
Esempio n. 10
0
 def test_code_owner_mapping_hits_and_misses(self, module, expected_owner):
     with patch(
             'edx_django_utils.monitoring.code_owner.utils._PATH_TO_CODE_OWNER_MAPPINGS',
             _process_code_owner_mappings()):
         actual_owner = get_code_owner_from_module(module)
         self.assertEqual(expected_owner, actual_owner)
Esempio n. 11
0
 def test_is_config_loaded_with_no_config(self):
     with patch(
             'edx_django_utils.monitoring.code_owner.utils._PATH_TO_CODE_OWNER_MAPPINGS',
             _process_code_owner_mappings()):
         self.assertFalse(is_code_owner_mappings_configured(),
                          "Mappings should not be configured.")