diff --git a/tests/test_generics.py b/tests/test_generics.py
index 247237584..2c3679c46 100644
--- a/tests/test_generics.py
+++ b/tests/test_generics.py
@@ -98,8 +98,8 @@ class TestRootView(TestCase):
request = factory.get('/')
with self.assertNumQueries(1):
response = self.view(request).render()
- self.assertEqual(response.status_code, status.HTTP_200_OK)
- self.assertEqual(response.data, self.data)
+ assert response.status_code == status.HTTP_200_OK
+ assert response.data == self.data
def test_post_root_view(self):
"""
@@ -109,10 +109,10 @@ class TestRootView(TestCase):
request = factory.post('/', data, format='json')
with self.assertNumQueries(1):
response = self.view(request).render()
- self.assertEqual(response.status_code, status.HTTP_201_CREATED)
- self.assertEqual(response.data, {'id': 4, 'text': 'foobar'})
+ assert response.status_code == status.HTTP_201_CREATED
+ assert response.data == {'id': 4, 'text': 'foobar'}
created = self.objects.get(id=4)
- self.assertEqual(created.text, 'foobar')
+ assert created.text == 'foobar'
def test_put_root_view(self):
"""
@@ -122,8 +122,8 @@ class TestRootView(TestCase):
request = factory.put('/', data, format='json')
with self.assertNumQueries(0):
response = self.view(request).render()
- self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
- self.assertEqual(response.data, {"detail": 'Method "PUT" not allowed.'})
+ assert response.status_code == status.HTTP_405_METHOD_NOT_ALLOWED
+ assert response.data == {"detail": 'Method "PUT" not allowed.'}
def test_delete_root_view(self):
"""
@@ -132,8 +132,8 @@ class TestRootView(TestCase):
request = factory.delete('/')
with self.assertNumQueries(0):
response = self.view(request).render()
- self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
- self.assertEqual(response.data, {"detail": 'Method "DELETE" not allowed.'})
+ assert response.status_code == status.HTTP_405_METHOD_NOT_ALLOWED
+ assert response.data == {"detail": 'Method "DELETE" not allowed.'}
def test_post_cannot_set_id(self):
"""
@@ -143,10 +143,10 @@ class TestRootView(TestCase):
request = factory.post('/', data, format='json')
with self.assertNumQueries(1):
response = self.view(request).render()
- self.assertEqual(response.status_code, status.HTTP_201_CREATED)
- self.assertEqual(response.data, {'id': 4, 'text': 'foobar'})
+ assert response.status_code == status.HTTP_201_CREATED
+ assert response.data == {'id': 4, 'text': 'foobar'}
created = self.objects.get(id=4)
- self.assertEqual(created.text, 'foobar')
+ assert created.text == 'foobar'
def test_post_error_root_view(self):
"""
@@ -156,7 +156,7 @@ class TestRootView(TestCase):
request = factory.post('/', data, HTTP_ACCEPT='text/html')
response = self.view(request).render()
expected_error = 'Ensure this field has no more than 100 characters.'
- self.assertIn(expected_error, response.rendered_content.decode('utf-8'))
+ assert expected_error in response.rendered_content.decode('utf-8')
EXPECTED_QUERIES_FOR_PUT = 2
@@ -185,8 +185,8 @@ class TestInstanceView(TestCase):
request = factory.get('/1')
with self.assertNumQueries(1):
response = self.view(request, pk=1).render()
- self.assertEqual(response.status_code, status.HTTP_200_OK)
- self.assertEqual(response.data, self.data[0])
+ assert response.status_code == status.HTTP_200_OK
+ assert response.data == self.data[0]
def test_post_instance_view(self):
"""
@@ -196,8 +196,8 @@ class TestInstanceView(TestCase):
request = factory.post('/', data, format='json')
with self.assertNumQueries(0):
response = self.view(request).render()
- self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
- self.assertEqual(response.data, {"detail": 'Method "POST" not allowed.'})
+ assert response.status_code == status.HTTP_405_METHOD_NOT_ALLOWED
+ assert response.data == {"detail": 'Method "POST" not allowed.'}
def test_put_instance_view(self):
"""
@@ -207,10 +207,10 @@ class TestInstanceView(TestCase):
request = factory.put('/1', data, format='json')
with self.assertNumQueries(EXPECTED_QUERIES_FOR_PUT):
response = self.view(request, pk='1').render()
- self.assertEqual(response.status_code, status.HTTP_200_OK)
- self.assertEqual(dict(response.data), {'id': 1, 'text': 'foobar'})
+ assert response.status_code == status.HTTP_200_OK
+ assert dict(response.data) == {'id': 1, 'text': 'foobar'}
updated = self.objects.get(id=1)
- self.assertEqual(updated.text, 'foobar')
+ assert updated.text == 'foobar'
def test_patch_instance_view(self):
"""
@@ -221,10 +221,10 @@ class TestInstanceView(TestCase):
with self.assertNumQueries(EXPECTED_QUERIES_FOR_PUT):
response = self.view(request, pk=1).render()
- self.assertEqual(response.status_code, status.HTTP_200_OK)
- self.assertEqual(response.data, {'id': 1, 'text': 'foobar'})
+ assert response.status_code == status.HTTP_200_OK
+ assert response.data == {'id': 1, 'text': 'foobar'}
updated = self.objects.get(id=1)
- self.assertEqual(updated.text, 'foobar')
+ assert updated.text == 'foobar'
def test_delete_instance_view(self):
"""
@@ -233,10 +233,10 @@ class TestInstanceView(TestCase):
request = factory.delete('/1')
with self.assertNumQueries(2):
response = self.view(request, pk=1).render()
- self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
- self.assertEqual(response.content, six.b(''))
+ assert response.status_code == status.HTTP_204_NO_CONTENT
+ assert response.content == six.b('')
ids = [obj.id for obj in self.objects.all()]
- self.assertEqual(ids, [2, 3])
+ assert ids == [2, 3]
def test_get_instance_view_incorrect_arg(self):
"""
@@ -246,7 +246,7 @@ class TestInstanceView(TestCase):
request = factory.get('/a')
with self.assertNumQueries(0):
response = self.view(request, pk='a').render()
- self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
+ assert response.status_code == status.HTTP_404_NOT_FOUND
def test_put_cannot_set_id(self):
"""
@@ -256,10 +256,10 @@ class TestInstanceView(TestCase):
request = factory.put('/1', data, format='json')
with self.assertNumQueries(EXPECTED_QUERIES_FOR_PUT):
response = self.view(request, pk=1).render()
- self.assertEqual(response.status_code, status.HTTP_200_OK)
- self.assertEqual(response.data, {'id': 1, 'text': 'foobar'})
+ assert response.status_code == status.HTTP_200_OK
+ assert response.data == {'id': 1, 'text': 'foobar'}
updated = self.objects.get(id=1)
- self.assertEqual(updated.text, 'foobar')
+ assert updated.text == 'foobar'
def test_put_to_deleted_instance(self):
"""
@@ -271,7 +271,7 @@ class TestInstanceView(TestCase):
request = factory.put('/1', data, format='json')
with self.assertNumQueries(1):
response = self.view(request, pk=1).render()
- self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
+ assert response.status_code == status.HTTP_404_NOT_FOUND
def test_put_to_filtered_out_instance(self):
"""
@@ -282,7 +282,7 @@ class TestInstanceView(TestCase):
filtered_out_pk = BasicModel.objects.filter(text='filtered out')[0].pk
request = factory.put('/{0}'.format(filtered_out_pk), data, format='json')
response = self.view(request, pk=filtered_out_pk).render()
- self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
+ assert response.status_code == status.HTTP_404_NOT_FOUND
def test_patch_cannot_create_an_object(self):
"""
@@ -292,8 +292,8 @@ class TestInstanceView(TestCase):
request = factory.patch('/999', data, format='json')
with self.assertNumQueries(1):
response = self.view(request, pk=999).render()
- self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
- self.assertFalse(self.objects.filter(id=999).exists())
+ assert response.status_code == status.HTTP_404_NOT_FOUND
+ assert not self.objects.filter(id=999).exists()
def test_put_error_instance_view(self):
"""
@@ -303,7 +303,7 @@ class TestInstanceView(TestCase):
request = factory.put('/', data, HTTP_ACCEPT='text/html')
response = self.view(request, pk=1).render()
expected_error = 'Ensure this field has no more than 100 characters.'
- self.assertIn(expected_error, response.rendered_content.decode('utf-8'))
+ assert expected_error in response.rendered_content.decode('utf-8')
class TestFKInstanceView(TestCase):
@@ -363,8 +363,8 @@ class TestOverriddenGetObject(TestCase):
request = factory.get('/1')
with self.assertNumQueries(1):
response = self.view(request, pk=1).render()
- self.assertEqual(response.status_code, status.HTTP_200_OK)
- self.assertEqual(response.data, self.data[0])
+ assert response.status_code == status.HTTP_200_OK
+ assert response.data == self.data[0]
# Regression test for #285
@@ -394,9 +394,9 @@ class TestCreateModelWithAutoNowAddField(TestCase):
data = {'email': 'foobar@example.com', 'content': 'foobar'}
request = factory.post('/', data, format='json')
response = self.view(request).render()
- self.assertEqual(response.status_code, status.HTTP_201_CREATED)
+ assert response.status_code == status.HTTP_201_CREATED
created = self.objects.get(id=1)
- self.assertEqual(created.content, 'foobar')
+ assert created.content == 'foobar'
# Test for particularly ugly regression with m2m in browsable API
@@ -432,7 +432,7 @@ class TestM2MBrowsableAPI(TestCase):
request = factory.get('/', HTTP_ACCEPT='text/html')
view = ExampleView().as_view()
response = view(request).render()
- self.assertEqual(response.status_code, status.HTTP_200_OK)
+ assert response.status_code == status.HTTP_200_OK
class InclusiveFilterBackend(object):
@@ -489,9 +489,9 @@ class TestFilterBackendAppliedToViews(TestCase):
root_view = RootView.as_view(filter_backends=(InclusiveFilterBackend,))
request = factory.get('/')
response = root_view(request).render()
- self.assertEqual(response.status_code, status.HTTP_200_OK)
- self.assertEqual(len(response.data), 1)
- self.assertEqual(response.data, [{'id': 1, 'text': 'foo'}])
+ assert response.status_code == status.HTTP_200_OK
+ assert len(response.data) == 1
+ assert response.data == [{'id': 1, 'text': 'foo'}]
def test_get_root_view_filters_out_all_models_with_exclusive_filter_backend(self):
"""
@@ -500,8 +500,8 @@ class TestFilterBackendAppliedToViews(TestCase):
root_view = RootView.as_view(filter_backends=(ExclusiveFilterBackend,))
request = factory.get('/')
response = root_view(request).render()
- self.assertEqual(response.status_code, status.HTTP_200_OK)
- self.assertEqual(response.data, [])
+ assert response.status_code == status.HTTP_200_OK
+ assert response.data == []
def test_get_instance_view_filters_out_name_with_filter_backend(self):
"""
@@ -510,8 +510,8 @@ class TestFilterBackendAppliedToViews(TestCase):
instance_view = InstanceView.as_view(filter_backends=(ExclusiveFilterBackend,))
request = factory.get('/1')
response = instance_view(request, pk=1).render()
- self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
- self.assertEqual(response.data, {'detail': 'Not found.'})
+ assert response.status_code == status.HTTP_404_NOT_FOUND
+ assert response.data == {'detail': 'Not found.'}
def test_get_instance_view_will_return_single_object_when_filter_does_not_exclude_it(self):
"""
@@ -520,8 +520,8 @@ class TestFilterBackendAppliedToViews(TestCase):
instance_view = InstanceView.as_view(filter_backends=(InclusiveFilterBackend,))
request = factory.get('/1')
response = instance_view(request, pk=1).render()
- self.assertEqual(response.status_code, status.HTTP_200_OK)
- self.assertEqual(response.data, {'id': 1, 'text': 'foo'})
+ assert response.status_code == status.HTTP_200_OK
+ assert response.data == {'id': 1, 'text': 'foo'}
def test_dynamic_serializer_form_in_browsable_api(self):
"""
@@ -530,8 +530,8 @@ class TestFilterBackendAppliedToViews(TestCase):
view = DynamicSerializerView.as_view()
request = factory.get('/')
response = view(request).render()
- self.assertContains(response, 'field_b')
- self.assertNotContains(response, 'field_a')
+ assert 'field_b' in response
+ assert 'field_a' not in response
class TestGuardedQueryset(TestCase):