def test_last_version_explicit_version(alfred4, infopl): """Workflow: last_version explicit version""" vstr = '1.9.6' wf = Workflow() assert wf.set_last_version(vstr) is True assert wf.last_version_run == Version(vstr) wf.reset()
def test_first_run_with_version(alfred4, infopl): """Workflow: first_run""" vstr = '1.9.7' with env(alfred_workflow_version=vstr): wf = Workflow() assert wf.first_run is True wf.reset()
def createWorkflowYaml(yamlPath): # Initialize workflow workflow = Workflow() # EXAMPLE AREA - DELETE BEFORE EXECUTION # Create RawWriteStep rawStep = RawWriteStep(workflow, content=b'Testing', description="Write test string", position=1, positionType=PositionType.SECTOR) # Create step for loading boot sector from config file an write to disk fatStep = FAT32CreateBootSectorStep(workflow, pathToConfig=os.path.join( os.path.dirname(yamlPath), "fat32.yml")) # Adding steps to workflow workflow.addStep(rawStep) workflow.addStep(fatStep) # EXAMPLE AREA - DELETE BEFORE EXECUTION # Write workflow to yaml config file yaml = ruamel.yaml.YAML() with open(yamlPath, 'w') as fout: yaml.dump(workflow, fout)
def test_last_version_explicit_version(self): """Workflow: last_version explicit version""" vstr = '1.9.6' wf = Workflow() self.assertTrue(wf.set_last_version(vstr)) self.assertEqual(wf.last_version_run, Version(vstr)) wf.reset()
def setUp(self): self.libs = [os.path.join(os.path.dirname(__file__), 'lib')] self.wf = Workflow(libraries=self.libs) self.account = 'this-is-my-test-account' self.password = '******' self.password2 = 'this-is-my-other-safe-password' self.search_items = [ ('Test Item One', MATCH_STARTSWITH), ('test item two', MATCH_STARTSWITH), ('TwoExtraSpecialTests', MATCH_CAPITALS), ('this-is-a-test', MATCH_ATOM), ('the extra special trials', MATCH_INITIALS_STARTSWITH), ('not the extra special trials', MATCH_INITIALS_CONTAIN), ('intestinal fortitude', MATCH_SUBSTRING), ('the splits', MATCH_ALLCHARS), ('nomatch', 0), ] self.search_items_diacritics = [ # search key, query ('Änderungen vorbehalten', 'av'), ('Änderungen', 'anderungen'), ('überwiegend bewolkt', 'ub'), ('überwiegend', 'uberwiegend'), ('Öffnungszeiten an Feiertagen', 'offnungszeiten'), ('Öffnungszeiten an Feiertagen', 'oaf'), ('Fußpilz', 'fuss'), ('salé', 'sale') ]
def test_cachedir_is_unicode(self): """Workflow.cachedir returns Unicode""" wf = Workflow() self.assertTrue(isinstance(wf.cachedir, unicode)) self._teardown_env() wf = Workflow() self.assertTrue(isinstance(wf.cachedir, unicode))
def test_update(self): """Magic: update""" update_settings = { 'github_slug': 'deanishe/alfred-workflow-dummy', 'version': 'v2.0', 'frequency': 1, } wf = Workflow(update_settings=update_settings) self.assertFalse(wf.update_available) # Mock subprocess.call etc. so the script doesn't try to # update the workflow in Alfred c = WorkflowMock(['script', 'workflow:update']) with c: wf.args wf.logger.debug('Magic update command : {}'.format(c.cmd)) self.assertEquals(c.cmd[0], '/usr/bin/python') self.assertEquals(c.cmd[2], '__workflow_update_install') update_settings['version'] = 'v6.0' wf = Workflow(update_settings=update_settings) c = WorkflowMock(['script', 'workflow:update']) with c: wf.args # Update command wasn't called self.assertEqual(c.cmd, ())
def test_folding(self): """Magic: folding""" wf = Workflow() c = WorkflowMock(['script', 'workflow:foldingdefault']) with c: wf.args self.assertIsNone(wf.settings.get('__workflow_diacritic_folding')) wf = Workflow() c = WorkflowMock(['script', 'workflow:foldingon']) with c: wf.args self.assertTrue(wf.settings.get('__workflow_diacritic_folding')) wf = Workflow() c = WorkflowMock(['script', 'workflow:foldingdefault']) with c: wf.args self.assertIsNone(wf.settings.get('__workflow_diacritic_folding')) wf = Workflow() c = WorkflowMock(['script', 'workflow:foldingoff']) with c: wf.args self.assertFalse(wf.settings.get('__workflow_diacritic_folding'))
def test_last_version_auto_version(alfred4, infopl): """Workflow: last_version auto version""" vstr = '1.9.7' with env(alfred_workflow_version=vstr): wf = Workflow() assert wf.set_last_version() is True assert wf.last_version_run == Version(vstr) wf.reset()
def test_first_run_with_version(self): """Workflow: first_run""" vstr = '1.9.7' with VersionFile(vstr): with InfoPlist(): wf = Workflow() self.assertTrue(wf.first_run) wf.reset()
def test_first_run_no_version(alfred4, infopl2): """Workflow: first_run fails on no version""" with env(alfred_workflow_version=None): wf = Workflow() try: with pytest.raises(ValueError): wf.first_run finally: wf.reset()
def test_last_version_auto_version(self): """Workflow: last_version auto version""" vstr = '1.9.7' with VersionFile(vstr): with InfoPlist(): wf = Workflow() self.assertTrue(wf.set_last_version()) self.assertEqual(wf.last_version_run, Version(vstr)) wf.reset()
def test_additional_libs(alfred4, infopl): """Additional libraries""" wf = Workflow(libraries=LIBS) for path in LIBS: assert path in sys.path assert sys.path[0:len(LIBS)] == LIBS import youcanimportme youcanimportme.noop() wf.reset()
def test_first_run_with_previous_run(alfred4, infopl): """Workflow: first_run with previous run""" vstr = '1.9.7' last_vstr = '1.9.6' with env(alfred_workflow_version=vstr): wf = Workflow() wf.set_last_version(last_vstr) assert wf.first_run is True assert wf.last_version_run == Version(last_vstr) wf.reset()
def test_magic_args(self): """Magic args""" # cache original sys.argv oargs = sys.argv[:] # delsettings sys.argv = [oargs[0]] + [b'workflow:delsettings'] try: wf = Workflow(default_settings={'arg1': 'value1'}) self.assertEqual(wf.settings['arg1'], 'value1') self.assertTrue(os.path.exists(wf.settings_path)) self.assertRaises(SystemExit, lambda wf: wf.args, wf) self.assertFalse(os.path.exists(wf.settings_path)) finally: sys.argv = oargs[:] # delcache sys.argv = [oargs[0]] + [b'workflow:delcache'] def somedata(): return {'arg1': 'value1'} try: wf = Workflow() cachepath = wf.cachefile('somedir') os.makedirs(cachepath) wf.cached_data('test', somedata) self.assertTrue(os.path.exists(wf.cachefile('test.cpickle'))) self.assertRaises(SystemExit, lambda wf: wf.args, wf) self.assertFalse(os.path.exists(wf.cachefile('test.cpickle'))) finally: sys.argv = oargs[:]
def test_run_fails(infopl): """Run fails""" wf = Workflow() def cb(wf2): assert wf2 is wf raise ValueError('Have an error') wf.help_url = 'http://www.deanishe.net/alfred-workflow/' ret = wf.run(cb) assert ret == 1 # read name from info.plist with env(alfred_workflow_name=None): wf = Workflow() wf.name ret = wf.run(cb) assert ret == 1 # named after bundleid wf = Workflow() wf.bundleid ret = wf.run(cb) assert ret == 1 wf.reset()
def test_first_run_with_previous_run(self): """Workflow: first_run with previous run""" vstr = '1.9.7' last_vstr = '1.9.6' with VersionFile(vstr): with InfoPlist(): wf = Workflow() wf.set_last_version(last_vstr) self.assertTrue(wf.first_run) self.assertEqual(wf.last_version_run, Version(last_vstr)) wf.reset()
def test_delete_cache(self): """Magic: delete cache""" c = WorkflowMock(['script', 'workflow:delcache']) wf = Workflow() testpath = wf.cachefile('file.test') with open(testpath, 'wb') as file_obj: file_obj.write('test!') with c: self.assertTrue(os.path.exists(testpath)) # Process magic arguments wf.args self.assertFalse(os.path.exists(testpath))
def setUp(self): self.libs = [os.path.join(os.path.dirname(__file__), 'lib')] self.wf = Workflow(libraries=self.libs) self.account = 'this-is-my-test-account' self.password = '******' self.password2 = 'this-is-my-other-safe-password' self.search_items = [ ('Test Item One', MATCH_STARTSWITH), ('test item two', MATCH_STARTSWITH), ('TwoExtraSpecialTests', MATCH_CAPITALS), ('this-is-a-test', MATCH_ATOM), ('the extra special trials', MATCH_INITIALS_STARTSWITH), ('not the extra special trials', MATCH_INITIALS_CONTAIN), ('intestinal fortitude', MATCH_SUBSTRING), ('the splits', MATCH_ALLCHARS), ('nomatch', 0), ] self.search_items_diacritics = [ # search key, query ('Änderungen vorbehalten', 'av'), ('Änderungen', 'anderungen'), ('überwiegend bewolkt', 'ub'), ('überwiegend', 'uberwiegend'), ('Öffnungszeiten an Feiertagen', 'offnungszeiten'), ('Öffnungszeiten an Feiertagen', 'oaf'), ('Fußpilz', 'fuss'), ('salé', 'sale') ] self.env_data = { 'alfred_preferences': os.path.expanduser('~/Dropbox/Alfred/Alfred.alfredpreferences'), 'alfred_preferences_localhash': b'adbd4f66bc3ae8493832af61a41ee609b20d8705', 'alfred_theme': b'alfred.theme.yosemite', 'alfred_theme_background': b'rgba(255,255,255,0.98)', 'alfred_theme_subtext': b'3', 'alfred_version': b'2.4', 'alfred_version_build': b'277', 'alfred_workflow_bundleid': b'com.alfredapp.david.googlesuggest', 'alfred_workflow_cache': os.path.expanduser('~/Library/Caches/com.runningwithcrayons.' 'Alfred-2/Workflow Data/com.alfredapp.david' '.googlesuggest'), 'alfred_workflow_data': os.path.expanduser('~/Library/Application Support/Alfred 2/' 'Workflow Data/com.alfredapp.david.' 'googlesuggest'), 'alfred_workflow_name': b'Google Suggest', 'alfred_workflow_uid': b'user.workflow.B0AC54EC-601C-479A-9428-01F9FD732959', }
def test_run_fails(self): """Run fails""" def cb(wf): self.assertEqual(wf, self.wf) raise ValueError('Have an error') self.wf.name # cause info.plist to be parsed ret = self.wf.run(cb) self.assertEqual(ret, 1) # named after bundleid self.wf = Workflow() self.wf.bundleid ret = self.wf.run(cb) self.assertEqual(ret, 1)
def test_alfred_debugger(self): """Alfred debugger status""" wf = Workflow() self.assertTrue(wf.debugging) # Alfred's debugger is open self.assertEqual(wf.logger.getEffectiveLevel(), logging.DEBUG) # With debugger off self._teardown_env() data = self.env_data.copy() del data['alfred_debug'] self._setup_env(data) wf = Workflow() self.assertFalse(wf.debugging) # Alfred's debugger is closed self.assertEqual(wf.logger.getEffectiveLevel(), logging.INFO)
def post(self, request, *args, **kwargs): payment_id = request.POST.get('_submit') if payment_id: now = datetime.datetime.now() payment = Payment.objects.filter(payment_id=payment_id)[0] if not payment.is_applied: payment.create_time = now payment.is_applied = True payment.save(update_fields=['create_time', 'is_applied']) route = Route.objects.filter(route_name=PAYMENT_APPLY, company=self.user.company)[0] document = Document.objects.get_or_create(document_id=payment_id, defaults={ 'document_type': PAYMENT_TYPE, 'user': self.user, 'create_date': now }) item = Item.objects.get_or_create(document=document[0], item_name=PAYMENT_APPLY, route=route, user=self.user) #重新发起申请 if item[0].status == ITEM_REJECTED: workflow = Workflow() workflow.reApplyWorkflow(item[0], self.user, '') else: #新申请 workflow = Workflow() workflow.applyWorkflow(route, item[0], self.user) self.message_user(u"提交申请成功", 'success') return super(PaymentAdmin, self).post(request, *args, **kwargs)
def test_run_fails(self): """Run fails""" def cb(wf): self.assertEqual(wf, self.wf) raise ValueError('Have an error') self.wf.name # cause info.plist to be parsed self.wf.help_url = 'http://www.deanishe.net/alfred-workflow/' ret = self.wf.run(cb) self.assertEqual(ret, 1) # named after bundleid self.wf = Workflow() self.wf.bundleid ret = self.wf.run(cb) self.assertEqual(ret, 1)
def test_delete_settings(self): """Magic: delete settings""" c = WorkflowMock(['script', 'workflow:delsettings']) wf = Workflow() wf.settings['key'] = 'value' filepath = wf.datafile('settings.json') with c: self.assertTrue(os.path.exists(filepath)) wf2 = Workflow() self.assertEquals(wf2.settings.get('key'), 'value') # Process magic arguments wf.args self.assertFalse(os.path.exists(filepath)) wf3 = Workflow() self.assertFalse('key' in wf3.settings)
def test_last_version_on(self): """Workflow: last_version_run not empty""" vstr = '1.9.7' with InfoPlist(): with VersionFile(vstr): wf = Workflow() wf.set_last_version(vstr) self.assertEqual(Version(vstr), wf.last_version_run) wf.reset() # Set automatically with VersionFile(vstr): wf = Workflow() wf.set_last_version() self.assertEqual(Version(vstr), wf.last_version_run) wf.reset()
def setUp(self): self.libs = [os.path.join(os.path.dirname(__file__), "lib")] self.wf = Workflow(libraries=self.libs) self.account = "this-is-my-test-account" self.password = "******" self.password2 = "this-is-my-other-safe-password" self.search_items = [ ("Test Item One", MATCH_STARTSWITH), ("test item two", MATCH_STARTSWITH), ("TwoExtraSpecialTests", MATCH_CAPITALS), ("this-is-a-test", MATCH_ATOM), ("the extra special trials", MATCH_INITIALS_STARTSWITH), ("not the extra special trials", MATCH_INITIALS_CONTAIN), ("intestinal fortitude", MATCH_SUBSTRING), ("the splits", MATCH_ALLCHARS), ("nomatch", 0), ] self.search_items_diacritics = [ # search key, query ("Änderungen vorbehalten", "av"), ("Änderungen", "anderungen"), ("überwiegend bewolkt", "ub"), ("überwiegend", "uberwiegend"), ("Öffnungszeiten an Feiertagen", "offnungszeiten"), ("Öffnungszeiten an Feiertagen", "oaf"), ("Fußpilz", "fuss"), ("salé", "sale"), ]
def test_versions_from_info(alfred4, infopl): """Workflow: version from info.plist""" with env(alfred_workflow_version=None): wf = Workflow() assert str(wf.version) == WORKFLOW_VERSION assert isinstance(wf.version, Version) assert wf.version == Version(WORKFLOW_VERSION)
def test_last_version_on(alfred4, infopl): """Workflow: last_version_run not empty""" vstr = '1.9.7' with env(alfred_workflow_version=vstr): wf = Workflow() wf.set_last_version(vstr) assert Version(vstr) == wf.last_version_run wf.reset() # Set automatically with env(alfred_workflow_version=vstr): wf = Workflow() wf.set_last_version() assert Version(vstr) == wf.last_version_run wf.reset()
def test_cachefile_is_unicode(self): """Workflow.cachefile returns Unicode""" wf = Workflow() self.assertTrue(isinstance(wf.cachefile(b'test.txt'), unicode)) self.assertTrue(isinstance(wf.cachefile('über.txt'), unicode)) self._teardown_env() wf = Workflow() self.assertTrue(isinstance(wf.cachefile(b'test.txt'), unicode)) self.assertTrue(isinstance(wf.cachefile('über.txt'), unicode))
def test_info_plist_missing(self): """Info.plist missing""" delete_info_plist() try: with self.assertRaises(IOError): Workflow() finally: create_info_plist()
def test_versions_from_settings(self): """Workflow: version from `update_settings`""" vstr = '1.9.7' d = {'github_slug': 'deanishe/alfred-workflow', 'version': vstr} wf = Workflow(update_settings=d) self.assertEqual(str(wf.version), vstr) self.assertTrue(isinstance(wf.version, Version)) self.assertEqual(wf.version, Version(vstr))
def test_open_term(self): """Magic: open Terminal""" c = WorkflowMock(['script', 'workflow:openterm']) with c: wf = Workflow() # Process magic arguments wf.args self.assertEquals(c.cmd, ['open', '-a', 'Terminal', wf.workflowdir])
def WorkflowDetail(req, id, err=0): v = getAdminStdVars(req) if err == 0 and id == "": # new workflow workflow = Workflow(u"") db.session.commit() v["original_name"] = "" elif id != "" and err == 0: # edit workflow workflow = getWorkflow(id) v["original_name"] = workflow.name else: # error workflow = Workflow(u"") workflow.name = req.params.get("name", "") workflow.set("description", req.params.get("description", "")) #workflow.setAccess("write", req.params.get("writeaccess", "")) v["original_name"] = req.params.get("orig_name", "") workflow.id = req.params.get("id") db.session.commit() try: rule = { "read": [ r.ruleset_name for r in workflow.access_ruleset_assocs.filter_by( ruletype='read') ], "write": [ r.ruleset_name for r in workflow.access_ruleset_assocs.filter_by( ruletype='write') ] } except: rule = {"read": [], "write": []} v["acl_read"] = makeList(req, "read", removeEmptyStrings(rule["read"]), {}, overload=0, type="read") v["acl_write"] = makeList(req, "write", removeEmptyStrings(rule["write"]), {}, overload=0, type="write") v["workflow"] = workflow v["languages"] = config.languages v["error"] = err v["actpage"] = req.params.get("actpage") v["csrf"] = req.csrf_token.current_token return req.getTAL("web/admin/modules/workflows.html", v, macro="modify")
def test_magic_args(self): """Magic args""" # cache original sys.argv oargs = sys.argv[:] # delsettings sys.argv = [oargs[0]] + [b'workflow:delsettings'] try: wf = Workflow(default_settings={'arg1': 'value1'}) self.assertEqual(wf.settings['arg1'], 'value1') self.assertTrue(os.path.exists(wf.settings_path)) with self.assertRaises(SystemExit): wf.args self.assertFalse(os.path.exists(wf.settings_path)) finally: sys.argv = oargs[:] # delcache sys.argv = [oargs[0]] + [b'workflow:delcache'] def somedata(): return {'arg1': 'value1'} try: wf = Workflow() cachepath = wf.cachefile('somedir') os.makedirs(cachepath) wf.cached_data('test', somedata) self.assertTrue(os.path.exists(wf.cachefile('test.cpickle'))) with self.assertRaises(SystemExit): wf.args self.assertFalse(os.path.exists(wf.cachefile('test.cpickle'))) finally: sys.argv = oargs[:]
def test_update(self): """Workflow update methods""" # Initialise with outdated version wf = Workflow( update_settings={ 'github_slug': 'deanishe/alfred-workflow-dummy', 'version': 'v2.0', 'frequency': 1, }) # 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) # 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'], }) # Wait for background update check self.assertTrue(is_running('__workflow_update_check')) while is_running('__workflow_update_check'): time.sleep(0.05) # Remove version is same as the one we passed to Workflow self.assertFalse(wf.update_available) self.assertFalse(wf.start_update())
def test_versions_from_version_file(self): """Workflow: version from `version`""" vstr = '1.9.7' with VersionFile(vstr): with InfoPlist(): wf = Workflow() self.assertEqual(str(wf.version), vstr) self.assertTrue(isinstance(wf.version, Version)) self.assertEqual(wf.version, Version(vstr))
def test_versions_from_settings(alfred4, infopl2): """Workflow: version from `update_settings`""" vstr = "1.9.7" d = {"github_slug": "deanishe/alfred-workflow", "version": vstr} with env(alfred_workflow_version=None): wf = Workflow(update_settings=d) assert str(wf.version) == vstr assert isinstance(wf.version, Version) assert wf.version == Version(vstr)
def test_versions_from_file(alfred4, infopl2): """Workflow: version from `version` file""" vstr = '1.9.7' with env(alfred_workflow_version=None): with VersionFile(vstr): wf = Workflow() assert str(wf.version) == vstr assert isinstance(wf.version, Version) assert wf.version == Version(vstr)
def setUp(self): self.libs = [os.path.join(os.path.dirname(__file__), b'lib')] self.account = 'this-is-my-test-account' self.password = '******' self.password2 = 'this-is-my-other-safe-password' self.search_items = [ ('Test Item One', MATCH_STARTSWITH), ('test item two', MATCH_STARTSWITH), ('TwoExtraSpecialTests', MATCH_CAPITALS), ('this-is-a-test', MATCH_ATOM), ('the extra special trials', MATCH_INITIALS_STARTSWITH), ('not the extra special trials', MATCH_INITIALS_CONTAIN), ('intestinal fortitude', MATCH_SUBSTRING), ('the splits', MATCH_ALLCHARS), ('nomatch', 0), ] self.search_items_diacritics = [ # search key, query ('Änderungen vorbehalten', 'av'), ('Änderungen', 'anderungen'), ('überwiegend bewolkt', 'ub'), ('überwiegend', 'uberwiegend'), ('Öffnungszeiten an Feiertagen', 'offnungszeiten'), ('Öffnungszeiten an Feiertagen', 'oaf'), ('Fußpilz', 'fuss'), ('salé', 'sale') ] self.env_data = { 'alfred_preferences': os.path.expanduser('~/Dropbox/Alfred/Alfred.alfredpreferences'), 'alfred_preferences_localhash': b'adbd4f66bc3ae8493832af61a41ee609b20d8705', 'alfred_theme': b'alfred.theme.yosemite', 'alfred_theme_background': b'rgba(255,255,255,0.98)', 'alfred_theme_subtext': b'3', 'alfred_version': b'2.4', 'alfred_version_build': b'277', 'alfred_workflow_bundleid': str(BUNDLE_ID), 'alfred_workflow_cache': os.path.expanduser(b'~/Library/Caches/com.runningwithcrayons.' b'Alfred-2/Workflow Data/{}'.format(BUNDLE_ID)), 'alfred_workflow_data': os.path.expanduser(b'~/Library/Application Support/Alfred 2/' b'Workflow Data/{}'.format(BUNDLE_ID)), 'alfred_workflow_name': b'Alfred-Workflow Test', 'alfred_workflow_uid': b'user.workflow.B0AC54EC-601C-479A-9428-01F9FD732959', } self._setup_env() self.wf = Workflow(libraries=self.libs)
def test_update(self): """Workflow updating methods""" self.assertFalse(self.wf.update_available) self.wf = Workflow(update_info={ 'github_slug': 'fniephaus/alfred-pocket', 'version': 'v0.0', 'frequency': 1, }) # wait for background update check time.sleep(2) self.assertTrue(self.wf.update_available) self.assertTrue(self.wf.start_update()) update_info = self.wf.cached_data('__workflow_update_available') self.wf = Workflow(update_info={ 'github_slug': 'fniephaus/alfred-pocket', 'version': update_info['version'], }) # wait for background update check time.sleep(2) self.assertFalse(self.wf.update_available) self.assertFalse(self.wf.start_update())
def test_reset(self): """Magic: 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): self.assertTrue(os.path.exists(p)) c = WorkflowMock(['script', 'workflow:reset']) with c: wf.args for p in (datatest, cachetest, settings_path): self.assertFalse(os.path.exists(p))
def post(self, request, *args, **kwargs): payment_id = request.POST.get('_submit') if payment_id: now = datetime.datetime.now() payment = Payment.objects.filter(payment_id = payment_id)[0] if not payment.is_applied: payment.create_time = now payment.is_applied = True payment.save(update_fields=['create_time', 'is_applied']) route = Route.objects.filter(route_name = PAYMENT_APPLY, company = self.user.company)[0] document = Document.objects.get_or_create(document_id = payment_id, defaults = {'document_type':PAYMENT_TYPE, 'user':self.user, 'create_date':now}) item = Item.objects.get_or_create(document = document[0], item_name = PAYMENT_APPLY, route = route, user = self.user) #重新发起申请 if item[0].status == ITEM_REJECTED: workflow = Workflow() workflow.reApplyWorkflow(item[0], self.user, '') else:#新申请 workflow = Workflow() workflow.applyWorkflow(route, item[0], self.user) self.message_user(u"提交申请成功", 'success') return super(PaymentAdmin, self).post(request, *args, **kwargs)
def setUp(self): self.libs = [os.path.join(os.path.dirname(__file__), 'lib')] self.wf = Workflow(libraries=self.libs) self.account = 'this-is-my-test-account' self.password = '******' self.password2 = 'this-is-my-other-safe-password' self.search_items = [ ('Test Item One', MATCH_STARTSWITH), ('test item two', MATCH_STARTSWITH), ('TwoExtraSpecialTests', MATCH_CAPITALS), ('this-is-a-test', MATCH_ATOM), ('the extra special trials', MATCH_INITIALS_STARTSWITH), ('not the extra special trials', MATCH_INITIALS_CONTAIN), ('intestinal fortitude', MATCH_SUBSTRING), ('the splits', MATCH_ALLCHARS), ('nomatch', 0), ]
def test_update(self): """Workflow update methods""" # Initialise with outdated version wf = Workflow(update_settings={ 'github_slug': 'deanishe/alfred-workflow-dummy', 'version': 'v2.0', 'frequency': 1, }) # 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) # 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'], }) # Wait for background update check self.assertTrue(is_running('__workflow_update_check')) while is_running('__workflow_update_check'): time.sleep(0.05) # Remove version is same as the one we passed to Workflow self.assertFalse(wf.update_available) self.assertFalse(wf.start_update())
def test_magic_args(self): """Magic args""" # cache original sys.argv oargs = sys.argv[:] # # openlog # sys.argv = [oargs[0]] + [b'workflow:openlog'] # try: # wf = Workflow() # wf.logger.debug('This is a test message') # ensure log file exists # with self.assertRaises(SystemExit): # wf.args # finally: # sys.argv = oargs[:] # delsettings sys.argv = [oargs[0]] + [b"workflow:delsettings"] try: wf = Workflow(default_settings={"arg1": "value1"}) self.assertEqual(wf.settings["arg1"], "value1") self.assertTrue(os.path.exists(wf.settings_path)) with self.assertRaises(SystemExit): wf.args self.assertFalse(os.path.exists(wf.settings_path)) finally: sys.argv = oargs[:] # delcache sys.argv = [oargs[0]] + [b"workflow:delcache"] def somedata(): return {"arg1": "value1"} try: wf = Workflow() cachepath = wf.cachefile("somedir") os.makedirs(cachepath) wf.cached_data("test", somedata) self.assertTrue(os.path.exists(wf.cachefile("test.cache"))) with self.assertRaises(SystemExit): wf.args self.assertFalse(os.path.exists(wf.cachefile("test.cache"))) finally: sys.argv = oargs[:]
def test_last_version_set_after_run(alfred4, infopl): """Workflow: last_version set after `run()`""" vstr = '1.9.7' def cb(wf): return with env(alfred_workflow_version=vstr): wf = Workflow() assert wf.last_version_run is None wf.run(cb) wf = Workflow() assert wf.last_version_run == Version(vstr) wf.reset()
def test_last_version_set_after_run(self): """Workflow: last_version set after `run()`""" vstr = '1.9.7' def cb(wf): return with VersionFile(vstr): with InfoPlist(): wf = Workflow() self.assertTrue(wf.last_version_run is None) wf.run(cb) wf = Workflow() self.assertEqual(wf.last_version_run, Version(vstr)) wf.reset()