Add methods to AuthedTestCase to test response content.

Add methods assert_equals_response and assert_in_response to
AuthedTestCase.  These methods make it convenient to check if
a string equals the contents of an HttpResponse's body or if a
string is a substring of the contents of an HttpResponse's body.
This commit is contained in:
Eklavya Sharma 2016-07-12 23:51:47 +05:30 committed by Tim Abbott
parent 2080ff6c2a
commit 161c27d0e9
1 changed files with 8 additions and 0 deletions

View File

@ -391,6 +391,14 @@ class AuthedTestCase(TestCase):
# type: (HttpResponse, text_type, int) -> None # type: (HttpResponse, text_type, int) -> None
self.assertIn(msg_substring, self.get_json_error(result, status_code=status_code)) self.assertIn(msg_substring, self.get_json_error(result, status_code=status_code))
def assert_equals_response(self, string, response):
# type: (text_type, HttpResponse) -> None
self.assertEqual(string, response.content.decode('utf-8'))
def assert_in_response(self, substring, response):
# type: (text_type, HttpResponse) -> None
self.assertIn(substring, response.content.decode('utf-8'))
def fixture_data(self, type, action, file_type='json'): def fixture_data(self, type, action, file_type='json'):
# type: (text_type, text_type, text_type) -> text_type # type: (text_type, text_type, text_type) -> text_type
return force_text(open(os.path.join(os.path.dirname(__file__), return force_text(open(os.path.join(os.path.dirname(__file__),