compose/tests/service_collection_test.py

63 lines
1.8 KiB
Python
Raw Normal View History

2013-12-09 15:10:23 +01:00
from plum.service import Service
from plum.service_collection import ServiceCollection
2013-12-10 21:47:08 +01:00
from .testcases import DockerClientTestCase
2013-12-09 15:10:23 +01:00
2013-12-10 21:47:08 +01:00
class ServiceCollectionTest(DockerClientTestCase):
2013-12-09 15:10:23 +01:00
def test_from_dict(self):
collection = ServiceCollection.from_dicts(None, [
{
'name': 'web',
'image': 'ubuntu'
},
{
'name': 'db',
'image': 'ubuntu'
}
])
self.assertEqual(len(collection), 2)
2013-12-09 19:43:10 +01:00
self.assertEqual(collection.get('web').name, 'web')
2013-12-10 21:51:55 +01:00
self.assertEqual(collection.get('web').options['image'], 'ubuntu')
2013-12-09 19:43:10 +01:00
self.assertEqual(collection.get('db').name, 'db')
2013-12-10 21:51:55 +01:00
self.assertEqual(collection.get('db').options['image'], 'ubuntu')
2013-12-09 15:10:23 +01:00
def test_from_dict_sorts_in_dependency_order(self):
collection = ServiceCollection.from_dicts(None, [
{
'name': 'web',
'image': 'ubuntu',
'links': ['db'],
},
{
'name': 'db',
'image': 'ubuntu'
}
])
2013-12-09 19:43:10 +01:00
2013-12-09 15:10:23 +01:00
self.assertEqual(collection[0].name, 'db')
self.assertEqual(collection[1].name, 'web')
2013-12-09 19:43:10 +01:00
def test_get(self):
web = self.create_service('web')
collection = ServiceCollection([web])
self.assertEqual(collection.get('web'), web)
def test_start_stop(self):
collection = ServiceCollection([
self.create_service('web'),
self.create_service('db'),
])
collection.start()
self.assertEqual(len(collection[0].containers), 1)
self.assertEqual(len(collection[1].containers), 1)
collection.stop()
self.assertEqual(len(collection[0].containers), 0)
self.assertEqual(len(collection[1].containers), 0)
2013-12-09 22:39:11 +01:00