testcases.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from __future__ import unicode_literals
  2. from __future__ import absolute_import
  3. from fig.service import Service
  4. from fig.cli.docker_client import docker_client
  5. from fig.progress_stream import stream_output
  6. from .. import unittest
  7. class DockerClientTestCase(unittest.TestCase):
  8. @classmethod
  9. def setUpClass(cls):
  10. cls.client = docker_client()
  11. def setUp(self):
  12. for c in self.client.containers(all=True):
  13. if c['Names'] and 'figtest' in c['Names'][0]:
  14. self.client.kill(c['Id'])
  15. self.client.remove_container(c['Id'])
  16. for i in self.client.images():
  17. if isinstance(i.get('Tag'), basestring) and 'figtest' in i['Tag']:
  18. self.client.remove_image(i)
  19. def create_service(self, name, **kwargs):
  20. if 'command' not in kwargs:
  21. kwargs['command'] = ["/bin/sleep", "300"]
  22. return Service(
  23. project='figtest',
  24. name=name,
  25. client=self.client,
  26. image="busybox:latest",
  27. **kwargs
  28. )
  29. def check_build(self, *args, **kwargs):
  30. build_output = self.client.build(*args, **kwargs)
  31. stream_output(build_output, open('/dev/null', 'w'))