Exemplo n.º 1
0
def text_write_list_to_yaml(tmp_path):
    new_file = tmp_path / "newfile.yaml"

    dummy_list = ["foo", "bar", "baz"]
    write_to_yaml(str(new_file), dummy_list)

    _yaml = read_yaml(str(new_file))
    assert _yaml == ["foo", "bar", "baz"]
Exemplo n.º 2
0
def test_write_to_yaml_bad_perms(test_yaml, mocker):
    error = "foobar"

    mocker.patch("builtins.open", side_effect=IOError(error))
    with pytest.raises(MoulinetteError) as exception:
        write_to_yaml(str(test_yaml), {"a": 1})

    translation = m18n.g("cannot_write_file", file=str(test_yaml), error=error)
    expected_msg = translation.format(file=str(test_yaml), error=error)
    assert expected_msg in str(exception)
Exemplo n.º 3
0
def _skip_all_migrations():
    """
    Skip all pending migrations.
    This is meant to be used during postinstall to
    initialize the migration system.
    """
    all_migrations = _get_migrations_list()
    new_states = {"migrations": {}}
    for migration in all_migrations:
        new_states["migrations"][migration.id] = "skipped"
    write_to_yaml(MIGRATIONS_STATE_PATH, new_states)
Exemplo n.º 4
0
def test_write_yaml_to_file_exception(test_file, mocker):
    error = "foobar"

    dummy_dict = {"foo": 42, "bar": ["a", "b", "c"]}

    mocker.patch("builtins.open", side_effect=Exception(error))
    with pytest.raises(MoulinetteError) as exception:
        write_to_yaml(str(test_file), dummy_dict)

    translation = m18n.g("error_writing_file", file=str(test_file), error=error)
    expected_msg = translation.format(file=str(test_file), error=error)
    assert expected_msg in str(exception)
Exemplo n.º 5
0
def test_write_dict_to_yaml(tmp_path):
    new_file = tmp_path / "newfile.yaml"

    dummy_dict = {"foo": 42, "bar": ["a", "b", "c"]}
    write_to_yaml(str(new_file), dummy_dict)
    _yaml = read_yaml(str(new_file))

    assert "foo" in _yaml.keys()
    assert "bar" in _yaml.keys()

    assert _yaml["foo"] == 42
    assert _yaml["bar"] == ["a", "b", "c"]
Exemplo n.º 6
0
def test_apps_catalog_load_with_conflicts_between_lists(mocker):

    # Initialize ...
    _initialize_apps_catalog_system()

    conf = [
        {
            "id": "default",
            "url": APPS_CATALOG_DEFAULT_URL
        },
        {
            "id":
            "default2",
            "url":
            APPS_CATALOG_DEFAULT_URL.replace("yunohost.org", "yolohost.org"),
        },
    ]

    write_to_yaml(APPS_CATALOG_CONF, conf)

    # Update
    with requests_mock.Mocker() as m:

        # Mock the server response with a dummy apps catalog
        # + the same apps catalog for the second list
        m.register_uri("GET",
                       APPS_CATALOG_DEFAULT_URL_FULL,
                       text=DUMMY_APP_CATALOG)
        m.register_uri(
            "GET",
            APPS_CATALOG_DEFAULT_URL_FULL.replace("yunohost.org",
                                                  "yolohost.org"),
            text=DUMMY_APP_CATALOG,
        )

        # Try to load the apps catalog
        # This should implicitly trigger an update in the background
        mocker.spy(logger, "warning")
        app_dict = _load_apps_catalog()["apps"]
        logger.warning.assert_any_call(AnyStringWith("Duplicate"))

    # Cache shouldn't be empty anymore empty
    assert glob.glob(APPS_CATALOG_CACHE + "/*")

    assert "foo" in app_dict.keys()
    assert "bar" in app_dict.keys()
Exemplo n.º 7
0
def _write_migration_state(migration_id, state):

    current_states = tools_migrations_state()
    current_states["migrations"][migration_id] = state
    write_to_yaml(MIGRATIONS_STATE_PATH, current_states)
Exemplo n.º 8
0
def _diagnosis_write_configuration(conf):
    write_to_yaml(DIAGNOSIS_CONFIG_FILE, conf)
Exemplo n.º 9
0
def test_write_yaml_cannot_write_to_non_existant_folder():
    with pytest.raises(AssertionError):
        write_to_yaml("/toto/test.yaml", ["a", "b"])