From 7459f44f6bf102c7e39fd9f2623388136e033ae4 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Mon, 19 Jan 2015 04:57:48 -0400 Subject: [PATCH] Check for test client response content the right way --- mayan/apps/documents/tests.py | 17 ++++++----------- mayan/apps/dynamic_search/tests.py | 4 ++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/mayan/apps/documents/tests.py b/mayan/apps/documents/tests.py index 1c270fc033..ba6c20564a 100644 --- a/mayan/apps/documents/tests.py +++ b/mayan/apps/documents/tests.py @@ -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) diff --git a/mayan/apps/dynamic_search/tests.py b/mayan/apps/dynamic_search/tests.py index 9cebe6f292..b6a37f0d3c 100644 --- a/mayan/apps/dynamic_search/tests.py +++ b/mayan/apps/dynamic_search/tests.py @@ -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)