Skip to content

Commit

Permalink
Increase urls utils tests coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
hramezani committed Jul 19, 2018
1 parent 08ebed5 commit 83a4aca
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions tests/urlpatterns_reverse/tests.py
Expand Up @@ -1141,16 +1141,40 @@ def test_view_loading(self):
# passing a callable should return the callable
self.assertEqual(get_callable(empty_view), empty_view)

def test_exceptions(self):
# A missing view (identified by an AttributeError) should raise
def test_view_does_not_exist(self):
# missing view (identified by an AttributeError) should raise
# ViewDoesNotExist, ...
with self.assertRaisesMessage(ViewDoesNotExist, "View does not exist in"):
msg = "View does not exist in module urlpatterns_reverse.views."
with self.assertRaisesMessage(ViewDoesNotExist, msg):
get_callable('urlpatterns_reverse.views.i_should_not_exist')
# ... but if the AttributeError is caused by something else don't

def test_other_error(self):
# if the AttributeError is caused by something else don't
# swallow it.
with self.assertRaises(AttributeError):
get_callable('urlpatterns_reverse.views_broken.i_am_broken')

def test_non_string_value(self):
# Pass non string value, ViewDoesNotExist should raise
msg = "'1' is not a callable or a dot-notation path"
with self.assertRaisesMessage(ViewDoesNotExist, msg):
get_callable(1)

def test_string_without_dot(self):
# Pass string without dot, ImportError should raise
msg = "Could not import 'test'. The path must be fully qualified."
with self.assertRaisesMessage(ImportError, msg):
get_callable('test')

def test_module_does_not_exist(self):
with self.assertRaisesMessage(ImportError, "No module named 'foo'"):
get_callable('foo.bar')

def test_parent_module_does_not_exist(self):
msg = "Parent module urlpatterns_reverse.foo does not exist."
with self.assertRaisesMessage(ViewDoesNotExist, msg):
get_callable('urlpatterns_reverse.foo.bar')


class IncludeTests(SimpleTestCase):
url_patterns = [
Expand Down

0 comments on commit 83a4aca

Please sign in to comment.