Esempio n. 1
0
def test_write_file():
    tmp_dir = tempfile.gettempdir()
    tmp_file = '{}/test_out.json'.format(tmp_dir)
    arm = ArmFile('tests/test_template.json', tmp_file)
    arm.write_file()
    with open(tmp_file, 'r') as f:
        j = json.load(f)
    assert j == arm._ArmFile__data
Esempio n. 2
0
def test_get_value_orig():
    arm = ArmFile('tests/test_template.json')
    arm.set_value('parameters.storageAccountType.defaultValue', 'changed')
    assert 'changed' == arm.get_value(
        'parameters.storageAccountType.defaultValue')
    assert 'Standard_LRS' == arm.get_original_value(
        'parameters.storageAccountType.defaultValue')
Esempio n. 3
0
def test_change_log():
    arm = ArmFile('tests/test_template.json')
    key = 'parameters.storageAccountType.defaultValue'
    key2 = 'parameters.location.type'
    old = 'old_value'
    new = 'new_value'
    arm.set_value(key, 'changed')
    arm.set_value(key2, 'updated')
    changes = arm.get_change_log()
    assert changes[key][old] == 'Standard_LRS'
    assert changes[key][new] == 'changed'
    assert changes[key2][old] == 'string'
    assert changes[key2][new] == 'updated'
Esempio n. 4
0
def test_set_value_list():
    arm = ArmFile('tests/test_template.json')
    key = 'resources'
    my_list = ['a', 'b', 'c']
    arm.set_value(key, my_list)
    changes = arm.get_change_log()
    old = 'old_value'
    new = 'new_value'
    assert changes[key][old] != changes[key][new]
    assert changes[key][new] == my_list
    assert arm.get_value(key) == my_list
Esempio n. 5
0
def test_set_value_list_index():
    arm = ArmFile('tests/test_template.json')
    key = 'resources'
    my_dict = {"a": 1, "b": "string", "c": True}
    arm.set_value(key, my_dict, 0)
    changes = arm.get_change_log()
    old = 'old_value'
    new = 'new_value'
    assert changes[key][old] != changes[key][new]
    assert changes[key][new][0] == my_dict
    assert arm.get_value(key, 0) == my_dict
Esempio n. 6
0
def test_init_check_bad_src_link_url():
    with pytest.raises(ValueError, match=ArmFile.Errors.BAD_SRC_PATH):
        ArmFile('badlink.json', 'test_template')
Esempio n. 7
0
def test_set_value():
    arm = ArmFile('tests/test_template.json')
    arm.set_value('parameters.storageAccountType.defaultValue', 'changed')
    assert 'changed' == arm.get_value(
        'parameters.storageAccountType.defaultValue')
Esempio n. 8
0
def test_set_value_bad_key():
    arm = ArmFile('tests/test_template.json')
    key = 'parameters.storageAccountType.defaultValue.bad'
    with pytest.raises(KeyError, match=ArmFile.Errors.MISSING_KEY.format(key)):
        arm.set_value(key, 'changed')
Esempio n. 9
0
def test_get_value_list_index():
    arm = ArmFile('tests/test_template.json')
    key = 'resources'
    assert arm.get_value(key, 0) == arm._ArmFile__data[key][0]
Esempio n. 10
0
def test_key_exists_null():
    arm = ArmFile('tests/test_template.json')
    assert arm.key_exists('') == False
Esempio n. 11
0
def test_get_value_error():
    arm = ArmFile('tests/test_template.json')
    key = 'parameters.storageAccountType.badValue'
    with pytest.raises(KeyError, match=ArmFile.Errors.MISSING_KEY.format(key)):
        arm.get_value(key)
Esempio n. 12
0
def test_get_value_no_key():
    arm = ArmFile('tests/test_template.json')
    assert arm.get_value('') == arm._ArmFile__data
Esempio n. 13
0
def test_get_value_valid():
    arm = ArmFile('tests/test_template.json')
    assert arm.get_value(
        'parameters.storageAccountType.defaultValue') == 'Standard_LRS'
Esempio n. 14
0
def test_get_value_changed_outside_of_class():
    arm = ArmFile('tests/test_template.json')
    v = arm.get_value('parameters.storageAccountType')
    v['type'] = 'changed'
    assert v != arm.get_value('parameters.storageAccountType')
Esempio n. 15
0
def test_set_value_log_change():
    arm = ArmFile('tests/test_template.json')
    key = 'parameters.storageAccountType.defaultValue'
    arm.set_value(key, 'changed')
    assert key in arm._ArmFile__changed_values
Esempio n. 16
0
def test_init_check_src_link_local_file():
    ArmFile('tests/test_template.json', 'test_template')
Esempio n. 17
0
def test_init_check_attribute_dest():
    test = ArmFile(
        'https://raw.githubusercontent.com/TimSwart/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json',
        'test_template')
    assert hasattr(test, 'dest')
Esempio n. 18
0
def test_key_exists_invalid_2():
    arm = ArmFile('tests/test_template.json')
    assert arm.key_exists('parameters.bad') == False
Esempio n. 19
0
def test_key_exists_invalid_1():
    arm = ArmFile('tests/test_template.json')
    assert arm.key_exists('bad') == False
Esempio n. 20
0
def test_key_exists_valid_3():
    arm = ArmFile('tests/test_template.json')
    assert arm.key_exists('parameters.storageAccountType.defaultValue') == True
Esempio n. 21
0
def test_key_exists_valid_1():
    arm = ArmFile('tests/test_template.json')
    assert arm.key_exists('parameters') == True