def test_folding(info2):
    """Magic: folding"""
    with WorkflowMock(['script', 'workflow:foldingdefault']):
        wf = Workflow()
        # Process magic arguments
        wf.args
        assert wf.settings.get('__workflow_diacritic_folding') is None

    with WorkflowMock(['script', 'workflow:foldingon']):
        wf = Workflow()
        # Process magic arguments
        wf.args
        assert wf.settings.get('__workflow_diacritic_folding') is True

    with WorkflowMock(['script', 'workflow:foldingdefault']):
        wf = Workflow()
        # Process magic arguments
        wf.args
        assert wf.settings.get('__workflow_diacritic_folding') is None

    with WorkflowMock(['script', 'workflow:foldingoff']):
        wf = Workflow()
        # Process magic arguments
        wf.args
        assert wf.settings.get('__workflow_diacritic_folding') is False
Exemple #2
0
    def test_no_auto_update(self):
        """Update: no update check"""

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

        self.assertIsNone(self.wf.cached_data('__workflow_update_status'))

        wf = Workflow()
        c = WorkflowMock(['script', 'workflow:noautoupdate'])
        with c:
            wf.args
        self.assertFalse(wf.settings.get('__workflow_autoupdate'))

        self.assertIsNone(self.wf.cached_data('__workflow_update_status'))

        c = WorkflowMock()
        with c:
            wf = Workflow(update_settings={
                'github_slug': TEST_REPO_SLUG,
                'version': RELEASE_CURRENT
            })

        self.assertIsNone(self.wf.cached_data('__workflow_update_status'))
def test_prereleases(info2):
    """Magic: prereleases"""
    with WorkflowMock(['script', 'workflow:prereleases']):
        wf = Workflow()
        # Process magic arguments
        wf.args
        assert wf.settings.get('__workflow_prereleases') is True
        assert wf.prereleases is True

    with WorkflowMock(['script', 'workflow:noprereleases']):
        wf = Workflow()
        # Process magic arguments
        wf.args
        assert wf.settings.get('__workflow_prereleases') is False
        assert wf.prereleases is False
Exemple #4
0
def test_notifyapp_called(infopl, alfred4):
    """Notify.app is called"""
    c = WorkflowMock()
    notify.install_notifier()
    with c:
        assert notify.notify('Test Title', 'Test Message') is False
        assert c.cmd[0] == APPLET_PATH
def test_open_term(info2):
    """Magic: open Terminal"""
    with WorkflowMock(['script', 'workflow:openterm']) as c:
        wf = Workflow()
        # Process magic arguments
        wf.args
        assert c.cmd == ['open', '-a', 'Terminal', wf.workflowdir]
def test_update_settings_override_magic_prereleases(info2):
    """Magic: pre-release updates can be overridden by `True` value for `prereleases` key in `update_settings`"""
    with WorkflowMock(['script', 'workflow:prereleases']):
        d = {'prereleases': True}
        wf = Workflow(update_settings=d)
        # Process magic arguments
        wf.args
        assert wf.settings.get('__workflow_prereleases') is True
        assert wf.prereleases is True

    with WorkflowMock(['script', 'workflow:noprereleases']):
        wf = Workflow(update_settings=d)
        # Process magic arguments
        wf.args
        assert wf.settings.get('__workflow_prereleases') is False
        assert wf.prereleases is True
def test_openlog(info2):
    """Magic: open logfile"""
    with WorkflowMock(['script', 'workflow:openlog']) as c:
        wf = Workflow()
        # Process magic arguments
        wf.args
        assert c.cmd == ['open', wf.logfile]
Exemple #8
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'])
def test_datadir(info2):
    """Magic: open datadir"""
    with WorkflowMock(['script', 'workflow:opendata']) as c:
        wf = Workflow()
        # Process magic arguments
        wf.args
        assert c.cmd == ['open', wf.datadir]
Exemple #10
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
def test_openhelp_no_url(info2):
    """Magic: no help URL"""
    with WorkflowMock(['script', 'workflow:help']) as c:
        wf = Workflow()
        # Process magic arguments
        wf.args
        assert not c.cmd
def test_openhelp(info2):
    """Magic: open help URL"""
    url = 'http://www.deanishe.net/alfred-workflow/'
    with WorkflowMock(['script', 'workflow:help']) as c:
        wf = Workflow(help_url=url)
        # Process magic arguments
        wf.args
        assert c.cmd == ['open', url]
Exemple #13
0
 def test_notifyapp_called(self):
     """Notify.app is called"""
     c = WorkflowMock()
     with InfoPlist():
         notify.install_notifier()
         with c:
             self.assertFalse(notify.notify('Test Title', 'Test Message'))
             self.assertEqual(c.cmd[0], APPLET_PATH)
def test_list_magic(info2):
    """Magic: list magic"""
    # TODO: Verify output somehow
    with WorkflowMock(['script', 'workflow:magic']) as c:
        wf = Workflow()
        # Process magic arguments
        wf.args
        assert not c.cmd
