Skip to content

Commit 7fa8358

Browse files
author
Matthew Fisher
committed
fix(controller): update tests to check for 403
The unit tests were referencing the same variable over and over again (known as `url`). After concatenating to it, the following tests were running requests against odd URLs like /v1/apps/foo/config/builds, which would obviously return a 404. I've updated the unit tests to properly check for a 403 response.
1 parent a130937 commit 7fa8358

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

controller/api/tests/test_release.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,19 +254,25 @@ def test_unauthorized_user_cannot_modify_release(self):
254254
requests should return a 404.
255255
"""
256256
app_id = 'autotest'
257-
url = '/v1/apps'
257+
base_url = '/v1/apps'
258258
body = {'id': app_id}
259-
response = self.client.post(url, json.dumps(body), content_type='application/json',
259+
response = self.client.post(base_url, json.dumps(body), content_type='application/json',
260260
HTTP_AUTHORIZATION='token {}'.format(self.token))
261+
# push a new build
262+
url = '{base_url}/{app_id}/builds'.format(**locals())
263+
body = {'image': 'test'}
264+
response = self.client.post(
265+
url, json.dumps(body), content_type='application/json',
266+
HTTP_AUTHORIZATION='token {}'.format(self.token))
261267
# update config to roll a new release
262-
url = '/v1/apps/{app_id}/config'.format(**locals())
268+
url = '{base_url}/{app_id}/config'.format(**locals())
263269
body = {'values': json.dumps({'NEW_URL1': 'http://localhost:8080/'})}
264270
response = self.client.post(
265271
url, json.dumps(body), content_type='application/json',
266272
HTTP_AUTHORIZATION='token {}'.format(self.token))
267273
unauthorized_user = User.objects.get(username='autotest2')
268274
unauthorized_token = Token.objects.get(user=unauthorized_user).key
269275
# try to rollback
270-
url = '{}/{}/releases/rollback'.format(url, app_id)
276+
url = '{base_url}/{app_id}/releases/rollback/'.format(**locals())
271277
response = self.client.post(url, HTTP_AUTHORIZATION='token {}'.format(unauthorized_token))
272-
self.assertEqual(response.status_code, 404)
278+
self.assertEqual(response.status_code, 403)

0 commit comments

Comments
 (0)