예제 #1
0
    def test_empty_repo(self):
        """Update: no releases"""

        with self.assertRaises(ValueError):
            update.check_update(EMPTY_REPO_SLUG, '1.0')

        self.assertEquals(len(update.get_valid_releases(EMPTY_REPO_SLUG)), 0)
예제 #2
0
def test_check_update(httpserver, infopl, alfred4):
    """Check update"""
    key = "__workflow_latest_version"
    tests = [
        # data, alfred version, pre, expected value
        (RELEASES_JSON, None, False, True),
        (RELEASES_JSON, "3", False, True),
        (RELEASES_4PLUS_JSON, None, False, True),
        (RELEASES_4PLUS_JSON, "3", False, False),
        (RELEASES_4PLUS_JSON, "3", True, False),
    ]

    for data, alfred, pre, wanted in tests:
        wf = Workflow()
        wf.reset()

        with fakeresponse(httpserver, data, HTTP_HEADERS_JSON):
            v = update.check_update(TEST_REPO, RELEASE_CURRENT, pre, alfred)
            assert v == wanted, "unexpected update status"

            status = wf.cached_data(key)
            assert status is not None
            assert status["available"] == wanted
            assert wf.update_available == wanted

            if wanted:  # other data may not be set if available is False
                v = update.check_update(TEST_REPO, status["version"], pre,
                                        alfred)
                assert v is False
예제 #3
0
    def test_empty_repo(self):
        """Update: no releases"""

        with self.assertRaises(ValueError):
            update.check_update(EMPTY_REPO_SLUG, '1.0')

        self.assertEquals(len(update.get_valid_releases(EMPTY_REPO_SLUG)), 0)
예제 #4
0
def test_check_update(httpserver, infopl, alfred4):
    """Check update"""
    key = '__workflow_latest_version'
    tests = [
        # data, alfred version, pre, expected value
        (RELEASES_JSON, None, False, True),
        (RELEASES_JSON, '3', False, True),
        (RELEASES_4PLUS_JSON, None, False, True),
        (RELEASES_4PLUS_JSON, '3', False, False),
        (RELEASES_4PLUS_JSON, '3', True, False),
    ]

    for data, alfred, pre, wanted in tests:
        wf = Workflow()
        wf.reset()

        with fakeresponse(httpserver, data, HTTP_HEADERS_JSON):
            v = update.check_update(TEST_REPO, RELEASE_CURRENT,
                                    pre, alfred)
            assert v == wanted, "unexpected update status"

            status = wf.cached_data(key)
            assert status is not None
            assert status['available'] == wanted
            assert wf.update_available == wanted

            if wanted:  # other data may not be set if available is False
                v = update.check_update(TEST_REPO, status['version'],
                                        pre, alfred)
                assert v is False
예제 #5
0
def test_empty_repo(httpserver, info):
    """No releases"""
    # with webget(httpserver.url):
    with fakeresponse(httpserver, DATA_JSON_EMPTY, HTTP_HEADERS_JSON):
        with pytest.raises(ValueError):
            update.check_update(EMPTY_REPO_SLUG, '1.0')
        assert len(update.get_valid_releases(EMPTY_REPO_SLUG)) == 0
예제 #6
0
def test_empty_repo(httpserver, info):
    """No releases"""
    # with webget(httpserver.url):
    with fakeresponse(httpserver, DATA_JSON_EMPTY, HTTP_HEADERS_JSON):
        with pytest.raises(ValueError):
            update.check_update(EMPTY_REPO_SLUG, '1.0')
        assert len(update.get_valid_releases(EMPTY_REPO_SLUG)) == 0
예제 #7
0
    def test_check_update(self):
        """Update: Check update"""

        self.assertTrue(update.check_update(TEST_REPO_SLUG, RELEASE_CURRENT))

        update_info = self.wf.cached_data('__workflow_update_status')
        self.assertFalse(
            update.check_update(TEST_REPO_SLUG, update_info['version']))
예제 #8
0
    def test_check_update(self):
        """Update: Check update"""

        self.assertTrue(update.check_update(TEST_REPO_SLUG, RELEASE_CURRENT))

        update_info = self.wf.cached_data('__workflow_update_status')
        self.assertFalse(update.check_update(TEST_REPO_SLUG,
                                             update_info['version']))
예제 #9
0
def test_update_available(httpserver):
    """update_available property works"""
    slug = UPDATE_SETTINGS['github_slug']
    v = UPDATE_SETTINGS['version']
    with fakeresponse(httpserver, DATA_JSON, HTTP_HEADERS_JSON):
        with ctx() as (wf, c):
            assert wf.update_available is False
            update.check_update(slug, v)
            assert wf.update_available is True
