cli_test.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from __future__ import unicode_literals
  2. from __future__ import absolute_import
  3. import logging
  4. import os
  5. from .. import unittest
  6. import mock
  7. from fig.cli import main
  8. from fig.cli.main import TopLevelCommand
  9. from fig.packages.six import StringIO
  10. class CLITestCase(unittest.TestCase):
  11. def test_default_project_name(self):
  12. cwd = os.getcwd()
  13. try:
  14. os.chdir('tests/fixtures/simple-figfile')
  15. command = TopLevelCommand()
  16. project_name = command.get_project_name(command.get_config_path())
  17. self.assertEquals('simplefigfile', project_name)
  18. finally:
  19. os.chdir(cwd)
  20. def test_project_name_with_explicit_base_dir(self):
  21. command = TopLevelCommand()
  22. command.base_dir = 'tests/fixtures/simple-figfile'
  23. project_name = command.get_project_name(command.get_config_path())
  24. self.assertEquals('simplefigfile', project_name)
  25. def test_project_name_with_explicit_project_name(self):
  26. command = TopLevelCommand()
  27. name = 'explicit-project-name'
  28. project_name = command.get_project_name(None, project_name=name)
  29. self.assertEquals('explicitprojectname', project_name)
  30. def test_yaml_filename_check(self):
  31. command = TopLevelCommand()
  32. command.base_dir = 'tests/fixtures/longer-filename-figfile'
  33. with mock.patch('fig.cli.command.log', autospec=True) as mock_log:
  34. self.assertTrue(command.get_config_path())
  35. self.assertEqual(mock_log.warning.call_count, 2)
  36. def test_get_project(self):
  37. command = TopLevelCommand()
  38. command.base_dir = 'tests/fixtures/longer-filename-figfile'
  39. project = command.get_project(command.get_config_path())
  40. self.assertEqual(project.name, 'longerfilenamefigfile')
  41. self.assertTrue(project.client)
  42. self.assertTrue(project.services)
  43. def test_help(self):
  44. command = TopLevelCommand()
  45. with self.assertRaises(SystemExit):
  46. command.dispatch(['-h'], None)
  47. def test_setup_logging(self):
  48. main.setup_logging()
  49. self.assertEqual(logging.getLogger().level, logging.DEBUG)
  50. self.assertEqual(logging.getLogger('requests').propagate, False)