Skip to content

Commit 9e37c8a

Browse files
author
Matthew Fisher
committed
ref(tests): use assertContains() instead of assertEquals
In Python 3, Django's HTTPResponse.content contains bytes, which becomes an issue if comparing against a string in tests. The preferred solution is to rely on assertContains() and assertNotContains(). See https://docs.djangoproject.com/es/1.9/topics/python3/#httprequest-and-httpresponse-objects
1 parent 825e46a commit 9e37c8a

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

rootfs/api/tests/test_app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,20 @@ def test_app_actions(self, mock_requests, mock_get):
109109
mock_response.status_code = 400
110110
response = self.client.get(url)
111111
self.assertEqual(response.status_code, 500)
112-
self.assertEqual(response.content, "Error accessing logs for {}".format(app_id))
112+
self.assertContains(response, "Error accessing logs for {}".format(app_id))
113113

114114
# test logs - success accessing deis-logger
115115
mock_response.status_code = 200
116116
mock_response.content = FAKE_LOG_DATA
117117
response = self.client.get(url)
118118
self.assertEqual(response.status_code, 200)
119-
self.assertEqual(response.content, FAKE_LOG_DATA)
119+
self.assertContains(response, FAKE_LOG_DATA)
120120

121121
# test logs - HTTP request error while accessing deis-logger
122122
mock_get.side_effect = requests.exceptions.RequestException('Boom!')
123123
response = self.client.get(url)
124124
self.assertEqual(response.status_code, 500)
125-
self.assertEqual(response.content, "Error accessing logs for {}".format(app_id))
125+
self.assertContains(response, "Error accessing logs for {}".format(app_id))
126126

127127
# TODO: test run needs an initial build
128128

0 commit comments

Comments
 (0)