Exemple #1
0
def test_set_not_string():

    dictionary = {'key1': 'value1'}

    patcher = Patcher(dictionary)
    with pytest.raises(exceptions.InvalidValueTypeException):
        patcher.set('key1', 5).finish()
Exemple #2
0
def test_set_not_string():

    dictionary = {'key1': 'value1'}

    patcher = Patcher(dictionary)
    with pytest.raises(exceptions.InvalidValueTypeException):
        patcher.set('key1', 5).finish()
Exemple #3
0
def test_add_to_non_list():

    dictionary = {'key': 'value1'}

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.InvalidKeyTypeException):
        patcher.add(key='key', value='value2')
Exemple #4
0
def test_delete_non_existing_key():

    dictionary = {'key': 'value'}

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.KeyNotFoundException):
        patcher.delete('non-existing')
Exemple #5
0
def test_add_to_non_list():

    dictionary = {'key': 'value1'}

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.InvalidKeyTypeException):
        patcher.add(key='key', value='value2')
Exemple #6
0
def test_get_compund_object_unsupported_format():

    dictionary = {'key1': ['value1', 'value2']}

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.UnsupportedFormatException):
        patcher.get('key1', fmt='unsupported')
Exemple #7
0
def test_get_non_existing_two_level_complex_key():

    dictionary = {'key1': {'key2': {'key3': 'value1'}}}

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.KeyNotFoundException):
        patcher.get('key1:key2:key4')
Exemple #8
0
def test_delete_non_existing_key():

    dictionary = {'key': 'value'}

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.KeyNotFoundException):
        patcher.delete('non-existing')
Exemple #9
0
def test_set_existing_two_level_complex_key():

    dictionary = {'key1': {'key2': {'key3': 'value1'}}}

    expected_dictionary = {'key1': {'key2': {'key3': 'value2'}}}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1:key2:key3', 'value2').finish()

    assert expected_dictionary == dictionary
Exemple #10
0
def test_add_to_complex_key():

    dictionary = {'key1': {'key2': ['value1']}}

    expected_dictionary = {'key1': {'key2': ['value1', 'value2']}}

    patcher = Patcher(dictionary)
    patcher.add(key='key1:key2', value='value2')

    assert expected_dictionary == dictionary
Exemple #11
0
def test_get_compund_object_unsupported_format():

    dictionary = {
        'key1': ['value1', 'value2']
    }

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.UnsupportedFormatException):
        patcher.get('key1', fmt='unsupported')
Exemple #12
0
def test_delete_complex_key():

    dictionary = {'key1': {'key2': 'value1', 'key3': 'value2'}}

    expected_dictionary = {'key1': {'key2': 'value1'}}

    patcher = Patcher(dictionary)
    dictionary = patcher.delete('key1:key3').finish()

    assert expected_dictionary == dictionary
Exemple #13
0
def test_set_complex_key_compound_value():

    dictionary = {'key1': {'key2': 'value1'}}

    expected_dictionary = {'key1': {'key2': {'key3': 'value2'}}}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1:key2', '{"key3":"value2"}').finish()

    assert expected_dictionary == dictionary
Exemple #14
0
def test_get_dict_as_yaml():

    dictionary = {'key1': {'key2': 'value1'}}

    expected_value = 'key2: value1\n'

    patcher = Patcher(dictionary)
    value = patcher.get('key1', fmt=constants.YAML)

    assert expected_value == value
Exemple #15
0
def test_set_unicode():

    dictionary = {'key1': 'value1'}

    expected_dictionary = {'key1': 'value2'}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1', u'value2').finish()

    assert expected_dictionary == dictionary
Exemple #16
0
def test_get_existing_one_level_complex_key():

    dictionary = {'key1': {'key2': 'value1'}}

    expected_value = 'value1'

    patcher = Patcher(dictionary)
    value = patcher.get('key1:key2')

    assert expected_value == value
Exemple #17
0
def test_remove_from_complex_key():

    dictionary = {'key1': {'key2': ['value1', 'value2']}}

    expected_dictionary = {'key1': {'key2': ['value1']}}

    patcher = Patcher(dictionary)
    patcher.remove(key='key1:key2', value='value2')

    assert expected_dictionary == dictionary
Exemple #18
0
def test_get_float():

    dictionary = {'key1': 5.5}

    expected_value = '5.5'

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    assert expected_value == value
Exemple #19
0
def test_get_integer():

    dictionary = {'key1': 5}

    expected_value = '5'

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    assert expected_value == value
Exemple #20
0
def test_get_string():

    dictionary = {'key1': 'value1'}

    expected_value = 'value1'

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    assert expected_value == value
Exemple #21
0
def test_delete():

    dictionary = {'key1': 'value1', 'key2': 'value2'}

    expected_dictionary = {'key2': 'value2'}

    patcher = Patcher(dictionary)
    dictionary = patcher.delete('key1').finish()

    assert expected_dictionary == dictionary
