def do_business(self): # execution origin if not self._origin_validation_cmd: self._origin_cmd.do_business() result = self._origin_cmd.result if result and result.key: self._origin_validation_cmd = self._extract_command( to_node_key(result), _OriginHasDestinationRaiseError) self._origin_validation_cmd.set_up() if self._origin_validation_cmd: self._origin_validation_cmd.do_business() self.errors.update(self._origin_validation_cmd.errors) self.origin = self._origin_validation_cmd.result if not self._destination_validation_cmd: self._destination_cmd.do_business() result = self._destination_cmd.result if result and result.key: self._destination_validation_cmd = self._extract_command( to_node_key(result), _DestinationHasOriginRaiseError) self._destination_validation_cmd.set_up() if self._destination_validation_cmd: self._destination_validation_cmd.do_business() self.errors.update(self._destination_validation_cmd.errors) self.destination = self._destination_validation_cmd.result
def do_business(self): # execution origin if not self._origin_validation_cmd: self._origin_cmd.do_business() result = self._origin_cmd.result if result and result.key: self._origin_validation_cmd = self._extract_command(to_node_key(result), _OriginHasDestinationRaiseError) self._origin_validation_cmd.set_up() if self._origin_validation_cmd: self._origin_validation_cmd.do_business() self.errors.update(self._origin_validation_cmd.errors) self.origin = self._origin_validation_cmd.result if not self._destination_validation_cmd: self._destination_cmd.do_business() result = self._destination_cmd.result if result and result.key: self._destination_validation_cmd = self._extract_command(to_node_key(result), _DestinationHasOriginRaiseError) self._destination_validation_cmd.set_up() if self._destination_validation_cmd: self._destination_validation_cmd.do_business() self.errors.update(self._destination_validation_cmd.errors) self.destination = self._destination_validation_cmd.result
def setarc(_resp, arc, origin_id, destination_id): arc_cls = all_arcs.get(arc) arc_count = Arc.query(Arc.origin == to_node_key(origin_id), Arc.destination == to_node_key(destination_id)).count() if arc_count > 0: _resp.write("Arc already exists") else: arc_cls(origin=to_node_key(origin_id), destination=to_node_key(destination_id)).put() _resp.write("Arc Created")
def assert_arc_creation(self, cmd, origin, destination): created_arc = cmd() self.assertEqual(to_node_key(origin), to_node_key(cmd.origin)) self.assertEqual(to_node_key(destination), to_node_key(cmd.destination)) arc = Arc.query().order(-Arc.creation).get() self.assertEqual(arc, created_arc) self.assertEqual(to_node_key(origin), to_node_key(arc.origin)) self.assertEqual(to_node_key(destination), to_node_key(arc.destination))
def __init__(self, *model_keys): class _NodeSearch(NodeSearch): _model_class = self._model_class self.model_keys = [to_node_key(m) for m in model_keys] super(DeleteNode, self).__init__(*[_NodeSearch(m) for m in self.model_keys])
def __init__(self, node_or_key_or_id, relation_factory, relations): node_key = to_node_key(node_or_key_or_id) relations = relations or [] self._relations_commands = {k: relation_factory[k](node_key) for k in relations} super(RelationFiller, self).__init__(*self._relations_commands.itervalues())
def _extract_command(self, node, cmd_class): key = None try: key = to_node_key(node) except: return None cmd = cmd_class(key) cmd.arc_class = self.arc_class return cmd
def _to_command(self, node_or_command): if isinstance(node_or_command, Command): return node_or_command cmd = Command() try: node_key = to_node_key(node_or_command) cmd.result = node_key except: pass return cmd
def _to_command(self, node_or_command): if isinstance(node_or_command, Command): return node_or_command cmd = Command() try: node_key = to_node_key(node_or_command) cmd.result = node_key except: cmd.add_error('node', 'Invalid Node') return cmd
def __init__(self, node_or_key_or_id, relation_factory, relations): node_key = to_node_key(node_or_key_or_id) relations = relations or [] self._relations_commands = { k: relation_factory[k](node_key) for k in relations } super(RelationFiller, self).__init__(*self._relations_commands.itervalues())
def tasks(cursor=None): cmd = UserSearch(cursor) user = cmd() if user: user = user[0] email = SingleEmailUserSearch(user)().email MainUser(name=email, email=email, key=to_node_key(user), creation=user.creation).put() path = to_path(tasks, cmd.cursor.urlsafe()) taskqueue.add(url=path) else: send_mail_to_admins(settings.SENDER_EMAIL, 'Migration End', 'Migration end')
def test_success(self): users_mock = Mock() google_user = Mock() user_email = '*****@*****.**' google_user.email = Mock(return_value=user_email) users_mock.get_current_user = Mock(return_value=google_user) users_mock.is_current_user_admin = Mock(return_value=True) sites.users = users_mock setup = facade.initial_setup() setup.execute() site = setup.result self.assertEqual(settings.APP_HOST, site.domain) find_user = FindOrCreateUser(user_email) find_user.execute() user = find_user.result search = SitesSearch(to_node_key(user)) search.execute() user_sites = search.result self.assertListEqual([site.key], [s.key for s in user_sites])
def __init__(self, user, site, domain=None, token=False): super(UpdateSite, self).__init__(user) self.token = token self.domain = domain self.site_key = to_node_key(site) self.user = user
def __init__(self, model_key, **form_parameters): model_or_key = model_key if isinstance( model_key, ndb.Model) else to_node_key(model_key) super(UpdateNode, self).__init__(model_or_key, **form_parameters)
def __init__(self, node_or_key_or_id): super(_NodeSearch, self).__init__() self.node_key = to_node_key(node_or_key_or_id) self._future = None
def __init__(self, model_key, **form_parameters): super(UpdateNode, self).__init__(to_node_key(model_key), **form_parameters)
def do_business(self, stop_on_error=False): if not self.errors: site_key = self._future.get_result() self._to_commit = SiteOwner(origin=to_node_key(self._user), destination=site_key)
def find_last(cls, user): return cls.query(cls.destination == to_node_key(user)).order(-cls.creation)
def __init__(self, model_key, **form_parameters): model_or_key = model_key if isinstance(model_key, ndb.Model) else to_node_key(model_key) super(UpdateNode, self).__init__(model_or_key, **form_parameters)
def editar_livro(livro_id, **propriedades): return EditarLivro(to_node_key(livro_id), **propriedades)
def __init__(self, model_key, **form_parameters): model_key=to_node_key(model_key) super(EditarEscravo, self).__init__(model_key, **form_parameters)
def test_to_node_key(self): node = Node(id=1) self.assertEqual(node.key, model.to_node_key(1)) self.assertEqual(node.key, model.to_node_key("1")) self.assertEqual(node.key, model.to_node_key(node.key)) self.assertEqual(node.key, model.to_node_key(node))
def __init__(self, *model_keys): super(DeleteNode, self).__init__(*[to_node_key(m) for m in model_keys])
def __init__(self, node_or_key_or_id): super(NodeSearch, self).__init__() self.node_key = to_node_key(node_or_key_or_id) self._future = None
def commit(self): return [cls(origin=to_node_key(self.result), destination=to_node_key(obj)) for cls, obj in [(LoginStatusArc, self.login_status), (LoginUser, self.user), (LoginSite, self.site)]]
def find_last(cls, user): return cls.query( cls.destination == to_node_key(user)).order(-cls.creation)