示例#1
0
def test_SystemPaastaConfig_get_cluster():
    fake_config = utils.SystemPaastaConfig({
        'cluster': 'peanut',
    }, '/some/fake/dir')
    expected = 'peanut'
    actual = fake_config.get_cluster()
    assert actual == expected
示例#2
0
def test_load_system_paasta_config_merge_lexographically():
    fake_file_a = {'foo': 'this value will be overriden', 'fake': 'fake_data'}
    fake_file_b = {'foo': 'overriding value'}
    expected = utils.SystemPaastaConfig(
        {
            'foo': 'overriding value',
            'fake': 'fake_data'
        }, '/some/fake/dir')
    file_mock = mock.MagicMock(spec=file)
    with contextlib.nested(
            mock.patch('os.path.isdir', return_value=True),
            mock.patch('os.access', return_value=True),
            mock.patch('utils.open', create=True, return_value=file_mock),
            mock.patch('utils.get_readable_files_in_glob',
                       autospec=True,
                       return_value=['a', 'b']),
            mock.patch('utils.json.load',
                       autospec=True,
                       side_effect=[fake_file_a, fake_file_b])) as (
                           os_is_dir_patch,
                           os_access_patch,
                           open_file_patch,
                           mock_get_readable_files_in_glob,
                           json_patch,
                       ):
        actual = utils.load_system_paasta_config()
        assert actual == expected
示例#3
0
def test_load_system_paasta_config():
    json_load_return_value = {'foo': 'bar'}
    expected = utils.SystemPaastaConfig(json_load_return_value,
                                        '/some/fake/dir')
    file_mock = mock.MagicMock(spec=file)
    with contextlib.nested(
            mock.patch('os.path.isdir', return_value=True),
            mock.patch('os.access', return_value=True),
            mock.patch('utils.open', create=True, return_value=file_mock),
            mock.patch('utils.get_readable_files_in_glob',
                       autospec=True,
                       return_value=['/some/fake/dir/some_file.json']),
            mock.patch('utils.json.load',
                       autospec=True,
                       return_value=json_load_return_value)) as (
                           os_is_dir_patch,
                           os_access_patch,
                           open_file_patch,
                           mock_get_readable_files_in_glob,
                           json_patch,
                       ):
        actual = utils.load_system_paasta_config()
        assert actual == expected
        # Kinda weird but without this load_system_paasta_config() can (and
        # did! during development) return a plain dict without the test
        # complaining.
        assert actual.__class__ == expected.__class__
        open_file_patch.assert_any_call('/some/fake/dir/some_file.json')
        json_patch.assert_any_call(file_mock.__enter__())
        assert json_patch.call_count == 1
示例#4
0
def test_SystemPaastaConfig_get_volumes():
    fake_config = utils.SystemPaastaConfig(
        {
            'volumes': [{
                'fake_path': "fake_other_path"
            }],
        }, '/some/fake/dir')
    expected = [{'fake_path': "fake_other_path"}]
    actual = fake_config.get_volumes()
    assert actual == expected
示例#5
0
def test_SystemPaastaConfig_get_registry_dne():
    fake_config = utils.SystemPaastaConfig({}, '/some/fake/dir')
    with raises(utils.PaastaNotConfiguredError):
        fake_config.get_docker_registry()
示例#6
0
def test_SystemPaastaConfig_get_registry():
    fake_config = utils.SystemPaastaConfig(
        {'docker_registry': 'fake_registry'}, '/some/fake/dir')
    expected = 'fake_registry'
    actual = fake_config.get_docker_registry()
    assert actual == expected
示例#7
0
def test_SystemPaastaConfig_get_zk_dne():
    fake_config = utils.SystemPaastaConfig({}, '/some/fake/dir')
    with raises(utils.PaastaNotConfiguredError):
        fake_config.get_zk_hosts()
示例#8
0
def test_SystemPaastaConfig_get_zk():
    fake_config = utils.SystemPaastaConfig(
        {'zookeeper': 'zk://fake_zookeeper_host'}, '/some/fake/dir')
    expected = 'fake_zookeeper_host'
    actual = fake_config.get_zk_hosts()
    assert actual == expected