示例#1
0
def test_parse_releases(infopl, alfred4):
    """Parse releases JSON"""
    dls = Download.from_releases(RELEASES_JSON)
    assert len(dls) == len(VALID_DOWNLOADS), "wrong no. of downloads"

    for i, dl in enumerate(dls):
        print(("dl=%r, x=%r" % (dl, VALID_DOWNLOADS[i])))
        assert dl == VALID_DOWNLOADS[i], "different downloads"
示例#2
0
def test_parse_releases(infopl, alfred4):
    """Parse releases JSON"""
    dls = Download.from_releases(RELEASES_JSON)
    assert len(dls) == len(VALID_DOWNLOADS), "wrong no. of downloads"

    for i, dl in enumerate(dls):
        print('dl=%r, x=%r' % (dl, VALID_DOWNLOADS[i]))
        assert dl == VALID_DOWNLOADS[i], "different downloads"
示例#3
0
def test_compare_downloads():
    """Compare Downloads"""
    dl = Download(
        "https://github.com/deanishe/alfred-workflow-dummy/releases/download/v11/Dummy-11.0.alfredworkflow",  # noqa: E501
        "Dummy-11.0.alfredworkflow",
        "v11",
        False)

    for other in VALID_DOWNLOADS:
        assert dl > other, "unexpected comparison"
        assert dl != other, "unexpected equality"
示例#4
0
def test_latest_download(infopl):
    """Latest download for Alfred version."""
    dls = Download.from_releases(RELEASES_JSON)
    tests = (
        # downloads, alfred version, prereleases, wanted result
        ([], None, False, None),
        (dls, None, False, "9.0"),
        (dls, None, True, "10.0-beta"),
        (dls, "4", False, "9.0"),
        (dls, "4", True, "10.0-beta"),
        (dls, "3", False, "6.0"),
        (dls, "3", True, "10.0-beta"),
    )

    for data, version, pre, wanted in tests:
        dl = update.latest_download(data, version, pre)
        if wanted is None:
            assert dl is None, "latest is not None"
        else:
            assert dl.version == Version(wanted), "unexpected version"
示例#5
0
def test_latest_download(infopl):
    """Latest download for Alfred version."""
    dls = Download.from_releases(RELEASES_JSON)
    tests = (
        # downloads, alfred version, prereleases, wanted result
        ([], None, False, None),
        (dls, None, False, '9.0'),
        (dls, None, True, '10.0-beta'),
        (dls, '4', False, '9.0'),
        (dls, '4', True, '10.0-beta'),
        (dls, '3', False, '6.0'),
        (dls, '3', True, '10.0-beta'),
    )

    for data, version, pre, wanted in tests:
        dl = update.latest_download(data, version, pre)
        if wanted is None:
            assert dl is None, "latest is not None"
        else:
            assert dl.version == Version(wanted), "unexpected version"
示例#6
0
# It contains multiple releases, some valid, some invalid
# The .alfredworkflow files in the releases are working demos.
#
# The repo has since been mirrored to the `tests/data` directory
# (see DATA_* variables above), so the tests can run offline.
TEST_REPO = "deanishe/alfred-workflow-dummy"
EMPTY_REPO = "deanishe/alfred-workflow-empty-dummy"
GH_ROOT = "https://github.com/" + TEST_REPO
GH_API_ROOT = "https://api.github.com/repos/" + TEST_REPO
RELEASES_URL = GH_API_ROOT + "/releases"
URL_DL = "https://github.com/releases/download/v6.0/Dummy-6.0.alfredworkflow"
URL_BAD = "http://github.com/file.zip"
# INVALID_RELEASE_URL = GH_ROOT + '/releases/download/v3.0/Dummy-3.0.zip'

DL_BAD = Download(url="http://github.com/file.zip",
                  filename="file.zip",
                  version=Version("0"))


@contextmanager
def fakeresponse(httpserver, content, headers=None):
    """Monkey patch `web.request()` to return the specified response."""
    httpserver.serve_content(content, headers=headers)
    orig = requests.request

    def _request(*args, **kwargs):
        """Replace request URL with `httpserver` URL"""
        new_args = (args[0], httpserver.url) + args[2:]
        print("intercept", args, kwargs, "->", new_args)
        return orig(*new_args, **kwargs)