Browsable API tests asserts to pytest (#4725)

This commit is contained in:
Asif Saifuddin Auvi 2016-12-01 22:17:36 +06:00 committed by Tom Christie
parent 16f5d42cbc
commit 932d04a4be
3 changed files with 18 additions and 12 deletions

View File

@ -26,16 +26,19 @@ class DropdownWithAuthTests(TestCase):
def test_name_shown_when_logged_in(self):
self.client.login(username=self.username, password=self.password)
response = self.client.get('/')
self.assertContains(response, 'john')
content = response.content.decode('utf8')
assert 'john' in content
def test_logout_shown_when_logged_in(self):
self.client.login(username=self.username, password=self.password)
response = self.client.get('/')
self.assertContains(response, '>Log out<')
content = response.content.decode('utf8')
assert '>Log out<' in content
def test_login_shown_when_logged_out(self):
response = self.client.get('/')
self.assertContains(response, '>Log in<')
content = response.content.decode('utf8')
assert '>Log in<' in content
@override_settings(ROOT_URLCONF='tests.browsable_api.no_auth_urls')
@ -58,13 +61,16 @@ class NoDropdownWithoutAuthTests(TestCase):
def test_name_shown_when_logged_in(self):
self.client.login(username=self.username, password=self.password)
response = self.client.get('/')
self.assertContains(response, 'john')
content = response.content.decode('utf8')
assert 'john' in content
def test_dropdown_not_shown_when_logged_in(self):
self.client.login(username=self.username, password=self.password)
response = self.client.get('/')
self.assertNotContains(response, '<li class="dropdown">')
content = response.content.decode('utf8')
assert '<li class="dropdown">' not in content
def test_dropdown_not_shown_when_logged_out(self):
response = self.client.get('/')
self.assertNotContains(response, '<li class="dropdown">')
content = response.content.decode('utf8')
assert '<li class="dropdown">' not in content

View File

@ -35,8 +35,8 @@ class DropdownWithAuthTests(TestCase):
@override_settings(ROOT_URLCONF='tests.browsable_api.test_browsable_nested_api')
def test_login(self):
response = self.client.get('/api/')
self.assertEqual(200, response.status_code)
assert 200 == response.status_code
content = response.content.decode('utf-8')
self.assertIn('form action="/api/"', content)
self.assertIn('input name="nested.one"', content)
self.assertIn('input name="nested.two"', content)
assert 'form action="/api/"' in content
assert 'input name="nested.one"' in content
assert 'input name="nested.two"' in content

View File

@ -50,5 +50,5 @@ class TestManyPostView(TestCase):
request = factory.post('/', data, format='json')
with self.assertNumQueries(1):
response = self.view(request).render()
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data), 3)
assert response.status_code == status.HTTP_200_OK
assert len(response.data) == 3