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
Example #2
0
    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
Example #3
0
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")
Example #4
0
 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])
Example #6
0
    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
Example #8
0
 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
Example #9
0
 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 _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 __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())
Example #13
0
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')
Example #14
0
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')
Example #15
0
 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])
Example #16
0
 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
Example #19
0
    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, model_key, **form_parameters):
     super(UpdateNode, self).__init__(to_node_key(model_key), **form_parameters)
Example #21
0
 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)
Example #22
0
 def find_last(cls, user):
     return cls.query(cls.destination == to_node_key(user)).order(-cls.creation)
Example #23
0
 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
Example #24
0
 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)
Example #25
0
 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)
Example #26
0
def editar_livro(livro_id, **propriedades):
    return EditarLivro(to_node_key(livro_id), **propriedades)
Example #27
0
 def __init__(self, model_key, **form_parameters):
     model_key=to_node_key(model_key)
     super(EditarEscravo, self).__init__(model_key, **form_parameters)
Example #28
0
 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
Example #31
0
 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)]]
Example #32
0
 def find_last(cls, user):
     return cls.query(
         cls.destination == to_node_key(user)).order(-cls.creation)