Ejemplo n.º 1
0
def test_config_file_printing(prepare_config_file):
    config, config_text = prepare_config_file
    tested_path = "parent.parent_update_node"

    original_value = get_attribute_by_path(tested_path, parse(config_text))
    assert original_value not in print_config_with_hidden_attrs(
        parse(config_text), [tested_path])
Ejemplo n.º 2
0
def test_create_or_update_attribute(mode):
    (action, obj), where = mode
    value = "baz"
    if action == "update":
        attribute_path = f"{where}_foo"
    else:
        attribute_path = "foz"

    if obj == "table":
        attribute_path = "new_table." + attribute_path

    if where == "parent":
        attribute_path = "parent." + attribute_path
    elif where == "child":
        attribute_path = "parent.child." + attribute_path

    updated_config = create_update_attr(attribute=attribute_path,
                                        value=value,
                                        config=source_config)
    assert (updated_config != source_config
            ), "This function should not change the original content"
    assert (get_attribute_by_path(attribute_path=attribute_path,
                                  config=updated_config) == value)
    assert updated_config["control_value"] == "value"
    # Test that the attribute is actually added and found
    # Maybe move this to a separate test? Probably dup?
    if action == "update":
        checked_attributes = get_filled_attributes(source_config)
    else:
        checked_attributes = get_filled_attributes(source_config) + (
            attribute_path, )

    assert set(checked_attributes) == set(
        get_filled_attributes(updated_config))
Ejemplo n.º 3
0
def test_get_attribute_by_path(path):
    *_, location = path[0].split(".")
    attribute_name = path[1]
    if attribute_name == "foz" or location == "nonexistent_child":
        attribute_value = None
    else:
        attribute_value = f"{location}_bar"

    attribute_name = f"{location}_" + attribute_name
    if location == "root":
        location = None

    if location:
        attribute_path = f"{'.'.join(_ + [location])}.{attribute_name}"
    else:
        attribute_path = f"{attribute_name}"

    assert (get_attribute_by_path(attribute_path=attribute_path,
                                  config=source_config) == attribute_value)
Ejemplo n.º 4
0
def test_single_dialog_existing_file_multiple_updates(user_updates_values,
                                                      prepare_config_file,
                                                      monkeypatch):
    """In a scenario where there are more than 1 keys to update - make sure that permutations of user input are
    handled correctly"""
    new_value = "new_value"
    update_attrs = ["update_node", "parent.parent_update_node"]
    answer_1, answer_2 = user_updates_values
    config, config_text = prepare_config_file
    test_input = ["Y"]
    for user_answer in [answer_1, answer_2]:
        if user_answer:
            test_input += ["Y", new_value]
        else:
            test_input += ["N"]
    test_input += ["Y"]
    setup_input(monkeypatch, test_input)

    assert config_dialog(config, update_attrs)
    for user_answer, attr in zip([answer_1, answer_2], update_attrs):
        # The value should be updated <=> user said yes
        assert user_answer == (get_attribute_by_path(
            attribute_path=attr,
            config=parse(config.read_text())) == new_value)
Ejemplo n.º 5
0
def test_page_add_dialog(prepare_config_file, monkeypatch):
    config, config_text = prepare_config_file
    setup_input(monkeypatch, ["title", "testfile", "", "SPC", "Y"])
    assert page_add_dialog(config)
    assert (get_attribute_by_path("pages.page1.page_title",
                                  parse(config.read_text())) == "title")