Check for test client response content the right way

This commit is contained in:
Roberto Rosario
2015-01-19 04:57:48 -04:00
parent 4f3d3cf25c
commit 7459f44f6b
2 changed files with 8 additions and 13 deletions

View File

@@ -176,19 +176,16 @@ class DocumentsViewsFunctionalTestCase(TestCase):
def test_document_view(self):
response = self.client.get(reverse('documents:document_list'))
self.assertEqual(response.status_code, 200)
self.assertTrue('ocuments (1)' in response.content)
self.assertContains(response, 'ocuments (1)', status_code=200)
# test document simple view
response = self.client.get(reverse('documents:document_properties', args=[self.document.pk]))
self.assertEqual(response.status_code, 200)
self.assertTrue('ocument properties' in response.content)
self.assertContains(response, 'ocument properties', status_code=200)
def test_document_type_views(self):
# Check that there are no document types
response = self.client.get(reverse('documents:document_type_list'))
self.assertEqual(response.status_code, 200)
self.assertTrue('ocument types (1)' in response.content)
self.assertContains(response, 'ocument types (1)', status_code=200)
# Create a document type
response = self.client.post(reverse('documents:document_type_create'), data={'name': TEST_DOCUMENT_TYPE}, follow=True)
@@ -206,18 +203,16 @@ class DocumentsViewsFunctionalTestCase(TestCase):
# Edit the document type
response = self.client.post(reverse('documents:document_type_edit', args=[document_type.pk]), data={'name': TEST_DOCUMENT_TYPE + 'partial'}, follow=True)
self.assertEqual(response.status_code, 200)
self.assertTrue('Document type edited successfully' in response.content)
self.assertContains(response, 'Document type edited successfully', status_code=200)
document_type = DocumentType.objects.first()
self.assertEqual(document_type.name, TEST_DOCUMENT_TYPE + 'partial')
# Delete the document type
response = self.client.post(reverse('documents:document_type_delete', args=[document_type.pk]), follow=True)
self.assertEqual(response.status_code, 200)
self.assertTrue('Document type: {0} deleted successfully'.format(document_type.name) in response.content)
self.assertContains(response, 'Document type: {0} deleted successfully'.format(document_type.name), status_code=200)
# Check that there are no document types
response = self.client.get(reverse('documents:document_type_list'))
self.assertEqual(response.status_code, 200)
self.assertTrue('ocument types (0)' in response.content)
self.assertContains(response, 'ocument types (0)', status_code=200)

View File

@@ -100,8 +100,8 @@ class Issue46TestCase(TestCase):
# Funcitonal test for the first page of advanced results
response = self.client.get(reverse('search:results'), {'label': 'test'})
self.assertTrue('esults (1 - 20 out of 30) (Page 1 of 2)' in response.content)
self.assertContains(response, 'esults (1 - 20 out of 30) (Page 1 of 2)', status_code=200)
# Functional test for the second page of advanced results
response = self.client.get(reverse('search:results'), {'label': 'test', 'page': 2})
self.assertTrue('esults (21 - 30 out of 30) (Page 2 of 2)' in response.content)
self.assertContains(response, 'esults (21 - 30 out of 30) (Page 2 of 2)', status_code=200)