From 4b59ec27fa725a83646792b560fae1b646baadcd Mon Sep 17 00:00:00 2001 From: Asif Saifuddin Auvi Date: Wed, 23 Nov 2016 19:17:00 +0600 Subject: [PATCH] convert tests asserts to pytest style (#4696) --- tests/test_views.py | 16 ++++++++-------- tests/test_viewsets.py | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/test_views.py b/tests/test_views.py index 05c499481..adafa1cd7 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -71,8 +71,8 @@ class ClassBasedViewIntegrationTests(TestCase): expected = { 'detail': JSON_ERROR } - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - self.assertEqual(sanitise_json_error(response.data), expected) + assert response.status_code == status.HTTP_400_BAD_REQUEST + assert sanitise_json_error(response.data) == expected class FunctionBasedViewIntegrationTests(TestCase): @@ -85,8 +85,8 @@ class FunctionBasedViewIntegrationTests(TestCase): expected = { 'detail': JSON_ERROR } - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - self.assertEqual(sanitise_json_error(response.data), expected) + assert response.status_code == status.HTTP_400_BAD_REQUEST + assert sanitise_json_error(response.data) == expected class TestCustomExceptionHandler(TestCase): @@ -107,8 +107,8 @@ class TestCustomExceptionHandler(TestCase): request = factory.get('/', content_type='application/json') response = view(request) expected = 'Error!' - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - self.assertEqual(response.data, expected) + assert response.status_code == status.HTTP_400_BAD_REQUEST + assert response.data == expected def test_function_based_view_exception_handler(self): view = error_view @@ -116,5 +116,5 @@ class TestCustomExceptionHandler(TestCase): request = factory.get('/', content_type='application/json') response = view(request) expected = 'Error!' - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - self.assertEqual(response.data, expected) + assert response.status_code == status.HTTP_400_BAD_REQUEST + assert response.data == expected diff --git a/tests/test_viewsets.py b/tests/test_viewsets.py index 0d9b6b310..a3c4e6be5 100644 --- a/tests/test_viewsets.py +++ b/tests/test_viewsets.py @@ -21,15 +21,15 @@ class InitializeViewSetsTestCase(TestCase): }) response = my_view(request) - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data, {'ACTION': 'LIST'}) + assert response.status_code == status.HTTP_200_OK + assert response.data == {'ACTION': 'LIST'} def test_initialize_view_set_with_empty_actions(self): try: BasicViewSet.as_view() except TypeError as e: - self.assertEqual(str(e), "The `actions` argument must be provided " - "when calling `.as_view()` on a ViewSet. " - "For example `.as_view({'get': 'list'})`") + assert str(e) == ("The `actions` argument must be provided " + "when calling `.as_view()` on a ViewSet. " + "For example `.as_view({'get': 'list'})`") else: self.fail("actions must not be empty.")