2014-04-25 23:58:21 +02:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import absolute_import
|
2014-07-15 21:59:25 +02:00
|
|
|
import logging
|
|
|
|
import os
|
2014-04-25 23:58:21 +02:00
|
|
|
from .. import unittest
|
2014-07-15 21:59:25 +02:00
|
|
|
|
2014-07-30 07:42:58 +02:00
|
|
|
import mock
|
|
|
|
|
2014-07-15 21:59:25 +02:00
|
|
|
from fig.cli import main
|
2014-04-25 23:58:21 +02:00
|
|
|
from fig.cli.main import TopLevelCommand
|
2014-07-30 22:11:11 +02:00
|
|
|
from six import StringIO
|
2014-07-15 21:59:25 +02:00
|
|
|
|
2014-04-25 23:58:21 +02:00
|
|
|
|
|
|
|
class CLITestCase(unittest.TestCase):
|
2014-07-14 20:32:10 +02:00
|
|
|
def test_default_project_name(self):
|
|
|
|
cwd = os.getcwd()
|
|
|
|
|
|
|
|
try:
|
|
|
|
os.chdir('tests/fixtures/simple-figfile')
|
|
|
|
command = TopLevelCommand()
|
2014-07-30 07:42:58 +02:00
|
|
|
project_name = command.get_project_name(command.get_config_path())
|
|
|
|
self.assertEquals('simplefigfile', project_name)
|
2014-07-14 20:32:10 +02:00
|
|
|
finally:
|
|
|
|
os.chdir(cwd)
|
|
|
|
|
|
|
|
def test_project_name_with_explicit_base_dir(self):
|
2014-07-13 08:35:37 +02:00
|
|
|
command = TopLevelCommand()
|
|
|
|
command.base_dir = 'tests/fixtures/simple-figfile'
|
2014-07-30 07:42:58 +02:00
|
|
|
project_name = command.get_project_name(command.get_config_path())
|
|
|
|
self.assertEquals('simplefigfile', project_name)
|
2014-07-13 08:35:37 +02:00
|
|
|
|
2014-10-21 13:32:54 +02:00
|
|
|
def test_project_name_with_explicit_uppercase_base_dir(self):
|
|
|
|
command = TopLevelCommand()
|
|
|
|
command.base_dir = 'tests/fixtures/Simple-figfile'
|
|
|
|
project_name = command.get_project_name(command.get_config_path())
|
|
|
|
self.assertEquals('simplefigfile', project_name)
|
|
|
|
|
2014-07-14 20:32:10 +02:00
|
|
|
def test_project_name_with_explicit_project_name(self):
|
|
|
|
command = TopLevelCommand()
|
2014-07-30 07:42:58 +02:00
|
|
|
name = 'explicit-project-name'
|
|
|
|
project_name = command.get_project_name(None, project_name=name)
|
|
|
|
self.assertEquals('explicitprojectname', project_name)
|
2014-07-14 20:32:10 +02:00
|
|
|
|
2014-09-23 18:28:08 +02:00
|
|
|
def test_project_name_from_environment(self):
|
|
|
|
command = TopLevelCommand()
|
|
|
|
name = 'namefromenv'
|
|
|
|
with mock.patch.dict(os.environ):
|
|
|
|
os.environ['FIG_PROJECT_NAME'] = name
|
|
|
|
project_name = command.get_project_name(None)
|
|
|
|
self.assertEquals(project_name, name)
|
|
|
|
|
2014-04-25 23:58:21 +02:00
|
|
|
def test_yaml_filename_check(self):
|
|
|
|
command = TopLevelCommand()
|
|
|
|
command.base_dir = 'tests/fixtures/longer-filename-figfile'
|
2014-07-30 07:42:58 +02:00
|
|
|
with mock.patch('fig.cli.command.log', autospec=True) as mock_log:
|
|
|
|
self.assertTrue(command.get_config_path())
|
|
|
|
self.assertEqual(mock_log.warning.call_count, 2)
|
|
|
|
|
|
|
|
def test_get_project(self):
|
|
|
|
command = TopLevelCommand()
|
|
|
|
command.base_dir = 'tests/fixtures/longer-filename-figfile'
|
|
|
|
project = command.get_project(command.get_config_path())
|
|
|
|
self.assertEqual(project.name, 'longerfilenamefigfile')
|
|
|
|
self.assertTrue(project.client)
|
|
|
|
self.assertTrue(project.services)
|
2014-04-25 23:58:21 +02:00
|
|
|
|
|
|
|
def test_help(self):
|
|
|
|
command = TopLevelCommand()
|
|
|
|
with self.assertRaises(SystemExit):
|
|
|
|
command.dispatch(['-h'], None)
|
2014-07-15 21:59:25 +02:00
|
|
|
|
|
|
|
def test_setup_logging(self):
|
|
|
|
main.setup_logging()
|
|
|
|
self.assertEqual(logging.getLogger().level, logging.DEBUG)
|
|
|
|
self.assertEqual(logging.getLogger('requests').propagate, False)
|