Exemple #22
0
def test_remove():

    dictionary = {'key1': ['value1', 'value2']}

    expected_dictionary = {'key1': ['value1']}

    patcher = Patcher(dictionary)
    patcher.remove(key='key1', value='value2')

    assert expected_dictionary == dictionary
Exemple #23
0
def test_add():

    dictionary = {'key': ['value1']}

    expected_dictionary = {'key': ['value1', 'value2']}

    patcher = Patcher(dictionary)
    patcher.add(key='key', value='value2')

    assert expected_dictionary == dictionary
Exemple #24
0
def test_set_list():

    dictionary = {'key1': 'value1'}

    expected_dictionary = {'key1': ['value1', 'value2']}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1', '["value1", "value2"]').finish()

    assert expected_dictionary == dictionary
Exemple #25
0
def test_delete():

    dictionary = {'key1': 'value1', 'key2': 'value2'}

    expected_dictionary = {'key2': 'value2'}

    patcher = Patcher(dictionary)
    dictionary = patcher.delete('key1').finish()

    assert expected_dictionary == dictionary
Exemple #26
0
def test_add():

    dictionary = {'key': ['value1']}

    expected_dictionary = {'key': ['value1', 'value2']}

    patcher = Patcher(dictionary)
    patcher.add(key='key', value='value2')

    assert expected_dictionary == dictionary
Exemple #27
0
def test_set_unicode():

    dictionary = {'key1': 'value1'}

    expected_dictionary = {'key1': 'value2'}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1', u'value2').finish()

    assert expected_dictionary == dictionary
Exemple #28
0
def test_set_float():

    dictionary = {'key1': 'value1'}

    expected_dictionary = {'key1': 5.5}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1', '5.5').finish()

    assert expected_dictionary == dictionary
Exemple #29
0
def test_set_dict():

    dictionary = {'key1': 'value1'}

    expected_dictionary = {'key1': {'key2': 'value2'}}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1', '{"key2":"value2"}').finish()

    assert expected_dictionary == dictionary
Exemple #30
0
def test_get_ini_section():

    dictionary = {'section': {'key1': 'key2'}}

    expected_value = writer.dumps(obj={'key1': 'key2'},
                                  fmt=constants.PROPERTIES)

    patcher = Patcher(dictionary)
    value = patcher.get('section', fmt=constants.INI)

    assert expected_value == value
Exemple #31
0
def test_get_list_as_yaml():

    dictionary = {'key1': ['value1', 'value2']}

    expected_value = '''- value1
- value2\n'''

    patcher = Patcher(dictionary)
    value = patcher.get('key1', fmt=constants.YAML)

    assert expected_value == value
Exemple #32
0
def test_get_float():

    dictionary = {
        'key1': 5.5
    }

    expected_value = '5.5'

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    assert expected_value == value
Exemple #33
0
def test_get_integer():

    dictionary = {
        'key1': 5
    }

    expected_value = '5'

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    assert expected_value == value
Exemple #34
0
def test_get_string():

    dictionary = {
        'key1': 'value1'
    }

    expected_value = 'value1'

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    assert expected_value == value
Exemple #35
0
def test_set_float():

    dictionary = {'key1': 'value1'}

    expected_dictionary = {
        'key1': 5.5
    }

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1', '5.5').finish()

    assert expected_dictionary == dictionary
Exemple #36
0
def test_set_list():

    dictionary = {'key1': 'value1'}

    expected_dictionary = {
        'key1': ['value1', 'value2']
    }

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1', '["value1", "value2"]').finish()

    assert expected_dictionary == dictionary
Exemple #37
0
def test_get_dict_as_json():

    dictionary = {'key1': {'key2': 'value1'}}

    expected_value = '''{
  "key2": "value1"
}'''

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    assert expected_value == value
Exemple #38
0
def test_set_dict():

    dictionary = {'key1': 'value1'}

    expected_dictionary = {
        'key1': {
            'key2': 'value2'
        }}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1', '{"key2":"value2"}').finish()

    assert expected_dictionary == dictionary
Exemple #39
0
def test_get_list_as_yaml():

    dictionary = {
        'key1': ['value1', 'value2']
    }

    expected_value = '''- value1
- value2\n'''

    patcher = Patcher(dictionary)
    value = patcher.get('key1', fmt=constants.YAML)

    assert expected_value == value
Exemple #40
0
def test_remove():

    dictionary = {
        'key1': ['value1', 'value2']
    }

    expected_dictionary = {
        'key1': ['value1']
    }

    patcher = Patcher(dictionary)
    patcher.remove(key='key1', value='value2')

    assert expected_dictionary == dictionary
