Extract test setup

This commit is contained in:
Aanand Prasad 2013-12-09 15:00:01 +00:00
parent bc51134ceb
commit 630f6fcf02
1 changed files with 23 additions and 15 deletions

View File

@ -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)