def test_create_skipped_test_for_not_supported_endpoint( self, http_method, mocked_normalize): mocked_normalize.return_value = [] tests_generator = SmokeTestsGenerator() url_pattern = URLPattern(r'^{}$'.format(create_random_string()), RedirectView.as_view(url='/', permanent=False), name=create_random_string()) expected_test_name = tests_generator.create_test_name( http_method, get_pattern(url_pattern)) tests_generator.create_tests_for_endpoint(get_pattern(url_pattern), url_pattern.name) self.assertTrue(hasattr(SmokeTests, expected_test_name)) is_successful, failures, skipped = self._execute_smoke_test( expected_test_name) self.assertEqual(len(skipped), 1) self.assertEqual(len(tests_generator.warnings), 1)
def test_if_view_decorated_with_wraps_is_added_for_specified_app( self, mocked_call_command): url_pattern = url_patterns_with_decorator_with_wraps[0] http_method = 'GET' tests_generator = SmokeTestsGenerator(app_names=['tests.app'], http_methods=[http_method]) tests_generator.execute() expected_test_name = self.tests_generator.create_test_name( http_method, '^app_urls/' + get_pattern(url_pattern)) self.assertTrue(hasattr(SmokeTests, expected_test_name)) mocked_call_command.assert_called_once()
def test_if_authentication_is_successful(self, url_pattern_with_auth, mocked_call_command): tests_generator = SmokeTestsGenerator() tests_generator.execute() expected_test_name = self.tests_generator.create_test_name( 'GET', get_pattern(url_pattern_with_auth)) is_successful, failures, skipped = self._execute_smoke_test( expected_test_name) mocked_call_command.assert_called_once() self.assertTrue(is_successful) self.assertEqual(failures, []) self.assertEqual(tests_generator.warnings, [])
def test_if_view_decorated_without_wraps_is_not_added_for_specified_app( self, mocked_call_command): # it's not possible to retrieve callback (view) module when it's wrapped in decorator url_pattern = url_patterns_with_decorator_without_wraps[0] http_method = 'GET' tests_generator = SmokeTestsGenerator(app_names=['tests.app'], http_methods=[http_method]) tests_generator.execute() expected_test_name = self.tests_generator.create_test_name( http_method, '^app_urls/' + get_pattern(url_pattern)) self.assertFalse(hasattr(SmokeTests, expected_test_name)) mocked_call_command.assert_called_once()
def test_only_proper_tests_were_created_for_custom_methods(self, mocked_call_command): shuffled_methods = random.sample(self.all_possible_methods, len(self.all_possible_methods)) split_index = random.randint(1, len(shuffled_methods) - 1) methods_to_call = shuffled_methods[:split_index] methods_not_called = shuffled_methods[split_index:] call_command('smoke_tests', http_methods=','.join(methods_to_call)) mocked_call_command.assert_called_once() # skip RegexURLResolver (eg. include(app.urls)) urlpatterns_without_resolvers = [ url for url in urlpatterns if isinstance(url, URLPattern) ] for url in urlpatterns_without_resolvers: for method in methods_to_call: test_name = self.test_generator.create_test_name(method, get_pattern(url)) self.assertTrue(hasattr(SmokeTests, test_name)) for method in methods_not_called: test_name = self.test_generator.create_test_name(method, get_pattern(url)) self.assertFalse(hasattr(SmokeTests, test_name))
def test_proper_tests_were_created_for_default_methods(self, mocked_call_command): call_command('smoke_tests') mocked_call_command.assert_called_once() # skip RegexURLResolver (eg. include(app.urls)) urlpatterns_without_resolvers = [ url for url in urlpatterns if isinstance(url, URLPattern) ] for url in urlpatterns_without_resolvers: for method in self.test_generator.SUPPORTED_HTTP_METHODS: test_name = self.test_generator.create_test_name(method, get_pattern(url)) self.assertTrue(hasattr(SmokeTests, test_name))
def test_smoke_test_is_created_only_for_specified_app( self, mocked_call_command): outside_app_url_pattern = URLPattern( r'^{}$'.format(create_random_string()), RedirectView.as_view(url='/', permanent=False), name=create_random_string()) outside_app_test_name = self.tests_generator.create_test_name( 'GET', get_pattern(outside_app_url_pattern)) inside_app_url_pattern = app_url_patterns[0] inside_app_url_full_pattern = '^app_urls/' + get_pattern( inside_app_url_pattern) inside_app_test_name = self.tests_generator.create_test_name( 'GET', inside_app_url_full_pattern) tests_generator = SmokeTestsGenerator(app_names=['tests.app']) tests_generator.execute() self.assertFalse(hasattr(SmokeTests, outside_app_test_name)) self.assertTrue(hasattr(SmokeTests, inside_app_test_name)) mocked_call_command.assert_called_once_with('test', 'django_smoke_tests')
def test_skipped_app_url(self, mocked_call_command): url_pattern = skipped_app_url_patterns[0] http_method = 'GET' tests_generator = SmokeTestsGenerator(http_methods=[http_method]) tests_generator.execute() expected_test_name = tests_generator.create_test_name( http_method, '^app_urls/' + get_pattern(url_pattern)) self.assertTrue(hasattr(SmokeTests, expected_test_name)) is_successful, failures, skipped = self._execute_smoke_test( expected_test_name) self.assertTrue(is_successful) self.assertEqual(len(skipped), 1) self.assertEqual(failures, [])
def test_if_url_is_not_skipped_when_setting_is_empty( self, mocked_call_command): url_pattern = skipped_url_patterns[0] http_method = 'GET' tests_generator = SmokeTestsGenerator(http_methods=[http_method]) tests_generator.execute() expected_test_name = tests_generator.create_test_name( http_method, get_pattern(url_pattern)) self.assertTrue(hasattr(SmokeTests, expected_test_name)) is_successful, failures, skipped = self._execute_smoke_test( expected_test_name) self.assertTrue(is_successful) self.assertEqual(skipped, []) self.assertEqual(failures, [])