mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +03:00
convert tests asserts to pytest style (#4696)
This commit is contained in:
parent
3e1b31bb9b
commit
4b59ec27fa
|
@ -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
|
||||
|
|
|
@ -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.")
|
||||
|
|
Loading…
Reference in New Issue
Block a user