Esempio n. 1
0
 def _saveCache(key, method, expires=3600, content={}):
     content = pickle.dumps(content, pickle.HIGHEST_PROTOCOL)
     cached = datetime.now()
     values = {
         'hashkey': md5(key).hexdigest(),
         'query': key,
         'name': method,
         'cached': cached,
         'expired': cached + timedelta(seconds=expires),
         'content': content
     }
     rp = Response()
     [setattr(rp, key, values[key]) for key in Response.fields().keys()]
     rp.put()
Esempio n. 2
0
    def testPut(self):
        result = True
        try:
            props = [
                'hashkey', 'query', 'name', 'cached', 'expired', 'content'
            ]
            cached = datetime.now()
            values = {
                'hashkey': md5(self._hashkey).hexdigest(),
                'query': self._hashkey,
                'name': 'testPut',
                'cached': cached,
                'expired': cached + timedelta(seconds=3600),
                'content': pickle.dumps(props)
            }
            rp = Response()
            [setattr(rp, key, values[key]) for key in props]
            rp.put()

            rp = Response.all()
            rp.filter('hashkey =', md5(self._hashkey).hexdigest())
            model = rp.get()

            self.assertTrue(isinstance(model, db.Model))
            self.assertTrue(model.name, 'testPut')

        except IOError, e:
            result = False
Esempio n. 3
0
 def _saveCache(key, method, expires=3600, content={}):
     content = pickle.dumps(content, pickle.HIGHEST_PROTOCOL)
     cached = datetime.now()
     values = {
         'hashkey': md5(key).hexdigest(),
         'query': key,
         'name': method,
         'cached': cached,
         'expired': cached + timedelta(seconds=expires),
         'content': content
     }
     rp = Response()
     [setattr(rp, key, values[key]) for key in Response.fields().keys()]
     rp.put()
Esempio n. 4
0
 def setUp(self):
     self._hashkey = 'lat=1&lng=2'
     rp = Response.all()
     rp.filter('hashkey =', md5(self._hashkey).hexdigest())
     model = rp.get()
     if (not model == None):
         model.delete()
Esempio n. 5
0
 def setUp(self):
     self._hashkey = 'lat=1&lng=2'
     rp = Response.all()
     rp.filter('hashkey =', md5(self._hashkey).hexdigest())
     model = rp.get()
     if (not model == None):
         model.delete()
Esempio n. 6
0
    def testPut(self):
        result = True
        try:
            props = ['hashkey', 'query', 'name', 'cached', 'expired', 'content']
            cached = datetime.now()
            values = {
                'hashkey': md5(self._hashkey).hexdigest(),
                'query': self._hashkey,
                'name': 'testPut',
                'cached': cached,
                'expired': cached + timedelta(seconds=3600),
                'content': pickle.dumps(props)
            }
            rp = Response()
            [setattr(rp, key, values[key]) for key in props]
            rp.put()

            rp = Response.all()
            rp.filter('hashkey =', md5(self._hashkey).hexdigest())
            model = rp.get()
    
            self.assertTrue(isinstance(model, db.Model))
            self.assertTrue(model.name, 'testPut')
        
        except IOError, e:
            result = False
Esempio n. 7
0
    def _getCache(key):

        rp = Response.all()
        rp.filter('hashkey = ', md5(key).hexdigest())
        res = rp.get()

        if (not res == None):
            content = pickle.loads(res.content)
            rsp = APIResponse(content)

        return rsp if (not res == None) else False
Esempio n. 8
0
    def _getCache(key):

        rp = Response.all()
        rp.filter('hashkey = ', md5(key).hexdigest())
        res = rp.get()

        if (not res == None):
            content = pickle.loads(res.content)
            rsp = APIResponse(content)

        return rsp if (not res == None) else False
Esempio n. 9
0
    def setUp(self):
        self._value1 = 100
        self._value2 = 200

        rp = ResponseModel.all()
        rp.filter('hashkey =', md5('key1=value&key2=' + str(self._value1)).hexdigest())
        mdl1 = rp.get()
        if (not mdl1 == None):
            print 'rm1'
            mdl1.delete()

        rp.filter('hashkey =', md5('key1=value&key2=' + str(self._value2)).hexdigest())
        mdl2 = rp.get()
        if (not mdl2 == None):
            print 'rm2'
            mdl2.delete()
Esempio n. 10
0
 def setUp(self):
     rp = ResponseModel.all()
     rp.filter('hashkey = ', md5('Latitude=35.6763&Longitude=139.8105').hexdigest())
     mdl = rp.get()
     if (not mdl == None):
         mdl.delete()