예제 #1
0
def test_apps_catalog_load_with_empty_cache(mocker):

    # Initialize ...
    _initialize_apps_catalog_system()

    # Cache is empty
    assert not glob.glob(APPS_CATALOG_CACHE + "/*")

    # Update
    with requests_mock.Mocker() as m:

        # Mock the server response with a dummy apps catalog
        m.register_uri("GET",
                       APPS_CATALOG_DEFAULT_URL_FULL,
                       text=DUMMY_APP_CATALOG)

        # Try to load the apps catalog
        # This should implicitly trigger an update in the background
        mocker.spy(m18n, "n")
        app_dict = _load_apps_catalog()["apps"]
        m18n.n.assert_any_call("apps_catalog_obsolete_cache")
        m18n.n.assert_any_call("apps_catalog_update_success")

    # 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()
예제 #2
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()
예제 #3
0
def test_apps_catalog_load_with_oudated_api_version(mocker):

    # Initialize ...
    _initialize_apps_catalog_system()

    # Update
    with requests_mock.Mocker() as m:

        mocker.spy(m18n, "n")
        m.register_uri("GET",
                       APPS_CATALOG_DEFAULT_URL_FULL,
                       text=DUMMY_APP_CATALOG)
        _update_apps_catalog()

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

    # Tweak the cache to replace the from_api_version with a different one
    for cache_file in glob.glob(APPS_CATALOG_CACHE + "/*"):
        cache_json = read_json(cache_file)
        assert cache_json["from_api_version"] == APPS_CATALOG_API_VERSION
        cache_json["from_api_version"] = 0
        write_to_json(cache_file, cache_json)

    # Update
    with requests_mock.Mocker() as m:

        # Mock the server response with a dummy apps catalog
        m.register_uri("GET",
                       APPS_CATALOG_DEFAULT_URL_FULL,
                       text=DUMMY_APP_CATALOG)

        mocker.spy(m18n, "n")
        app_dict = _load_apps_catalog()["apps"]
        m18n.n.assert_any_call("apps_catalog_update_success")

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

    # Check that we indeed have the new api number in cache
    for cache_file in glob.glob(APPS_CATALOG_CACHE + "/*"):
        cache_json = read_json(cache_file)
        assert cache_json["from_api_version"] == APPS_CATALOG_API_VERSION