Exemple #41
0
def test_get_existing_one_level_complex_key():

    dictionary = {
        'key1': {
            'key2': 'value1'
        }
    }

    expected_value = 'value1'

    patcher = Patcher(dictionary)
    value = patcher.get('key1:key2')

    assert expected_value == value
Exemple #42
0
def test_get_ini_section():

    dictionary = {
        'section': {
            'key1': 'key2'
        }
    }

    expected_value = writer.dumps(obj={'key1': 'key2'}, fmt=constants.PROPERTIES)

    patcher = Patcher(dictionary)
    value = patcher.get('section', fmt=constants.INI)

    assert expected_value == value
Exemple #43
0
def test_get_non_existing_two_level_complex_key():

    dictionary = {
        'key1': {
            'key2': {
                'key3': 'value1'
            }
        }
    }

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.KeyNotFoundException):
        patcher.get('key1:key2:key4')
Exemple #44
0
def test_get_dict_as_yaml():

    dictionary = {
        'key1': {
            'key2': 'value1'
        }
    }

    expected_value = 'key2: value1\n'

    patcher = Patcher(dictionary)
    value = patcher.get('key1', fmt=constants.YAML)

    assert expected_value == value
Exemple #45
0
def test_get_list_as_json():

    dictionary = {'key1': ['value1', 'value2']}

    expected_value = '''[
"value1",
"value2"
]'''

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    actual = value.replace(' ', '')

    assert expected_value == actual
Exemple #46
0
def configure(ctx, alias):

    repo = ctx.parent.repo

    file_path = repo.path(alias)

    try:
        parsed = parser.load(file_path=file_path, fmt=repo.fmt(alias))
    except exceptions.CorruptFileException as e:
        e.cause = causes.EDITED_MANUALLY
        e.possible_solutions = [
            solutions.edit_manually(),
            solutions.reset_to_latest(alias)
        ]
        raise

    # detect if the file was manually edited since the last command.
    # if so, warn because it means the current version of the file is not
    # under version control and will be lost after the change
    latest = parser.loads(repo.contents(alias=alias, version='latest'),
                          fmt=repo.fmt(alias))
    if latest != parsed:

        exception = click.ClickException(message='Cannot perform operation')
        exception.cause = causes.DIFFER_FROM_LATEST
        exception.possible_solutions = [
            solutions.reset_to_latest(alias),
            solutions.commit(alias)
        ]
        raise exception

    patcher = Patcher(parsed)
    ctx.patcher = patcher
Exemple #47
0
def test_get_dict_as_json():

    dictionary = {
        'key1': {
            'key2': 'value1'
        }
    }

    expected_value = '''{
  "key2": "value1"
}'''

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    assert expected_value == value
Exemple #48
0
def test_get_list_as_json():

    dictionary = {
        'key1': ['value1', 'value2']
    }

    expected_value = '''[
"value1",
"value2"
]'''

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    actual = value.replace(' ', '')

    assert expected_value == actual
Exemple #49
0
def test_remove_from_complex_key():

    dictionary = {
        'key1': {
            'key2': ['value1', 'value2']
        }
    }

    expected_dictionary = {
        'key1': {
            'key2': ['value1']
        }
    }

    patcher = Patcher(dictionary)
    patcher.remove(key='key1:key2', value='value2')

    assert expected_dictionary == dictionary
Exemple #50
0
def test_set_existing_one_level_complex_key():

    dictionary = {
        'key1': {
            'key2': 'value1'
        }
    }

    expected_dictionary = {
        'key1': {
            'key2': 'value2'
        }
    }

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1:key2', 'value2').finish()

    assert expected_dictionary == dictionary
Exemple #51
0
def test_add_to_complex_key():

    dictionary = {
        'key1': {
            'key2': ['value1']
        }
    }

    expected_dictionary = {
        'key1': {
            'key2': ['value1', 'value2']
        }
    }

    patcher = Patcher(dictionary)
    patcher.add(key='key1:key2', value='value2')

    assert expected_dictionary == dictionary
Exemple #52
0
def test_set_complex_key_compound_value():

    dictionary = {
        'key1': {
            'key2': 'value1'
        }
    }

    expected_dictionary = {
        'key1': {
            'key2': {
                'key3': 'value2'
            }
        }}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1:key2', '{"key3":"value2"}').finish()

    assert expected_dictionary == dictionary
Exemple #53
0
def test_delete_complex_key():

    dictionary = {
        'key1': {
            'key2': 'value1',
            'key3': 'value2'
        }
    }

    expected_dictionary = {
        'key1': {
            'key2': 'value1'
        }
    }

    patcher = Patcher(dictionary)
    dictionary = patcher.delete('key1:key3').finish()

    assert expected_dictionary == dictionary