def test_update_available(httpserver, alfred4):
    """update_available property works"""
    repo = UPDATE_SETTINGS['github_slug']
    v = os.getenv('alfred_workflow_version')
    with fakeresponse(httpserver, RELEASES_JSON, HTTP_HEADERS_JSON):
        with ctx() as (wf, _):
            wf.reset()
            assert wf.update_available is False
            update.check_update(repo, v)
            assert wf.update_available is True
def test_update_available(httpserver, alfred4):
    """update_available property works"""
    repo = UPDATE_SETTINGS['github_slug']
    v = os.getenv('alfred_workflow_version')
    with fakeresponse(httpserver, RELEASES_JSON, HTTP_HEADERS_JSON):
        with ctx() as (wf, _):
            wf.reset()
            assert wf.update_available is False
            update.check_update(repo, v)
            assert wf.update_available is True
예제 #12
0
def test_check_update(httpserver, info):
    """Check update"""
    wf = Workflow()
    wf.reset()

    with fakeresponse(httpserver, DATA_JSON, HTTP_HEADERS_JSON):
        assert update.check_update(TEST_REPO_SLUG, RELEASE_CURRENT) is True

        update_info = wf.cached_data('__workflow_update_status')
        assert update_info is not None
        assert wf.update_available is True

        assert update.check_update(TEST_REPO_SLUG,
                                   update_info['version']) is False
예제 #13
0
def test_check_update(httpserver, info):
    """Check update"""
    wf = Workflow()
    wf.reset()

    with fakeresponse(httpserver, DATA_JSON, HTTP_HEADERS_JSON):
        assert update.check_update(TEST_REPO_SLUG,
                                   RELEASE_CURRENT) is True

        update_info = wf.cached_data('__workflow_update_status')
        assert update_info is not None
        assert wf.update_available is True

        assert update.check_update(TEST_REPO_SLUG,
                                   update_info['version']) is False
예제 #14
0
    def test_install_update(self):
        """Update: installs update"""

        # Make sure there's no cached update data
        wf = Workflow()
        wf.reset()

        # Verify that there's no update available
        self.assertIsNone(wf.cached_data('__workflow_update_status'))

        self.assertFalse(update.install_update(TEST_REPO_SLUG, RELEASE_LATEST))

        # Get new update data
        self.assertTrue(update.check_update(TEST_REPO_SLUG, RELEASE_CURRENT))

        # Verify new workflow is downloaded and installed
        c = WorkflowMock()
        with c:
            self.assertTrue(
                update.install_update(TEST_REPO_SLUG, RELEASE_CURRENT))
        self.assertEquals(c.cmd[0], 'open')
        self.assertTrue(c.cmd[1].endswith('.alfredworkflow'))

        self.assertFalse(
            wf.cached_data('__workflow_update_status')['available'])
예제 #15
0
    def test_install_update(self):
        """Update: installs update"""

        # Make sure there's no cached update data
        wf = Workflow()
        wf.reset()

        # Verify that there's no update available
        self.assertIsNone(wf.cached_data('__workflow_update_status'))

        self.assertFalse(update.install_update(TEST_REPO_SLUG,
                                               RELEASE_LATEST))

        # Get new update data
        self.assertTrue(update.check_update(TEST_REPO_SLUG, RELEASE_CURRENT))

        # Verify new workflow is downloaded and installed
        c = WorkflowMock()
        with c:
            self.assertTrue(update.install_update(TEST_REPO_SLUG,
                                                  RELEASE_CURRENT))
        self.assertEquals(c.cmd[0], 'open')
        self.assertTrue(c.cmd[1].endswith('.alfredworkflow'))

        self.assertFalse(wf.cached_data(
                         '__workflow_update_status')['available'])
예제 #16
0
def test_install_update(httpserver, info):
    """Update is installed"""
    # Clear any cached data
    wf = Workflow()
    wf.reset()

    # Assert cache was cleared
    assert wf.cached_data('__workflow_update_status') is None

    with fakeresponse(httpserver, DATA_JSON, HTTP_HEADERS_JSON):
        # No update for latest release
        assert update.install_update(TEST_REPO_SLUG, RELEASE_LATEST) is False

        # Check for updates
        assert update.check_update(TEST_REPO_SLUG, RELEASE_CURRENT) is True

        # Verify new workflow is downloaded and installed
        c = WorkflowMock()
        with c:
            assert update.install_update(TEST_REPO_SLUG,
                                         RELEASE_CURRENT) is True

        assert c.cmd[0] == 'open'
        assert c.cmd[1].endswith('.alfredworkflow')
        assert wf.cached_data('__workflow_update_status')['available'] is False
