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_LoadJSONTagList_ShortList(self): file = open("E:\\eclipse\\testworkspace\\zardoztestzone\\src\\DeliciousTagExplorer\\UnitTests\\shortTagDag\\shorttaglist.json", "r") db = TagDAGBuilderClass() dict = db.LoadJSONTagList(file.read()) file.close() check.ok_(len(dict) == 7) check.ok_(dict["28mm"] == 62) check.ok_(dict["2mm"] == 1) check.ok_(dict["6mm"] == 29) check.ok_(dict["accessories"] == 52) check.ok_(dict["acrylic"] == 14) check.ok_(dict["actionscript"] == 1) check.ok_(dict["activities"] == 3)
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)
def Test_AddMasterTagsToDataStore(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() dict = dag.StoreMasterTagList(u1, file.read()) file.close() # add an extra vertex to represent the second user's data tv = TagVertex(u2, "wild thing") tv.put() # check that the returned dictionary is complete check.ok_(dict.has_key("28mm") == True) check.ok_(dict.has_key("2mm") == True) check.ok_(dict.has_key("6mm") == True) check.ok_(dict.has_key("accessories") == True) check.ok_(dict.has_key("actionscript") == True) check.ok_(dict.has_key("activities") == True) check.ok_(dict.has_key("d'oh!") == False) check.ok_(dict.has_key("wild thing") == False) #check that the complete set of vertices is correct dict2 = {} alist = dag.GetCompleteVertexSet() for tag in alist: dict2[tag.key().name()] = tag.ttlCount #endfor check.ok_(dict2.has_key("28mm") == True) check.ok_(dict2.has_key("2mm") == True) check.ok_(dict2.has_key("6mm") == True) check.ok_(dict2.has_key("accessories") == True) check.ok_(dict2.has_key("actionscript") == True) check.ok_(dict2.has_key("activities") == True) check.ok_(dict2.has_key("d'oh!") == False) check.ok_(dict2.has_key("wild thing") == True) #check we can get a set of vertices for each user dict3 = {} alist = dag.GetCompleteVertexSetForNamedUser("Bill") for tag in alist: dict3[tag.key().name()] = tag.ttlCount #endfor check.ok_(dict3.has_key("28mm") == True) check.ok_(dict3.has_key("2mm") == True) check.ok_(dict3.has_key("6mm") == True) check.ok_(dict3.has_key("accessories") == True) check.ok_(dict3.has_key("actionscript") == True) check.ok_(dict3.has_key("activities") == True) check.ok_(dict3.has_key("d'oh!") == False) check.ok_(dict3.has_key("wild thing") == False) dict4 = {} alist = dag.GetCompleteVertexSetForNamedUser("Ted") for tag in alist: dict4[tag.key().name()] = tag.ttlCount #endfor check.ok_(dict4.has_key("28mm") == False) check.ok_(dict4.has_key("2mm") == False) check.ok_(dict4.has_key("6mm") == False) check.ok_(dict4.has_key("accessories") == False) check.ok_(dict4.has_key("actionscript") == False) check.ok_(dict4.has_key("activities") == False) check.ok_(dict4.has_key("d'oh!") == False) check.ok_(dict4.has_key("wild thing") == True) testVertexKey = db.Key.from_path("MyUser", "Bill", "TagVertex", "28mm") testVertex = db.get(testVertexKey) check.ok_(testVertex.key().name() == "28mm") check.ok_(testVertex.ttlCount == 62) check.ok_(testVertex.parent().key() == u1.key()) testVertexKey = db.Key.from_path("MyUser", "Bill", "TagVertex", "2mm") testVertex = db.get(testVertexKey) check.ok_(testVertex.key().name() == "2mm") check.ok_(testVertex.ttlCount == 1) testVertexKey = db.Key.from_path("MyUser", "Bill", "TagVertex", "6mm") testVertex = db.get(testVertexKey) check.ok_(testVertex.key().name() == "6mm") check.ok_(testVertex.ttlCount == 29) testVertexKey = db.Key.from_path("MyUser", "Bill", "TagVertex", "accessories") testVertex = db.get(testVertexKey) check.ok_(testVertex.key().name() == "accessories") check.ok_(testVertex.ttlCount == 52) testVertexKey = db.Key.from_path("MyUser", "Bill", "TagVertex", "actionscript") testVertex = db.get(testVertexKey) check.ok_(testVertex.key().name() == "actionscript") check.ok_(testVertex.ttlCount == 1) testVertexKey = db.Key.from_path("MyUser", "Bill", "TagVertex", "activities") testVertex = db.get(testVertexKey) check.ok_(testVertex.key().name() == "activities") check.ok_(testVertex.ttlCount == 3) #try to get an existing tag with the wrong user testVertexKey = db.Key.from_path("MyUser", "Ted", "TagVertex", "activities") testVertex = db.get(testVertexKey) check.ok_(testVertex == None) #try to get a tag that does not exist testVertexKey = db.Key.from_path("MyUser", "Bill", "TagVertex", "d'oh!") testVertex = db.get(testVertexKey) check.ok_(testVertex == None) # test that an empty tag string does not cause an exception dict = dag.StoreMasterTagList(u2, "") check.ok_(len(dict) == 0) s = None dict = dag.StoreMasterTagList(u2, s) check.ok_(len(dict) == 0)
def Test_EmptyJSONStrings(self): dag = TagDAGBuilderClass() # test passes if no exceptions thrown here s = "" dict = dag.LoadJSONTagList(s)
class TagVisualizerClass(webapp.RequestHandler): tdbc = TagDAGBuilderClass() tsc = TagSourceFactory().Factory() def GetCurrentUser(self): username = "" session = get_current_session() if session and session.has_key('name'): username = session['name'] #endif return username #end GetCurrentUser def post(self): try: # get a list of all tags tagsetString = self.tsc.FetchMasterTagList("Zardoz59") tagsetDict = self.tdbc.StoreMasterTagList(tagsetString) jsonString = "" if tagsetDict.has_key("6mm"): testVertexKey = db.Key.from_path("TagVertex", "6mm") testVertex = db.get(testVertexKey) nodes = [] node = {} node["id"] = testVertex.key().name() node["name"] = testVertex.key().name() data = {} data["count"] = testVertex.ttlCount node["data"] = data adjacencies = [] for edgeKey in testVertex.edges: thisEdge = db.get(edgeKey) adjacency = {} data = {} adjacency["nodeTo"] = thisEdge.myOtherVertex.key().name() data["count"] = thisEdge.edgeCount adjacency["data"] = data adjacencies.append(adjacency) #end for (edges) node["adjacencies"] = adjacencies nodes.append(node) jsonString = json.dumps(nodes) #endif stuff = {'tagDAGString': jsonString} dir = os.path.dirname(__file__) path = os.path.join(dir, 'templates', 'visualizer.html') self.response.out.write(template.render(path, stuff)) except Exception, data: logging.error("TagVisualizerClass::post exception raised: " + str(data)) self.error(404)
def post_worker(self, tagSource): userName = cgi.escape(self.request.get('getUserName')) if userName is not None: tdbc = TagDAGBuilderClass() dbm = MyMetaDataManager() #do we already know this user? user = dbm.GetUser(userName) if user is None: logging.info("Fetching master tag list for NEW user '" + userName + "'") #see if the user is known to Delicious *and* has some tags tagsetString = tagSource.FetchMasterTagList(userName) if tagsetString is None or len(tagsetString) < 2: logging.error("NEW user '" + userName + "' has no tags!") raise Exception("The user '" + userName + "' has no tags!") #endif #new user, with tags, if we get here... user = dbm.NewUser(userName) tdbc.StoreMasterTagList(user, tagsetString) else: #else we have the tags for them already... logging.info("Regenerating master tag list for KNOWN user '" + userName + "'") #endif #reset the session even if it is the same "user" session = get_current_session() if session is not None: if session.is_active(): session.terminate() #endif session['user'] = user session['name'] = userName #endif taglist = tdbc.GetCompleteVertexSetForNamedUser(user.key().name()) #sort alphabetically taglist.sort(key=lambda tag: unicode.lower(tag.key().name())) # compute the average count of tags and only show above-average ones # in the cloud. for tag in taglist: user.IncTagCount(tag.ttlCount) #endfor user.GenerateTagStats() #form up the expected tag cloud json ''' var word_list = [{text: "Lorem", weight: 15}, {text: "Ipsum", weight: 9, url: "http://jquery.com/", title: "jQuery Rocks!"}, {text: "Dolor", weight: 6}, {text: "Sit", weight: 7}, {text: "Amet", weight: 5} ...other words ''' word_list = "[" autocomplete_list = "[" filteredCount = 0 for tag in taglist: autocomplete_list = autocomplete_list + '"' + tag.key().name() + '",\n' if tag.ttlCount >= user.tagCountAverage: filteredCount = filteredCount + 1 word_list = word_list + '{text: "' + tag.key().name() + ' ", ' word_list = word_list + "weight: " + str(tag.ttlCount) + "}, " + "\n" #endif #endfor word_list = word_list.rstrip(", \n") + "]" autocomplete_list = autocomplete_list.rstrip(", \n") + "]" logging.info("Found " + str(user.numTags) + " for user '" + userName + "'. ") logging.info("Returned " + str(filteredCount) + " tags for the cloud.") return (word_list, autocomplete_list) else: logging.error("Bad or unknown user passed into StartTagSelectorClass::post() '" + userName + "'") raise Exception("Bad or unknown user passed into StartTagSelectorClass::post() '" + userName + "'") #endif return (None, None) #end post_worker #end class StartTagSelectorClass #eof