service_collection_test.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from plum.service import Service
  2. from plum.service_collection import ServiceCollection
  3. from .testcases import DockerClientTestCase
  4. class ServiceCollectionTest(DockerClientTestCase):
  5. def test_from_dict(self):
  6. collection = ServiceCollection.from_dicts(None, [
  7. {
  8. 'name': 'web',
  9. 'image': 'ubuntu'
  10. },
  11. {
  12. 'name': 'db',
  13. 'image': 'ubuntu'
  14. }
  15. ])
  16. self.assertEqual(len(collection), 2)
  17. self.assertEqual(collection.get('web').name, 'web')
  18. self.assertEqual(collection.get('web').options['image'], 'ubuntu')
  19. self.assertEqual(collection.get('db').name, 'db')
  20. self.assertEqual(collection.get('db').options['image'], 'ubuntu')
  21. def test_from_dict_sorts_in_dependency_order(self):
  22. collection = ServiceCollection.from_dicts(None, [
  23. {
  24. 'name': 'web',
  25. 'image': 'ubuntu',
  26. 'links': ['db'],
  27. },
  28. {
  29. 'name': 'db',
  30. 'image': 'ubuntu'
  31. }
  32. ])
  33. self.assertEqual(collection[0].name, 'db')
  34. self.assertEqual(collection[1].name, 'web')
  35. def test_get(self):
  36. web = self.create_service('web')
  37. collection = ServiceCollection([web])
  38. self.assertEqual(collection.get('web'), web)
  39. def test_start_stop(self):
  40. collection = ServiceCollection([
  41. self.create_service('web'),
  42. self.create_service('db'),
  43. ])
  44. collection.start()
  45. self.assertEqual(len(collection[0].containers), 1)
  46. self.assertEqual(len(collection[1].containers), 1)
  47. collection.stop()
  48. self.assertEqual(len(collection[0].containers), 0)
  49. self.assertEqual(len(collection[1].containers), 0)