Ejemplo n.º 1
0
def test_set_not_string():

    dictionary = {'key1': 'value1'}

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

    dictionary = {'key1': 'value1'}

    patcher = Patcher(dictionary)
    with pytest.raises(exceptions.InvalidValueTypeException):
        patcher.set('key1', 5).finish()
Ejemplo n.º 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')
Ejemplo n.º 4
0
def test_delete_non_existing_key():

    dictionary = {'key': 'value'}

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.KeyNotFoundException):
        patcher.delete('non-existing')
Ejemplo n.º 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')
Ejemplo n.º 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')
Ejemplo n.º 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')
Ejemplo n.º 8
0
def test_delete_non_existing_key():

    dictionary = {'key': 'value'}

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.KeyNotFoundException):
        patcher.delete('non-existing')
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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')
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 19
0
def test_get_integer():

    dictionary = {'key1': 5}

    expected_value = '5'

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

    assert expected_value == value
Ejemplo n.º 20
0
def test_get_string():

    dictionary = {'key1': 'value1'}

    expected_value = 'value1'

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

    assert expected_value == value
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 33
0
def test_get_integer():

    dictionary = {
        'key1': 5
    }

    expected_value = '5'

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

    assert expected_value == value
Ejemplo n.º 34
0
def test_get_string():

    dictionary = {
        'key1': 'value1'
    }

    expected_value = 'value1'

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

    assert expected_value == value
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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')
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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