def do_business(self): super(PasswordlessDetailCheck, self).do_business() if not self.errors: app = self.result self.result = None fetch_cmd = UrlFetchCommand(self.detail_url, {'ticket': self.ticket, 'app_id': app.app_id, 'token': app.token}, 'POST').execute() self.errors.update(fetch_cmd.errors) if not self.errors: dct = json.loads(fetch_cmd.result.content) cmd_parallel = CommandParallel(GetMainUserByEmail(dct['email']) , GetPasswordlessUser(dct['id'])) cmd_parallel.execute() main_user, passwordless_user = cmd_parallel[0].result, cmd_parallel[1].result if passwordless_user: main_user = SingleDestinationSearch(ExternalToMainUser, passwordless_user).execute().result elif main_user: passwordless_user_key = PasswordlessUser(external_id=dct['id']).put() self._to_commit = ExternalToMainUser(origin=passwordless_user_key, destination=main_user.key) else: main_user = MainUser(name=dct['email'], email=dct['email']) passwordless_user = PasswordlessUser(external_id=dct['id']) ndb.put_multi([main_user, passwordless_user]) self._to_commit = ExternalToMainUser(origin=passwordless_user.key, destination=main_user.key) self.result = main_user
def do_business(self): super(PasswordlessDetailCheck, self).do_business() if not self.errors: app = self.result self.result = None fetch_cmd = UrlFetchCommand(self.detail_url, {'ticket': self.ticket, 'app_id': app.app_id, 'token': app.token}, 'POST').execute() self.errors.update(fetch_cmd.errors) if not self.errors: dct = json.loads(fetch_cmd.result.content) cmd_parallel = CommandParallel(GetMainUserByEmail(dct['email']), GetPasswordlessUser(dct['id'])) cmd_parallel.execute() main_user, passwordless_user = cmd_parallel[0].result, cmd_parallel[1].result if passwordless_user: main_user = MainUserSearch(passwordless_user).execute().result elif main_user: passwordless_user_key = PasswordlessUser(external_id=dct['id']).put() self._to_commit = ExternalToMainUser(origin=passwordless_user_key, destination=main_user.key) else: main_user = MainUser(name=dct['email'], email=dct['email']) passwordless_user = PasswordlessUser(external_id=dct['id']) ndb.put_multi([main_user, passwordless_user]) self._to_commit = ExternalToMainUser(origin=passwordless_user.key, destination=main_user.key) self.result = main_user
def test_execute_successful_business(self): MOCK_1 = "mock 1" MOCK_2 = "mock 2" mock_1 = CommandMock(MOCK_1) mock_2 = CommandMock(MOCK_2) command_list = CommandParallel(mock_1, mock_2) errors = command_list.execute().errors self.assert_command_executed(mock_1, MOCK_1) self.assert_command_executed(mock_2, MOCK_2) self.assertDictEqual({}, errors)
def busca_produtos(_logged_user, busca): cmd = facade.list_observacoes_cmd() observacoes = cmd() busca = slugify(busca) pesquisa = Observacoe.query(Observacoe.busca >= busca).order(Observacoe.busca) get_dono_cmd_lista=[GetDonoObs(o) for o in observacoes] paralelo=CommandParallel(*get_dono_cmd_lista) paralelo() edit_path = router.to_path(edit) delete_path = router.to_path(delete) short_form = facade.observacoe_short_form() def short_observacoe_dict(observacoe): observacoe_dct = short_form.fill_with_model(observacoe) observacoe_dct['edit_path'] = router.to_path(edit_path, observacoe_dct['id']) observacoe_dct['delete_path'] = router.to_path(delete_path, observacoe_dct['id']) return observacoe_dct short_observacoes = [short_observacoe_dict(observacoe) for observacoe in observacoes] for observacao,dono_comando in zip(short_observacoes,get_dono_cmd_lista): observacao['dono_flag']=(dono_comando.result ==_logged_user) context = {'observacoe': short_observacoes, 'new_path': router.to_path(new), 'observacoes': pesquisa.fetch() } return TemplateResponse(context, router.to_path('observacoes/admin/home.html'))
def index(_logged_user): cmd = facade.list_observacoes_cmd() observacoes = cmd() get_dono_cmd_lista = [GetDonoObs(o) for o in observacoes] paralelo = CommandParallel(*get_dono_cmd_lista) paralelo() edit_path = router.to_path(edit) delete_path = router.to_path(delete) short_form = facade.observacoe_short_form() def short_observacoe_dict(observacoe): observacoe_dct = short_form.fill_with_model(observacoe) observacoe_dct['edit_path'] = router.to_path(edit_path, observacoe_dct['id']) observacoe_dct['delete_path'] = router.to_path(delete_path, observacoe_dct['id']) return observacoe_dct short_observacoes = [ short_observacoe_dict(observacoe) for observacoe in observacoes ] for observacao, dono_comando in zip(short_observacoes, get_dono_cmd_lista): observacao['dono_flag'] = (dono_comando.result == _logged_user) context = { 'observacoes': short_observacoes, 'new_path': router.to_path(new) } return TemplateResponse(context)
def do_business(self, stop_on_error=True): super(ModelSearchWithRelations, self).do_business(stop_on_error) if self._required_relations and self.result: cmds = CommandParallel( *(RelationFiller(r, self._relations, self._required_relations) for r in self.result)) cmds() for r, filler in izip(self.result, cmds): filler.fill(r)
def __init__(self, origin=None, destination=None): # this values will be set latter on _extract_and_validate or handle_previous self.origin = None self.destination = None self._command_parallel = CommandParallel(self._to_command(origin), self._to_command(destination)) super(CreateArc, self).__init__(self._command_parallel)
def index(_logged_user): cmd = facade.list_observacoes_cmd() observacoe_list = cmd() get_dono_cmd_lista = [GetDonoObs(o) for o in observacoe_list] paralelo = CommandParallel(*get_dono_cmd_lista) paralelo() short_form = facade.observacoe_short_form() observacoe_short = [short_form.fill_with_model(m) for m in observacoe_list] for observacao, dono_comando in zip(observacoe_short, get_dono_cmd_lista): observacao['dono_flag'] = (dono_comando.result == _logged_user) return JsonResponse(observacoe_short)
def index(_resp, nome): url_base = 'https://api.github.com/users' url_usuario = to_path(url_base, nome) url_repos = to_path(url_usuario, 'repos') usuario_cmd = UrlFetchCommand( url_usuario, headers={'Accept': 'application/vnd.github.v3+json'}) repo_cmd = UrlFetchCommand( url_repos, headers={'Accept': 'application/vnd.github.v3+json'}) CommandParallel(usuario_cmd, repo_cmd).execute() usuario_json = json.loads(usuario_cmd.result.content) repo_json = json.loads(repo_cmd.result.content) contexto = { 'nome': nome, 'avatar': usuario_json['avatar_url'], 'repos': [(r['name'], r['html_url']) for r in repo_json] } return TemplateResponse(contexto, 'github.html')
def do_business(self): super(ProcessExternalPaymentCmd, self).do_business() dct = self.__transaction_dct if self.result: self.result.status = XML_STATUS_TO_MODEL_STATUS.get( dct['transaction']['status']) cmd = UpdatePaymentAndSaveLog(self.result) cmd.execute() else: self.result = PagSegPayment( code=dct['transaction']['code'], status=XML_STATUS_TO_MODEL_STATUS.get( dct['transaction']['status']), total=dct['transaction']['grossAmount'], net_amount=dct['transaction']['netAmount']) payment_key = self.result.put() def create_item_cmd(item): return _SimpleSave( PagSegItem(description=item['description'], price=Decimal(item['amount']), quantity=int(item['quantity']))) items = dct['transaction']['items']['item'] if isinstance(items, dict): items = [items] items_cmd = [ CreatePaymentToItem(payment_key, create_item_cmd(item)) for item in items ] cmd = CommandParallel( CreatePagSegPaymentToLog( payment_key, _SimpleSave(PagSegLog(status=self.result.status))), *items_cmd) sender = dct['transaction'].get('sender') if sender: user = facade.get_user_by_email(sender['email'])() if user is None: user = facade.save_user_cmd(sender['email'], sender['name'])() cmd.append(SaveToPayment(user, payment_key)) cmd.execute()
def _chamar_api(repo_cmd, usuario_cmd): CommandParallel(usuario_cmd, repo_cmd).execute() usuario_json = usuario_cmd.result.content repos_json = repo_cmd.result.content return repos_json, usuario_json
def apagar_livro_cmd(livro_id): apagar_cmd = DeleteNode(livro_id) apagar_arcos = ApagarAutorArcos(livro_id) return CommandParallel(apagar_cmd, apagar_arcos)