예제 #17
0
def test_install_update(httpserver, info):
    """Update is installed"""
    # Clear any cached data
    wf = Workflow()
    wf.reset()

    # Assert cache was cleared
    assert wf.cached_data('__workflow_update_status') is None

    with fakeresponse(httpserver, DATA_JSON, HTTP_HEADERS_JSON):
        # No update for latest release
        assert update.install_update(TEST_REPO_SLUG, RELEASE_LATEST) is False

        # Check for updates
        assert update.check_update(TEST_REPO_SLUG, RELEASE_CURRENT) is True

        # Verify new workflow is downloaded and installed
        c = WorkflowMock()
        with c:
            assert update.install_update(TEST_REPO_SLUG,
                                         RELEASE_CURRENT) is True

        assert c.cmd[0] == 'open'
        assert c.cmd[1].endswith('.alfredworkflow')
        assert wf.cached_data(
            '__workflow_update_status')['available'] is False
예제 #18
0
def test_version_formats(httpserver, info):
    """Version formats"""
    falsey = (
        # Up-to-date versions
        '6.0', 'v6.0',
        # Unknown versions
        'v8.0', '8.0',
    )
    truthy = (
        # Old versions
        'v5.0', '5.0',
    )

    with fakeresponse(httpserver, DATA_JSON, HTTP_HEADERS_JSON):
        for vstr in falsey:
            assert update.check_update(TEST_REPO_SLUG, vstr) is False
        for vstr in truthy:
            assert update.check_update(TEST_REPO_SLUG, vstr) is True
예제 #19
0
def test_version_formats(httpserver, info):
    """Version formats"""
    falsey = (
        # Up-to-date versions
        '6.0',
        'v6.0',
        # Unknown versions
        'v8.0',
        '8.0',
    )
    truthy = (
        # Old versions
        'v5.0',
        '5.0',
    )

    with fakeresponse(httpserver, DATA_JSON, HTTP_HEADERS_JSON):
        for vstr in falsey:
            assert update.check_update(TEST_REPO_SLUG, vstr) is False
        for vstr in truthy:
            assert update.check_update(TEST_REPO_SLUG, vstr) is True
예제 #20
0
def test_update_nondefault_serialiser(httpserver, info):
    """Check update works when a custom serialiser is set on Workflow

    https://github.com/deanishe/alfred-workflow/issues/113
    """
    wf = Workflow()
    wf.cache_serializer = 'json'
    wf.reset()

    with fakeresponse(httpserver, DATA_JSON, HTTP_HEADERS_JSON):
        assert update.check_update(TEST_REPO_SLUG, RELEASE_CURRENT) is True

        assert wf.update_available is True
예제 #21
0
def test_update_nondefault_serialiser(httpserver, infopl, alfred4):
    """Check update works when a custom serialiser is set on Workflow

    https://github.com/deanishe/alfred-workflow/issues/113
    """
    wf = Workflow()
    wf.cache_serializer = 'json'
    wf.reset()

    with fakeresponse(httpserver, RELEASES_JSON, HTTP_HEADERS_JSON):
        assert update.check_update(TEST_REPO,
                                   RELEASE_CURRENT) is True

        assert wf.update_available is True
예제 #22
0
    def test_version_formats(self):
        """Update: version formats"""

        # Up-to-date versions
        self.assertFalse(update.check_update(TEST_REPO_SLUG, '6.0'))
        self.assertFalse(update.check_update(TEST_REPO_SLUG, 'v6.0'))

        # Old versions
        self.assertTrue(update.check_update(TEST_REPO_SLUG, 'v5.0'))
        self.assertTrue(update.check_update(TEST_REPO_SLUG, '5.0'))

        # Unknown versions
        self.assertFalse(update.check_update(TEST_REPO_SLUG, 'v8.0'))
        self.assertFalse(update.check_update(TEST_REPO_SLUG, '8.0'))
예제 #23
0
    def test_version_formats(self):
        """Update: version formats"""

        # Up-to-date versions
        self.assertFalse(update.check_update(TEST_REPO_SLUG, '6.0'))
        self.assertFalse(update.check_update(TEST_REPO_SLUG, 'v6.0'))

        # Old versions
        self.assertTrue(update.check_update(TEST_REPO_SLUG, 'v5.0'))
        self.assertTrue(update.check_update(TEST_REPO_SLUG, '5.0'))

        # Unknown versions
        self.assertFalse(update.check_update(TEST_REPO_SLUG, 'v8.0'))
        self.assertFalse(update.check_update(TEST_REPO_SLUG, '8.0'))
