def test_jsonDictAllHP(self):
     p = Proposal.objects.all()[0]
     pa = ProposalHttpAdapter(proposal = 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))
Exemple #2
0
    def test_from_post(self):

        self.assertEqual(1, len(Proposal.objects.all()))

        p = Proposal.objects.all()[0]
        pa = ProposalHttpAdapter(proposal = p)
        ormJson = pa.jsonDict()
        ormJson['pcode'] = u'GBT12A-003'

        pa.initFromPost(ormJson)
        self.assertEqual(2, len(Proposal.objects.all()))
Exemple #3
0
    def read(self, request, *args, **kws):
        if len(args) == 1:
            pcode,   = args
            adapter  = ProposalHttpAdapter(Proposal.objects.get(pcode = pcode))
            return HttpResponse(json.dumps(adapter.jsonDict())
                              , content_type = 'application/json')
        else:
            # Keep this here for when we start doing pagenation
            """
            start = request.GET.get('start', 0)
            limit = request.GET.get('limit', 25)
            end   = int(start) + int(limit)
            """
            propJson = ProposalHttpAdapter.jsonDictAllHP()

            return HttpResponse(json.dumps({"success" : "ok"
                                          , "proposals" : propJson
                                          , "total" : len(propJson)
                                           })
                              , content_type = 'application/json')