|
11 | 11 | from django.test import TestCase |
12 | 12 | from django.test.utils import override_settings |
13 | 13 |
|
| 14 | +from api.models import Container |
14 | 15 | from deis import settings |
15 | 16 |
|
16 | 17 |
|
@@ -455,3 +456,27 @@ def test_container_balance(self): |
455 | 456 | b_min = min([len(by_backend[b]) for b in by_backend.keys()]) |
456 | 457 | b_max = max([len(by_backend[b]) for b in by_backend.keys()]) |
457 | 458 | self.assertLess(b_max - b_min, 2) |
| 459 | + |
| 460 | + def test_container_str(self): |
| 461 | + """Test the text representation of a container.""" |
| 462 | + url = '/api/apps' |
| 463 | + body = {'formation': 'autotest'} |
| 464 | + response = self.client.post(url, json.dumps(body), content_type='application/json') |
| 465 | + self.assertEqual(response.status_code, 201) |
| 466 | + app_id = response.data['id'] |
| 467 | + # scale up |
| 468 | + url = "/api/apps/{app_id}/scale".format(**locals()) |
| 469 | + body = {'web': 4, 'worker': 2} |
| 470 | + response = self.client.post(url, json.dumps(body), content_type='application/json') |
| 471 | + self.assertEqual(response.status_code, 200) |
| 472 | + # should start with zero |
| 473 | + url = "/api/apps/{app_id}/containers".format(**locals()) |
| 474 | + response = self.client.get(url) |
| 475 | + self.assertEqual(response.status_code, 200) |
| 476 | + self.assertEqual(len(response.data['results']), 6) |
| 477 | + uuid = response.data['results'][0]['uuid'] |
| 478 | + container = Container.objects.get(uuid=uuid) |
| 479 | + self.assertEqual(container.short_name(), |
| 480 | + "{}.{}".format(container.type, container.num)) |
| 481 | + self.assertEqual(str(container), |
| 482 | + "{} {}".format(container.formation.id, container.short_name())) |
0 commit comments