def test_missing_named_urls_complained_about(self): with mocked_patterns([ url(r'^tested-url/$', WorkingView.as_view()), url(r'^untested-url/$', WorkingView.as_view(), name='name'), ]): results = get_results_for('test_all_urls_accounted_for', covered_urls=['/tested-url/']) self.assertEqual( results.failures[0][1][1].args[0], "The following views are untested:\n\n" "() ^untested-url/$ (name)\n\n" + IGNORE_TUTORIAL.format(name='EverythingTest') )
def test_missing_named_urls_complained_about(self): with override_settings(ROOT_URLCONF=patterns( '', url(r'^tested-url/$', WorkingView.as_view()), url(r'^untested-url/$', WorkingView.as_view(), name='name'), ), ): results = get_results_for('test_all_urls_accounted_for', covered_urls=['/tested-url/']) self.assertEqual( results.failures[0][1][1][0], "The following views are untested:\n\n" "() ^untested-url/$ (name)\n\n" + IGNORE_TUTORIAL.format(name='EverythingTest'))
def test_missing_nameless_urls_complained_about(self): with override_settings( ROOT_URLCONF=patterns( '', url(r'^tested-url/$', WorkingView.as_view()), url(r'^untested-url/$', WorkingView.as_view()), ), ): results = get_results_for('test_all_urls_accounted_for', covered_urls=['/tested-url/']) self.assertEqual( results.failures[0][1][1].args[0], "The following views are untested:\n\n" "() ^untested-url/$ (None)\n\n" + IGNORE_TUTORIAL.format(name='EverythingTest') )
def test_missing_url_in_include(self): incl = [ url(r'^broken-url/$', BrokenView.as_view()), ] with mocked_patterns([ url(r'^include/', include(incl)), ]), override_settings( COVERED_URLS=[], ): results = get_results_for('test_all_urls_accounted_for') self.assertEqual( results.failures[0][1][1].args[0], "The following views are untested:\n\n" "('^include/',) ^broken-url/$ (None)\n\n" + IGNORE_TUTORIAL.format(name='EverythingTest') )
def test_excepted_urls_not_complained_about(self): with mocked_patterns(patterns( '', url(r'^tested-url/$', WorkingView.as_view()), url(r'^untested-url/$', WorkingView.as_view()), url(r'^deliberately-untested-url/$', WorkingView.as_view()), )): results = get_results_for( 'test_all_urls_accounted_for', covered_urls=['/tested-url/'], uncovered_urls=['/deliberately-untested-url/']) self.assertEqual( results.failures[0][1][1].args[0], "The following views are untested:\n\n" "() ^untested-url/$ (None)\n\n" + IGNORE_TUTORIAL.format(name='EverythingTest') )
def test_missing_url_in_include(self): incl = patterns( '', url(r'^broken-url/$', BrokenView.as_view()), ) with override_settings( ROOT_URLCONF=patterns( '', url(r'^include/', include(incl)), ), COVERED_URLS=[], ): results = get_results_for('test_all_urls_accounted_for') self.assertEqual( results.failures[0][1][1][0], "The following views are untested:\n\n" "('^include/',) ^broken-url/$ (None)\n\n" + IGNORE_TUTORIAL.format(name='EverythingTest'))
def test_messaging_for_non_regex_patterns(self): if django.VERSION < (2, 0): self.skipTest('only works on django 2.0 or newer') from django.urls import path with mocked_patterns([ path('tested-url/', WorkingView.as_view()), path('untested-url/', WorkingView.as_view()), url(r'^another-untested-url/$', WorkingView.as_view()), ]): results = get_results_for('test_all_urls_accounted_for', covered_urls=['/tested-url/']) self.assertEqual( 'The following views are untested:\n\n' '() untested-url/ (None)\n' '() ^another-untested-url/$ (None)\n\n{}' .format(IGNORE_TUTORIAL.format(name='EverythingTest')), results.failures[0][1][1].args[0], )
def test_non_list_urls(self): """ Ensure you can use a tuple of URLs if you so desire. """ with mocked_patterns([ url(r'^$', BrokenView.as_view()), url(r'^untested/$', WorkingView.as_view()), ]): self.assertEqual( get_results_for('test_no_errors', covered_urls='/',).failures[0][1][1].args[0], "The following errors were raised:\n\n" "/: this view is broken\n\n" + INSTANT_TRACEBACKS_TUTORIAL.format(name='EverythingTest') ) self.assertEqual( get_results_for('test_all_urls_accounted_for', covered_urls='/',).failures[0][1][1].args[0], "The following views are untested:\n\n" "() ^untested/$ (None)\n\n" + IGNORE_TUTORIAL.format(name='EverythingTest') )