コード例 #1
0
    def Test_EdgeAndVertexAccessors(self):

        u1 = MyUser(None, "Bill")
        u1.put()

        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\shorttaglist.json", "r")
        dag = TagDAGBuilderClass()
        dag.StoreMasterTagList(u1, file.read())
        file.close()

        testVertexKey = db.Key.from_path("MyUser", u1.key().name(), "TagVertex", "6mm")
        testVertex = db.get(testVertexKey)
        check.ok_(testVertex != None)
        check.ok_(testVertex.key().name() == "6mm")

        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\6mmlinks_short.json", "r")
        dict = dag.AddEdgesForVertex(testVertex, file.read())
        file.close()

        testVertex = dag.GetVertex(u1.key().name(), "acrylic")
        check.ok_(testVertex != None)
        check.ok_(testVertex.key().name() == "acrylic")
        check.ok_(testVertex.ttlCount == 14)

        testVertex = dag.GetVertex("Bill", "6mm")
        check.ok_(testVertex != None)
        check.ok_(testVertex.key().name() == "6mm")
        check.ok_(testVertex.ttlCount == 29)
コード例 #2
0
    def Test_AddEdgesToStoreForOneTag(self):

        u1 = MyUser(None, "Bill")
        u1.put()
        u2 = MyUser(None, "Ted")
        u2.put()

        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\shorttaglist.json", "r")
        dag = TagDAGBuilderClass()
        dag.StoreMasterTagList(u2, file.read())
        file.close()

        testVertexKey = db.Key.from_path("MyUser", "Ted", "TagVertex", "6mm")
        testVertex = db.get(testVertexKey)
        check.ok_(testVertex != None)
        check.ok_(testVertex.key().name() == "6mm")

        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\6mmlinks_short.json", "r")
        dict = dag.AddEdgesForVertex(testVertex, file.read())
        file.close()

        check.ok_(dict.has_key("28mm") == True)
        check.ok_(dict.has_key("2mm") == True)
        check.ok_(dict.has_key("accessories") == True)
        check.ok_(dict.has_key("acrylic") == True)
        check.ok_(dict.has_key("activities") == True)
        check.ok_(dict.has_key("6mm") == False)

        check.ok_(len(testVertex.edges) == 5)
        otherVertices = testVertex.GetMyAdjacentVertices()
        check.ok_(len(otherVertices) == 5)
        check.ok_(otherVertices.has_key("28mm"))
        check.ok_(otherVertices.has_key("2mm"))
        check.ok_(otherVertices.has_key("accessories"))
        check.ok_(otherVertices.has_key("acrylic"))
        check.ok_(otherVertices.has_key("activities"))

        myEdges = testVertex.GetMyEdges()
        check.ok_(myEdges["28mm"].edgeCount == 11)
        check.ok_(myEdges["2mm"].edgeCount == 1)
        check.ok_(myEdges["accessories"].edgeCount == 4)
        check.ok_(myEdges["acrylic"].edgeCount == 5)
        check.ok_(myEdges["activities"].edgeCount == 6)

        otherVertex = dag.GetVertex(u2.key().name(), "28mm")
        myEdges = otherVertex.GetMyEdges()
        check.ok_(len(myEdges) == 0)
        check.ok_(otherVertex.key().name() == "28mm")
        theirEdges = otherVertex.GetAdjacentVerticesRecordedElsewhere()
        check.ok_(len(theirEdges) == 1)
        check.ok_(theirEdges.has_key("6mm"))

        # test no exceptions from an empty json string
        dict = dag.AddEdgesForVertex(testVertex, "")
        check.ok_(len(dict) == 0)

        #test no exceptions from a bad json string
        dict = dag.AddEdgesForVertex(testVertex, " not A { JSON string {{{")
        check.ok_(len(dict) == 0)