def test_config_get_simple(config): good_config = '{foo: {filename: x}}' mock_config = mock.mock_open(read_data=good_config) with mock.patch.object(config, "open", mock_config): with mock.patch.object(config.os.path, "isfile", return_value=True): c = config.ImageConfig("mock_config_name") assert c.get('foo') == {'filename': 'x'}
def test_config_get_default(config, path): good_config = '{foo: {filename: x, glance: {properties:{foo: bar}}}}' mock_config = mock.mock_open(read_data=good_config) with mock.patch.object(config, "open", mock_config): with mock.patch.object(config.os.path, "isfile", return_value=True): c = config.ImageConfig("mock_config_name") assert c.get(path, sentinel.notfound) == sentinel.notfound
def test_config_getitem_error(config, path): good_config = '{foo: {filename: x, glance: {properties:{foo: bar}}}}' mock_config = mock.mock_open(read_data=good_config) with mock.patch.object(config, "open", mock_config): with mock.patch.object(config.os.path, "isfile", return_value=True): c = config.ImageConfig("mock_config_name") with pytest.raises(config.NotFoundInConfigError): c[path]
def test_config_getitem_dotted(config, path, value): good_config = '{foo: {filename: x, glance: {properties:{foo: bar}}}, '\ 'baz: {filename: y}}' mock_config = mock.mock_open(read_data=good_config) with mock.patch.object(config, "open", mock_config): with mock.patch.object(config.os.path, "isfile", return_value=True): c = config.ImageConfig("mock_config_name") assert c[path] == value
def test_imageconfig_filename(config): mock_config = mock.mock_open( read_data='{"image1":{"filename": "bad"}, "image2":{"filename":"bad"}}' ) with mock.patch.object(config, "open", mock_config): with mock.patch.object(config.os.path, "isfile", return_value=True): conf = config.ImageConfig(override_filename='new') assert conf.get('image1') == {'filename': 'new'} assert conf.get('image2') == {'filename': 'new'}
def test_integration_imageconfig_schema_from_docs_example(config): config.ImageConfig(images_yaml)
def test_imageconfig_schema_good(config, good_config): mock_config = mock.mock_open(read_data=good_config) with mock.patch.object(config, "open", mock_config): with mock.patch.object(config.os.path, "isfile", return_value=True): config.ImageConfig("mock_config_name")
def test_imageconfig_schema_bad(config, bad_config): mock_config = mock.mock_open(read_data=bad_config) with mock.patch.object(config, "open", mock_config): with mock.patch.object(config.os.path, "isfile", return_value=True): with pytest.raises(config.InvaidConfigError): config.ImageConfig("mock_config_name")
def test_imageconfig_with_defaults(config): mock_config = mock.mock_open(read_data='{"image1":{"filename": "ok"}}') with mock.patch.object(config, "open", mock_config): with mock.patch.object(config.os.path, "isfile", return_value=True): conf = config.ImageConfig() assert conf.get('image1') == {'filename': 'ok'}
def test_imageconfig(config): mock_config = mock.mock_open(read_data='{"image1": {"filename": "ok"}}') with mock.patch.object(config, "open", mock_config) as mock_open: with mock.patch.object(config.os.path, "isfile", return_value=True): config.ImageConfig() assert mock_open.call_args[0][0] == './images.yaml'
def test_set_conf_name_not_found_natural(config): with mock.patch.object(config.os.path, "isfile", return_value=False): with pytest.raises(config.ConfigNotFound): config.ImageConfig()