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) callback, callback_args, callback_kwargs = resolver.resolve(request.path_info)
except Exception: except Exception:
self.fail("Failed to resolve URL: %s" % request.path_info) self.fail("Failed to resolve URL: %s" % request.path_info)
self.assertEqual(callback_args, test_path.args) assert callback_args == test_path.args
self.assertEqual(callback_kwargs, test_path.kwargs) assert callback_kwargs == test_path.kwargs
def test_trailing_slash(self): def test_trailing_slash(self):
factory = APIRequestFactory() factory = APIRequestFactory()

View File

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