From 630f6fcf02f51a3c257c69c65127597c343500cf Mon Sep 17 00:00:00 2001 From: Aanand Prasad Date: Mon, 9 Dec 2013 15:00:01 +0000 Subject: [PATCH] Extract test setup --- plum/tests/service_test.py | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/plum/tests/service_test.py b/plum/tests/service_test.py index eac2d498c..5870c30da 100644 --- a/plum/tests/service_test.py +++ b/plum/tests/service_test.py @@ -3,7 +3,26 @@ from docker import Client from plum import Service -class NameTestCase(TestCase): +client = Client('http://127.0.0.1:4243') +client.pull('ubuntu') + + +class ServiceTestCase(TestCase): + def setUp(self): + for c in client.containers(all=True): + client.kill(c['Id']) + client.remove_container(c['Id']) + + def create_service(self, name): + return Service( + name=name, + client=client, + image="ubuntu", + command=["/bin/sleep", "300"], + ) + + +class NameTestCase(ServiceTestCase): def test_name_validations(self): self.assertRaises(ValueError, lambda: Service(name='')) @@ -20,21 +39,10 @@ class NameTestCase(TestCase): Service('_____') -class ScalingTestCase(TestCase): +class ScalingTestCase(ServiceTestCase): def setUp(self): - self.client = Client('http://127.0.0.1:4243') - self.client.pull('ubuntu') - - for c in self.client.containers(all=True): - self.client.kill(c['Id']) - self.client.remove_container(c['Id']) - - self.service = Service( - name="test", - client=self.client, - image="ubuntu", - command=["/bin/sleep", "300"], - ) + super(ServiceTestCase, self).setUp() + self.service = self.create_service("scaling_test") def test_up_scale_down(self): self.assertEqual(len(self.service.containers), 0)