environment_test.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from __future__ import absolute_import
  2. from __future__ import unicode_literals
  3. import tempfile
  4. from ddt import data
  5. from ddt import ddt
  6. from .. import mock
  7. from compose.cli.command import project_from_options
  8. from tests.integration.testcases import DockerClientTestCase
  9. @ddt
  10. class EnvironmentTest(DockerClientTestCase):
  11. @classmethod
  12. def setUpClass(cls):
  13. super(EnvironmentTest, cls).setUpClass()
  14. cls.compose_file = tempfile.NamedTemporaryFile(mode='w+b')
  15. cls.compose_file.write(bytes("""version: '3.2'
  16. services:
  17. svc:
  18. image: busybox:latest
  19. environment:
  20. TEST_VARIABLE: ${TEST_VARIABLE}""", encoding='utf-8'))
  21. cls.compose_file.flush()
  22. @classmethod
  23. def tearDownClass(cls):
  24. super(EnvironmentTest, cls).tearDownClass()
  25. cls.compose_file.close()
  26. @data('events',
  27. 'exec',
  28. 'kill',
  29. 'logs',
  30. 'pause',
  31. 'ps',
  32. 'restart',
  33. 'rm',
  34. 'start',
  35. 'stop',
  36. 'top',
  37. 'unpause')
  38. def _test_no_warning_on_missing_host_environment_var_on_silent_commands(self, cmd):
  39. options = {'COMMAND': cmd, '--file': [EnvironmentTest.compose_file.name]}
  40. with mock.patch('compose.config.environment.log') as fake_log:
  41. # Note that the warning silencing and the env variables check is
  42. # done in `project_from_options`
  43. # So no need to have a proper options map, the `COMMAND` key is enough
  44. project_from_options('.', options)
  45. assert fake_log.warn.call_count == 0