def Test_WriteOutDAG(self):

        dag = TagDAGBuilderClass()
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\shorttaglist.json", "r")
        dag.StoreMasterTagList(None, file.read())
        file.close()
        aVertexKey = db.Key.from_path("TagVertex", "6mm")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "6mm")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\6mmlinks_short.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()
        aVertexKey = db.Key.from_path("TagVertex", "2mm")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "2mm")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\2mmlinks_short.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()
        aVertexKey = db.Key.from_path("TagVertex", "28mm")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "28mm")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\28mmlinks_short.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        dagAsJsonString = dag.DumpDAGToJsonString()
        file = open("c:\\temp\\smallTagDAG.json", "w")
        file.write(dagAsJsonString)
        file.close()
    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)
    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)
    def Test_GetAdjacentVertices_SmallDag_MultipleUsers(self):

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

        dag = TagDAGBuilderClass()
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\shorttaglist.json", "r")
        dag.StoreMasterTagList(u1, file.read())
        file.close()
        aVertexKey = db.Key.from_path("MyUser", "Bill", "TagVertex", "6mm")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "6mm")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\6mmlinks_short.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()
        aVertexKey = db.Key.from_path("MyUser", "Bill", "TagVertex", "2mm")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "2mm")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\2mmlinks_short.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()
        aVertexKey = db.Key.from_path("MyUser", "Bill", "TagVertex", "28mm")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "28mm")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\28mmlinks_short.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()
        aVertexKey = db.Key.from_path("MyUser", "Bill", "TagVertex", "acrylic")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "acrylic")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\acryliclinks_short.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()
        aVertexKey = db.Key.from_path("MyUser", "Bill", "TagVertex", "activities")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "activities")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\activitieslinks_short.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()
        aVertexKey = db.Key.from_path("MyUser", "Bill", "TagVertex", "accessories")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "accessories")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\accessorieslinks_short.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        #add *some* of the same tags and edges for the second user
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\shorttaglist.json", "r")
        dag.StoreMasterTagList(u2, file.read())
        file.close()
        aVertexKey = db.Key.from_path("MyUser", "Ted", "TagVertex", "6mm")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "6mm")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\6mmlinks_short.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        #actionscript has no links

        # walk to depth 1 - should just get the parent tag
        vertexDict = dag.GetDAGSubset("Bill", "6mm", 1)
        check.ok_(len(vertexDict) == 1)
        check.ok_(vertexDict.has_key("6mm") == True)
        check.ok_(vertexDict.has_key("28mm") == False)
        check.ok_(vertexDict.has_key("2mm") == False)
        check.ok_(vertexDict.has_key("activities") == False)
        check.ok_(vertexDict.has_key("acrylic") == False)
        check.ok_(vertexDict.has_key("accessories") == False)
        check.ok_(vertexDict.has_key("actionscript") == False)

        vertexDict = dag.GetDAGSubset("Bill", "acrylic", 1)
        check.ok_(len(vertexDict) == 1)
        check.ok_(vertexDict.has_key("6mm") == False)
        check.ok_(vertexDict.has_key("28mm") == False)
        check.ok_(vertexDict.has_key("2mm") == False)
        check.ok_(vertexDict.has_key("activities") == False)
        check.ok_(vertexDict.has_key("acrylic") == True)
        check.ok_(vertexDict.has_key("accessories") == False)
        check.ok_(vertexDict.has_key("actionscript") == False)

        vertexDict = dag.GetDAGSubset("Bill", "actionscript", 1)
        check.ok_(len(vertexDict) == 1)
        check.ok_(vertexDict.has_key("6mm") == False)
        check.ok_(vertexDict.has_key("28mm") == False)
        check.ok_(vertexDict.has_key("2mm") == False)
        check.ok_(vertexDict.has_key("activities") == False)
        check.ok_(vertexDict.has_key("acrylic") == False)
        check.ok_(vertexDict.has_key("accessories") == False)
        check.ok_(vertexDict.has_key("actionscript") == True)

        # walk to depth 2 - should get 6 tags
        vertexDict = dag.GetDAGSubset("Bill", "6mm", 2)
        check.ok_(len(vertexDict) == 6)
        check.ok_(vertexDict.has_key("6mm") == True)
        check.ok_(vertexDict.has_key("28mm") == True)
        check.ok_(vertexDict.has_key("2mm") == True)
        check.ok_(vertexDict.has_key("activities") == True)
        check.ok_(vertexDict.has_key("acrylic") == True)
        check.ok_(vertexDict.has_key("accessories") == True)
        check.ok_(vertexDict.has_key("actionscript") == False)

        # walk to depth 2 - should get 3 tags
        vertexDict = dag.GetDAGSubset("Bill", "activities", 2)
        check.ok_(len(vertexDict) == 3)
        check.ok_(vertexDict.has_key("6mm") == True)
        check.ok_(vertexDict.has_key("28mm") == False)
        check.ok_(vertexDict.has_key("2mm") == True)
        check.ok_(vertexDict.has_key("activities") == True)
        check.ok_(vertexDict.has_key("acrylic") == False)
        check.ok_(vertexDict.has_key("accessories") == False)
        check.ok_(vertexDict.has_key("actionscript") == False)
    def Test_MakeMediumDAG(self):

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

        aVertexKey = db.Key.from_path("TagVertex", "2mm")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "2mm")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\2mmLinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("TagVertex", "6mm")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "6mm")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\6mmlinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("TagVertex", "28mm")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "28mm")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\28mmLinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("TagVertex", "accessories")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "accessories")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\accessoriesLinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("TagVertex", "acrylic")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "acrylic")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\acrylicLinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("TagVertex", "activities")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "activities")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\activitiesLinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("TagVertex", "booksearch")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "booksearch")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\booksearchLinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("TagVertex", "bookshop")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "bookshop")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\bookshopLinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("TagVertex", "brass")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "brass")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\brassLinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("TagVertex", "breakfast")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "breakfast")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\breakfastLinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("TagVertex", "browser")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "browser")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\browserLinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("TagVertex", "buildings")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "buildings")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\buildingsLinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("TagVertex", "campaigns")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "campaigns")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\campaignsLinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("TagVertex", "casting")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "casting")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\castingLinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("TagVertex", "CDs")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "CDs")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\CDsLinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("TagVertex", "charts")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "charts")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\chartsLinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("TagVertex", "tools")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "tools")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\toolsLinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("TagVertex", "cabinets")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "cabinets")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\mediumTagDag\\cabinetsLinks_medium.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        dagAsJsonString = dag.DumpDAGToJsonString()
        file = open("c:\\temp\\mediumTagDAG.json", "w")
        file.write(dagAsJsonString)
        file.close()
    def Test_AddEdgesToStoreForMultipleTags(self):

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

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

        aVertexKey = db.Key.from_path("MyUser", u2.key().name(), "TagVertex", "6mm")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "6mm")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\6mmlinks_short.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("MyUser", u2.key().name(), "TagVertex", "2mm")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "2mm")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\2mmlinks_short.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        aVertexKey = db.Key.from_path("MyUser", u2.key().name(), "TagVertex", "28mm")
        aVertex = db.get(aVertexKey)
        check.ok_(aVertex.key().name() == "28mm")
        file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\28mmlinks_short.json", "r")
        dag.AddEdgesForVertex(aVertex, file.read())
        file.close()

        #"28mm":62, "2mm":1, "6mm":29, "accessories":52, "acrylic":14, "actionscript":1, "activities":3

        k = db.Key.from_path("MyUser", u2.key().name(), "TagVertex", "28mm")
        testVertex = db.get(k)
        check.ok_(len(testVertex.edges) == 0)

        k = db.Key.from_path("MyUser", u2.key().name(), "TagVertex", "2mm")
        testVertex = db.get(k)
        check.ok_(len(testVertex.edges) == 2)

        k = db.Key.from_path("MyUser", u2.key().name(), "TagVertex", "6mm")
        testVertex = db.get(k)
        check.ok_(len(testVertex.edges) == 5)

        k = db.Key.from_path("MyUser", u2.key().name(), "TagVertex", "accessories")
        testVertex = db.get(k)
        
        check.ok_(len(testVertex.edges) == 0)
        k = db.Key.from_path("MyUser", u2.key().name(), "TagVertex", "acrylic")
        testVertex = db.get(k)
        
        check.ok_(len(testVertex.edges) == 0)
        k = db.Key.from_path("MyUser", u2.key().name(), "TagVertex", "actionscript")
        testVertex = db.get(k)
        
        check.ok_(len(testVertex.edges) == 0)
        k = db.Key.from_path("MyUser", u2.key().name(), "TagVertex", "activities")
        testVertex = db.get(k)
        check.ok_(len(testVertex.edges) == 0)