convert some more test asserts to pytest (#4778)

* converted urlpatterns test asserts to pytest

* converted test utils asserts to pytest

* removed extra newlines
This commit is contained in:
Asif Saifuddin Auvi 2017-01-04 15:13:32 +06:00 committed by Tom Christie
parent eddc34f4c8
commit 7874bcabe9
2 changed files with 38 additions and 63 deletions

View File

@ -35,8 +35,8 @@ class FormatSuffixTests(TestCase):
callback, callback_args, callback_kwargs = resolver.resolve(request.path_info)
except Exception:
self.fail("Failed to resolve URL: %s" % request.path_info)
self.assertEqual(callback_args, test_path.args)
self.assertEqual(callback_kwargs, test_path.kwargs)
assert callback_args == test_path.args
assert callback_kwargs == test_path.kwargs
def test_trailing_slash(self):
factory = APIRequestFactory()

View File

@ -65,85 +65,60 @@ class BreadcrumbTests(TestCase):
"""
def test_root_breadcrumbs(self):
url = '/'
self.assertEqual(
get_breadcrumbs(url),
[('Root', '/')]
)
assert get_breadcrumbs(url) == [('Root', '/')]
def test_resource_root_breadcrumbs(self):
url = '/resource/'
self.assertEqual(
get_breadcrumbs(url),
[
('Root', '/'),
('Resource Root', '/resource/')
]
)
assert get_breadcrumbs(url) == [
('Root', '/'), ('Resource Root', '/resource/')
]
def test_resource_instance_breadcrumbs(self):
url = '/resource/123'
self.assertEqual(
get_breadcrumbs(url),
[
('Root', '/'),
('Resource Root', '/resource/'),
('Resource Instance', '/resource/123')
]
)
assert get_breadcrumbs(url) == [
('Root', '/'),
('Resource Root', '/resource/'),
('Resource Instance', '/resource/123')
]
def test_resource_instance_customname_breadcrumbs(self):
url = '/resource/customname'
self.assertEqual(
get_breadcrumbs(url),
[
('Root', '/'),
('Resource Root', '/resource/'),
('Foo', '/resource/customname')
]
)
assert get_breadcrumbs(url) == [
('Root', '/'),
('Resource Root', '/resource/'),
('Foo', '/resource/customname')
]
def test_nested_resource_breadcrumbs(self):
url = '/resource/123/'
self.assertEqual(
get_breadcrumbs(url),
[
('Root', '/'),
('Resource Root', '/resource/'),
('Resource Instance', '/resource/123'),
('Nested Resource Root', '/resource/123/')
]
)
assert get_breadcrumbs(url) == [
('Root', '/'),
('Resource Root', '/resource/'),
('Resource Instance', '/resource/123'),
('Nested Resource Root', '/resource/123/')
]
def test_nested_resource_instance_breadcrumbs(self):
url = '/resource/123/abc'
self.assertEqual(
get_breadcrumbs(url),
[
('Root', '/'),
('Resource Root', '/resource/'),
('Resource Instance', '/resource/123'),
('Nested Resource Root', '/resource/123/'),
('Nested Resource Instance', '/resource/123/abc')
]
)
assert get_breadcrumbs(url) == [
('Root', '/'),
('Resource Root', '/resource/'),
('Resource Instance', '/resource/123'),
('Nested Resource Root', '/resource/123/'),
('Nested Resource Instance', '/resource/123/abc')
]
def test_broken_url_breadcrumbs_handled_gracefully(self):
url = '/foobar'
self.assertEqual(
get_breadcrumbs(url),
[('Root', '/')]
)
assert get_breadcrumbs(url) == [('Root', '/')]
def test_modelviewset_resource_instance_breadcrumbs(self):
url = '/resources/1/'
self.assertEqual(
get_breadcrumbs(url),
[
('Root', '/'),
('Resource List', '/resources/'),
('Resource Instance', '/resources/1/')
]
)
assert get_breadcrumbs(url) == [
('Root', '/'),
('Resource List', '/resources/'),
('Resource Instance', '/resources/1/')
]
class ResolveModelTests(TestCase):
@ -154,15 +129,15 @@ class ResolveModelTests(TestCase):
"""
def test_resolve_django_model(self):
resolved_model = _resolve_model(BasicModel)
self.assertEqual(resolved_model, BasicModel)
assert resolved_model == BasicModel
def test_resolve_string_representation(self):
resolved_model = _resolve_model('tests.BasicModel')
self.assertEqual(resolved_model, BasicModel)
assert resolved_model == BasicModel
def test_resolve_unicode_representation(self):
resolved_model = _resolve_model(six.text_type('tests.BasicModel'))
self.assertEqual(resolved_model, BasicModel)
assert resolved_model == BasicModel
def test_resolve_non_django_model(self):
with self.assertRaises(ValueError):