def test_jsonDictAllHP(self): p = Period.objects.all()[0] pa = PeriodHttpAdapter(period = p) # here's what the json for this session looks like when # we use the ORM ormJson = pa.jsonDict() # here's what the json for this session looks like when # we use the high performance query of the DB sqlJsons = pa.jsonDictAllHP() self.assertEqual(1, len(sqlJsons)) sqlJson = sqlJsons[0] #keys = ormJson.keys() #print "ORM fields: " #for k in sorted(keys): # if k != 'abstract': # print k, " : ", ormJson[k] #print "********************" #print "SQL fields: " #keys = sqlJson.keys() #for k in sorted(keys): # if k != 'abstract': # print k, " : ", sqlJson[k] # still some issues w/ time accounting to figure out #self.assertEqual(ormJson, sqlJson) fields = sorted(ormJson.keys()) ignoreFields = [] for f in fields: if f not in ignoreFields: self.assertEqual(ormJson.get(f) , sqlJson.get(f))
def read(self, request, *args, **kws): if len(args) == 1: id, = args adapter = PeriodHttpAdapter(Period.objects.get(id = id)) return HttpResponse(json.dumps(adapter.jsonDict()) , content_type = 'application/json') else: pjson = PeriodHttpAdapter.jsonDictAllHP() return HttpResponse(json.dumps({"success" : "ok" , "periods" : pjson }) , content_type = 'application/json')