|
14 | 14 | from unittest import mock |
15 | 15 | from rest_framework.authtoken.models import Token |
16 | 16 |
|
17 | | -from api.models import Release |
| 17 | +from api.models import App, Release |
18 | 18 | from scheduler import KubeHTTPException |
19 | 19 | from . import adapter |
20 | 20 | from . import mock_port |
@@ -373,3 +373,42 @@ def test_release_no_change(self, mock_requests): |
373 | 373 | body = {'values': json.dumps({'NEW_URL1': 'http://localhost:8080/'})} |
374 | 374 | response = self.client.post(url, body) |
375 | 375 | self.assertEqual(response.status_code, 409, response.data) |
| 376 | + |
| 377 | + def test_release_get_port(self, mock_requests): |
| 378 | + """ |
| 379 | + Test that get_port always returns the proper value. |
| 380 | + """ |
| 381 | + url = '/v2/apps' |
| 382 | + response = self.client.post(url) |
| 383 | + self.assertEqual(response.status_code, 201, response.data) |
| 384 | + app_id = response.data['id'] |
| 385 | + app = App.objects.get(id=app_id) |
| 386 | + |
| 387 | + url = '/v2/apps/{app_id}/builds'.format(**locals()) |
| 388 | + body = {'sha': '123456', 'image': 'autotest/example'} |
| 389 | + response = self.client.post(url, body) |
| 390 | + self.assertEqual(response.status_code, 201, response.data) |
| 391 | + release = app.release_set.latest() |
| 392 | + |
| 393 | + # when app is not routable, returns None |
| 394 | + self.assertEqual(release.get_port(), None) |
| 395 | + |
| 396 | + # when a buildpack type, default to 5000 |
| 397 | + self.assertEqual(release.get_port(routable=True), 5000) |
| 398 | + |
| 399 | + # switch to a dockerfile app or else it'll automatically default to 5000 |
| 400 | + url = '/v2/apps/{app_id}/builds'.format(**locals()) |
| 401 | + body = {'image': 'autotest/example'} |
| 402 | + response = self.client.post(url, body) |
| 403 | + self.assertEqual(response.status_code, 201, response.data) |
| 404 | + |
| 405 | + url = '/v2/apps/{app_id}/config'.format(**locals()) |
| 406 | + body = {'values': json.dumps({'PORT': '8080'})} |
| 407 | + response = self.client.post(url, body) |
| 408 | + self.assertEqual(response.status_code, 201, response.data) |
| 409 | + release = app.release_set.latest() |
| 410 | + |
| 411 | + # check that the port number returned is an int, not a string |
| 412 | + self.assertEqual(release.get_port(routable=True), 8080) |
| 413 | + |
| 414 | + # TODO(bacongobbler): test dockerfile ports |
0 commit comments