def setup_config(port=PORT, **kwargs): from labtest.config import get_config filepath = kwargs.pop('filepath', '') cfg = get_config(filepath, host='127.0.0.1', app_name='testapp', code_repo_url='[email protected]:example/example.git', build_provider='default') instance._setup_env_with_config(cfg) if 'branch_name' in kwargs: instance._setup_default_env('testinstance', kwargs['branch_name']) else: if 'branch_name' in env: del env['branch_name'] instance._setup_default_env('testinstance') env.hosts = [ '{}@{}:{}'.format(USER, HOST, port), ] env.quiet = False env.host_string = env.hosts[0] env.key_filename = CLIENT_PRIVKEY env.abort_exception = FabricException env.test_domain = 'test.example.com' env.container_build_command = cfg.container_build_command env.update(kwargs) return cfg
def test_json_missing_labtest(): """ It should return an empty configuration """ c = config.get_config(os.path.join(FIXTURE_DIR, 'config_missing_labtest.json')) assert c.validate() is False
def test_single_environment_string(): """ Make sure an environment string without commas works """ c = config.get_config(os.path.join(FIXTURE_DIR, 'config.yml')) c.environment = 'NUMBER=1' assert len(c.environment) == 1 assert c.environment == ['NUMBER=1']
def test_get_state_none(): from .fabric_runner import run_fabric_command import random port = random.randint(1024, 49151) responses = { '/bin/bash -l -c "echo \\"Will you echo quotation marks\\""': 'Will you echo quotation marks', '/bin/bash -l -c "stat \\"\\$(echo /testing/state.json)\\""': ('', 'doesn\'t exist', 1), } env = {} files = {} expected = '' c = config.get_config(os.path.join(FIXTURE_DIR, 'config.yml'), host='[email protected]:{}'.format(port)) response = run_fabric_command(c.get_state, responses, expected, files, env, port=port) assert response is None
def test_overrides(): """ Test that passing overrides gets included in the config """ kw_overrides = { "app_name": "kwarg", "host": "kwarg", "use_ssh_config": False, "provider": "kwarg" } c = config.get_config(os.path.join(FIXTURE_DIR, 'config.yml'), **kw_overrides) assert c.app_name == kw_overrides['app_name'] assert c.host == kw_overrides['host'] assert c.use_ssh_config == kw_overrides['use_ssh_config'] assert c.provider == kw_overrides['provider']
def test_get_state_no_service(): from .fabric_runner import run_fabric_command import random port = random.randint(1024, 49151) responses = { '/bin/bash -l -c "echo \\"Will you echo quotation marks\\""': 'Will you echo quotation marks', '/bin/bash -l -c "stat \\"\\$(echo /testing/state.json)\\""': 'foo', } env = {} files = { '/testing/state.json': '{"provider": "local", "service": "foo", "options": {"command": "/testing/bin/get-state"}}', } expected = '' c = config.get_config(os.path.join(FIXTURE_DIR, 'config.yml'), host='[email protected]:{}'.format(port)) with pytest.raises(click.ClickException): run_fabric_command(c.get_state, responses, expected, files, env, port=port)
def test_get_state(): from .fabric_runner import run_fabric_command from labtest.provider.local.state import ScriptState import random port = random.randint(1024, 49151) responses = { '/bin/bash -l -c "echo \\"Will you echo quotation marks\\""': 'Will you echo quotation marks', '/bin/bash -l -c "stat \\"\\$(echo /testing/state.json)\\""': 'foo', } env = {} files = { '/testing/state.json': '{"provider": "local", "service": "script", "options": {"command": "/testing/bin/get-state"}}', } expected = '' c = config.get_config(os.path.join(FIXTURE_DIR, 'config.yml'), host='[email protected]:{}'.format(port)) response = run_fabric_command(c.get_state, responses, expected, files, env, port=port) assert isinstance(response, ScriptState)
def test_ini_config(): """ Make sure the INI processing is working """ c = config.get_config(os.path.join(FIXTURE_DIR, 'config.ini')) check_config_result(c)
def test_json_missing_config(): """ It should return an empty configuration """ with pytest.raises(IOError): c = config.get_config(os.path.join(FIXTURE_DIR, 'file_doesnt_exist.json')) # NOQA
def test_json_config(): """ Make sure the JSON processing is working """ c = config.get_config(os.path.join(FIXTURE_DIR, 'config.json')) check_config_result(c)
def test_yaml_config(): """ Make sure the YAML processing is working """ c = config.get_config(os.path.join(FIXTURE_DIR, 'config.yml')) check_config_result(c)
def test_backing_services(): c = config.get_config(os.path.join(FIXTURE_DIR, 'mysql-config.yml')) assert len(c.services) == 1
def test_use_ssh_config(): c = config.get_config(os.path.join(FIXTURE_DIR, 'config.yml')) c.use_ssh_config = True assert c.use_ssh_config is True c.use_ssh_config = 1.5 assert c.use_ssh_config is False