예제 #24
0
def test_version_formats(httpserver, infopl, alfred4):
    """Version formats"""
    tests = (
        # current version, prereleases, alfred version, expected value
        ('6.0', False, None, True),
        ('6.0', False, '4', True),
        ('6.0', False, '3', False),
        ('6.0', True, None, True),
        ('6.0', True, '4', True),
        ('6.0', True, '3', True),
        ('9.0', False, None, False),
        ('9.0', False, '4', False),
        ('9.0', False, '3', False),
        ('9.0', True, None, True),
        ('9.0', True, '4', True),
        ('9.0', True, '3', True),
    )

    with fakeresponse(httpserver, RELEASES_JSON, HTTP_HEADERS_JSON):
        for current, pre, alfred, wanted in tests:
            v = update.check_update(TEST_REPO, current, pre, alfred)
            assert v == wanted, "unexpected update status"
예제 #25
0
def test_version_formats(httpserver, infopl, alfred4):
    """Version formats"""
    tests = (
        # current version, prereleases, alfred version, expected value
        ("6.0", False, None, True),
        ("6.0", False, "4", True),
        ("6.0", False, "3", False),
        ("6.0", True, None, True),
        ("6.0", True, "4", True),
        ("6.0", True, "3", True),
        ("9.0", False, None, False),
        ("9.0", False, "4", False),
        ("9.0", False, "3", False),
        ("9.0", True, None, True),
        ("9.0", True, "4", True),
        ("9.0", True, "3", True),
    )

    with fakeresponse(httpserver, RELEASES_JSON, HTTP_HEADERS_JSON):
        for current, pre, alfred, wanted in tests:
            v = update.check_update(TEST_REPO, current, pre, alfred)
            assert v == wanted, "unexpected update status"
예제 #26
0
def test_install_update(httpserver, infopl, alfred4):
    """Update is installed."""
    key = '__workflow_latest_version'
    # Clear any cached data
    wf = Workflow()
    wf.reset()

    # Assert cache was cleared
    assert wf.cached_data(key) is None

    with fakeresponse(httpserver, RELEASES_JSON, HTTP_HEADERS_JSON):
        # No update because no update status has been cached
        assert update.install_update() is False

        # Check for updates
        v = update.check_update(TEST_REPO, RELEASE_CURRENT)
        assert v is True

        # Verify new workflow is downloaded and installed
        with WorkflowMock() as c:
            assert update.install_update() is True
            assert c.cmd[0] == 'open'
            assert re.search(r'\.alfred(\d+)?workflow$', c.cmd[1])

        assert wf.cached_data(key)['available'] is False

        # Test mangled update data
        status = wf.cached_data(key)
        assert status['available'] is False
        assert status['download'] is None
        assert status['version'] is None
        # Flip available bit, but leave rest invalid
        status['available'] = True
        wf.cache_data(key, status)

        with WorkflowMock():
            assert update.install_update() is False
예제 #27
0
def test_install_update(httpserver, infopl, alfred4):
    """Update is installed."""
    key = "__workflow_latest_version"
    # Clear any cached data
    wf = Workflow()
    wf.reset()

    # Assert cache was cleared
    assert wf.cached_data(key) is None

    with fakeresponse(httpserver, RELEASES_JSON, HTTP_HEADERS_JSON):
        # No update because no update status has been cached
        assert update.install_update() is False

        # Check for updates
        v = update.check_update(TEST_REPO, RELEASE_CURRENT)
        assert v is True

        # Verify new workflow is downloaded and installed
        with WorkflowMock() as c:
            assert update.install_update() is True
            assert c.cmd[0] == "open"
            assert re.search(r"\.alfred(\d+)?workflow$", c.cmd[1])

        assert wf.cached_data(key)["available"] is False

        # Test mangled update data
        status = wf.cached_data(key)
        assert status["available"] is False
        assert status["download"] is None
        assert status["version"] is None
        # Flip available bit, but leave rest invalid
        status["available"] = True
        wf.cache_data(key, status)

        with WorkflowMock():
            assert update.install_update() is False
예제 #28
0
def test_empty_repo(httpserver, infopl):
    """No releases"""
    with fakeresponse(httpserver, RELEASES_JSON_EMPTY, HTTP_HEADERS_JSON):
        update.check_update(EMPTY_REPO, '1.0')
        assert len(update.get_downloads(EMPTY_REPO)) == 0
예제 #29
0
def test_empty_repo(httpserver, infopl):
    """No releases"""
    with fakeresponse(httpserver, RELEASES_JSON_EMPTY, HTTP_HEADERS_JSON):
        update.check_update(EMPTY_REPO, "1.0")
        assert len(update.get_downloads(EMPTY_REPO)) == 0