8000 convert tests asserts to pytest style (#4696) · burnash/django-rest-framework@4b59ec2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4b59ec2

Browse files
auvipytomchristie
authored andcommitted
convert tests asserts to pytest style (encode#4696)
1 parent 3e1b31b commit 4b59ec2

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

tests/test_views.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def test_400_parse_error(self):
7171
expected = {
7272
'detail': JSON_ERROR
7373
}
74-
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
75-
self.assertEqual(sanitise_json_error(response.data), expected)
74+
assert response.status_code == status.HTTP_400_BAD_REQUEST
75+
assert sanitise_json_error(response.data) == expected
7676

7777

7878
class FunctionBasedViewIntegrationTests(TestCase):
@@ -85,8 +85,8 @@ def test_400_parse_error(self):
8585
expected = {
8686
'detail': JSON_ERROR
8787
}
88-
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
89-
self.assertEqual(sanitise_json_error(response.data), expected)
88+
assert response.status_code == status.HTTP_400_BAD_REQUEST
89+
assert sanitise_json_error(response.data) == expected
9090

9191

9292
class TestCustomExceptionHandler(TestCase):
@@ -107,14 +107,14 @@ def test_class_based_view_exception_handler(self):
107107
request = factory.get('/', content_type='application/json')
108108
response = view(request)
109109
expected = 'Error!'
110-
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
111-
self.assertEqual(response.data, expected)
110+
assert response.status_code == status.HTTP_400_BAD_REQUEST
111+
assert response.data == expected
112112

113113
def test_function_based_view_exception_handler(self):
114114
view = error_view
115115

116116
request = factory.get('/', content_type='application/json')
117117
response = view(request)
118118
expected = 'Error!'
119-
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
120-
self.assertEqual(response.data, expected)
119+
assert response.status_code == status.HTTP_400_BAD_REQUEST
120+
assert response.data == expected

tests/test_viewsets.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ def test_initialize_view_set_with_actions(self):
2121
})
2222

2323
response = my_view(request)
24-
self.assertEqual(response.status_code, status.HTTP_200_OK)
25-
self.assertEqual(response.data, {'ACTION': 'LIST'})
24+
assert response.status_code == status.HTTP_200_OK
25+
assert response.data == {'ACTION': 'LIST'}
2626

2727
def test_initialize_view_set_with_empty_actions(self):
2828
try:
2929
BasicViewSet.as_view()
3030
except TypeError as e:
31-
self.assertEqual(str(e), "The `actions` argument must be provided "
32-
"when calling `.as_view()` on a ViewSet. "
33-
"For example `.as_view({'get': 'list'})`")
31+
assert str(e) == ("The `actions` argument must be provided "
32+
"when calling `.as_view()` on a ViewSet. "
33+
"For example `.as_view({'get': 'list'})`")
3434
else:
3535
self.fail("actions must not be empty.")

0 commit comments

Comments
 (0)
0