Exemple #1
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")
Exemple #2
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))
Exemple #3
0
 def test_neighbors(self):
     root = Node(id=1)
     neighbors = [Node(id=i) for i in xrange(2, 5)]
     arcs = [Arc(origin=root.key, destination=n.key) for n in neighbors]
     ndb.put_multi(arcs + neighbors + [root])
     searched_arcs = Arc.find_destinations(root).fetch(10)
     searched_neighbors_keys = [a.destination for a in searched_arcs]
     neighbors_keys = [n.key for n in neighbors]
     self.assertListEqual(neighbors_keys, searched_neighbors_keys)
Exemple #4
0
    def test_content_graph(self):
        video = Video()
        video.put()

        text = Text()
        text.put()

        game = Game()
        game.put()

        arc = Arc()
        arc.origin = video.key
        arc.destination = text.key
        arc.put()

        arc = Arc()
        arc.origin = video.key
        arc.destination = game.key
        arc.put()

        nexts = Arc.find_destinations(video.key).fetch(100)

        self.assertEquals(text, nexts[0].destination.get())
        self.assertEquals(game, nexts[1].destination.get())