command_test.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from __future__ import absolute_import
  2. from __future__ import unicode_literals
  3. import os
  4. import ssl
  5. import pytest
  6. from compose.cli.command import get_config_path_from_options
  7. from compose.cli.command import get_tls_version
  8. from compose.config.environment import Environment
  9. from compose.const import IS_WINDOWS_PLATFORM
  10. from tests import mock
  11. class TestGetConfigPathFromOptions(object):
  12. def test_path_from_options(self):
  13. paths = ['one.yml', 'two.yml']
  14. opts = {'--file': paths}
  15. environment = Environment.from_env_file('.')
  16. assert get_config_path_from_options('.', opts, environment) == paths
  17. def test_single_path_from_env(self):
  18. with mock.patch.dict(os.environ):
  19. os.environ['COMPOSE_FILE'] = 'one.yml'
  20. environment = Environment.from_env_file('.')
  21. assert get_config_path_from_options('.', {}, environment) == ['one.yml']
  22. @pytest.mark.skipif(IS_WINDOWS_PLATFORM, reason='posix separator')
  23. def test_multiple_path_from_env(self):
  24. with mock.patch.dict(os.environ):
  25. os.environ['COMPOSE_FILE'] = 'one.yml:two.yml'
  26. environment = Environment.from_env_file('.')
  27. assert get_config_path_from_options(
  28. '.', {}, environment
  29. ) == ['one.yml', 'two.yml']
  30. @pytest.mark.skipif(not IS_WINDOWS_PLATFORM, reason='windows separator')
  31. def test_multiple_path_from_env_windows(self):
  32. with mock.patch.dict(os.environ):
  33. os.environ['COMPOSE_FILE'] = 'one.yml;two.yml'
  34. environment = Environment.from_env_file('.')
  35. assert get_config_path_from_options(
  36. '.', {}, environment
  37. ) == ['one.yml', 'two.yml']
  38. def test_no_path(self):
  39. environment = Environment.from_env_file('.')
  40. assert not get_config_path_from_options('.', {}, environment)
  41. class TestGetTlsVersion(object):
  42. def test_get_tls_version_default(self):
  43. environment = {}
  44. assert get_tls_version(environment) is None
  45. def test_get_tls_version_upgrade(self):
  46. environment = {'COMPOSE_TLS_VERSION': 'TLSv1_2'}
  47. assert get_tls_version(environment) == ssl.PROTOCOL_TLSv1_2
  48. def test_get_tls_version_unavailable(self):
  49. environment = {'COMPOSE_TLS_VERSION': 'TLSv5_5'}
  50. with mock.patch('compose.cli.command.log') as mock_log:
  51. tls_version = get_tls_version(environment)
  52. mock_log.warn.assert_called_once_with(mock.ANY)
  53. assert tls_version is None