Skip to content

Commit 73f6dea

Browse files
author
Matthew Fisher
committed
test(controller): add unit tests for ps:restart
1 parent 366161d commit 73f6dea

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

controller/api/tests/test_container.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,3 +636,39 @@ def test_modified_procfile_from_build_removes_containers(self):
636636
HTTP_AUTHORIZATION='token {}'.format(self.token))
637637
self.assertEqual(response.status_code, 201)
638638
self.assertEqual(Container.objects.filter(type='web').count(), 0)
639+
640+
def test_restart_containers(self):
641+
url = '/v1/apps'
642+
response = self.client.post(url, HTTP_AUTHORIZATION='token {}'.format(self.token))
643+
self.assertEqual(response.status_code, 201)
644+
app_id = response.data['id']
645+
# post a new build
646+
build_url = "/v1/apps/{app_id}/builds".format(**locals())
647+
body = {'image': 'autotest/example', 'sha': 'a'*40,
648+
'procfile': json.dumps({'web': 'node server.js', 'worker': 'node worker.js'})}
649+
response = self.client.post(build_url, json.dumps(body), content_type='application/json',
650+
HTTP_AUTHORIZATION='token {}'.format(self.token))
651+
url = "/v1/apps/{app_id}/scale".format(**locals())
652+
body = {'web': 4, 'worker': 8}
653+
response = self.client.post(url, json.dumps(body), content_type='application/json',
654+
HTTP_AUTHORIZATION='token {}'.format(self.token))
655+
self.assertEqual(response.status_code, 204)
656+
container_set = App.objects.get(id=app_id).container_set.all()
657+
# restart all containers
658+
response = self.client.post('/v1/apps/{}/containers/restart'.format(app_id),
659+
content_type='application/json',
660+
HTTP_AUTHORIZATION='token {}'.format(self.token))
661+
self.assertEqual(response.status_code, 200)
662+
self.assertEqual(len(response.data), container_set.count())
663+
# restart only the workers
664+
response = self.client.post('/v1/apps/{}/containers/worker/restart'.format(app_id),
665+
content_type='application/json',
666+
HTTP_AUTHORIZATION='token {}'.format(self.token))
667+
self.assertEqual(response.status_code, 200)
668+
self.assertEqual(len(response.data), container_set.filter(type='worker').count())
669+
# restart only web.2
670+
response = self.client.post('/v1/apps/{}/containers/web/1/restart'.format(app_id),
671+
content_type='application/json',
672+
HTTP_AUTHORIZATION='token {}'.format(self.token))
673+
self.assertEqual(response.status_code, 200)
674+
self.assertEqual(len(response.data), container_set.filter(type='web', num=1).count())

0 commit comments

Comments
 (0)