Exemple #15
0
    def test_workflow_update_methods(self):
        """Workflow update methods"""
        def fake(wf):
            return

        Workflow().reset()
        # Initialise with outdated version
        wf = Workflow(
            update_settings={
                'github_slug': 'deanishe/alfred-workflow-dummy',
                'version': 'v2.0',
                'frequency': 1,
            })

        wf.run(fake)

        # Check won't have completed yet
        self.assertFalse(wf.update_available)

        # wait for background update check
        self.assertTrue(is_running('__workflow_update_check'))
        while is_running('__workflow_update_check'):
            time.sleep(0.05)
        time.sleep(1)

        # There *is* a newer version in the repo
        self.assertTrue(wf.update_available)

        # Mock out subprocess and check the correct command is run
        c = WorkflowMock()
        with c:
            self.assertTrue(wf.start_update())
        # wf.logger.debug('start_update : {}'.format(c.cmd))
        self.assertEquals(c.cmd[0], '/usr/bin/python')
        self.assertEquals(c.cmd[2], '__workflow_update_install')

        # Grab the updated release data, then reset the cache
        update_info = wf.cached_data('__workflow_update_status')

        wf.reset()

        # Initialise with latest available release
        wf = Workflow(
            update_settings={
                'github_slug': 'deanishe/alfred-workflow-dummy',
                'version': update_info['version'],
            })

        wf.run(fake)

        # Wait for background update check
        self.assertTrue(is_running('__workflow_update_check'))
        while is_running('__workflow_update_check'):
            time.sleep(0.05)

        # Remote version is same as the one we passed to Workflow
        self.assertFalse(wf.update_available)
        self.assertFalse(wf.start_update())
def test_delete_cache(info2):
    """Magic: delete cache"""
    with WorkflowMock(['script', 'workflow:delcache']):
        wf = Workflow()
        testpath = wf.cachefile('file.test')
        with open(testpath, 'wb') as fp:
            fp.write('test!')

        assert os.path.exists(testpath)
        # Process magic arguments
        wf.args
        assert not os.path.exists(testpath)
def test_version_magic(info2):
    """Magic: version magic"""
    # TODO: Verify output somehow

    vstr = '1.9.7'

    # Versioned
    with WorkflowMock(['script', 'workflow:version']) as c:
        with VersionFile(vstr):
            wf = Workflow()
            # Process magic arguments
            wf.args

        assert not c.cmd
        # wf.logger.debug('STDERR : {0}'.format(c.stderr))

    # Unversioned
    with WorkflowMock(['script', 'workflow:version']) as c:
        wf = Workflow()
        # Process magic arguments
        wf.args
        assert not c.cmd
Exemple #18
0
def test_no_auto_update(info):
    """No update check."""
    wf = Workflow()
    wf.reset()
    # Assert cache was cleared
    assert wf.cached_data('__workflow_update_status') is None

    c = WorkflowMock(['script', 'workflow:noautoupdate'])
    with c:
        wf = Workflow()
        wf.args
        assert wf.settings.get('__workflow_autoupdate') is False
        assert wf.cached_data('__workflow_update_status') is None

    c = WorkflowMock()
    with c:
        wf = Workflow(update_settings={
            'github_slug': TEST_REPO_SLUG,
            'version': RELEASE_CURRENT
        })

        assert wf.cached_data('__workflow_update_status') is None
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
def ctx(args=None, update_settings=None, clear=True):
    update_settings = update_settings or UPDATE_SETTINGS
    args = args or []
    c = dummy()
    if args:
        # Add placeholder for ARGV[0]
        args = ['script'] + args
    create_info_plist()
    if args:
        c = WorkflowMock(args)
    with c:
        wf = Workflow(update_settings=update_settings)
        yield wf, c
    if clear:
        wf.reset()
        delete_info_plist()
def test_delete_settings(info2):
    """Magic: delete settings"""
    with WorkflowMock(['script', 'workflow:delsettings']):
        wf = Workflow()
        wf.settings['key'] = 'value'

        assert os.path.exists(wf.settings_path)

        wf2 = Workflow()
        assert wf2.settings['key'] == 'value'

        # Process magic arguments
        wf.args

        wf3 = Workflow()
        assert 'key' not in wf3.settings
def test_reset(info2):
    """Magic: reset"""
    with WorkflowMock(['script', 'workflow:reset']):
        wf = Workflow()
        wf.settings['key'] = 'value'
        datatest = wf.datafile('data.test')
        cachetest = wf.cachefile('cache.test')
        settings_path = wf.datafile('settings.json')

        for p in (datatest, cachetest):
            with open(p, 'wb') as file_obj:
                file_obj.write('test!')

        for p in (datatest, cachetest, settings_path):
            assert os.path.exists(p)

        # Process magic arguments
        wf.args

        for p in (datatest, cachetest, settings_path):
            assert not os.path.exists(p)