def test_result_type(self): single_result = pdb.get(self.setup_key) self.assertTrue(isinstance(single_result, db.Model)) dict_result = pdb.get(self.setup_key,_result_type='dict') self.assertTrue(isinstance(dict_result, dict)) self.assertEqual(dict_result.keys()[0],str(self.setup_key)) self.assertEqual(dict_result.values()[0].name,'test') name_dict_result = pdb.get(self.setup_key,_result_type='name_dict') self.assertTrue(isinstance(name_dict_result, dict)) self.assertEqual(name_dict_result.keys()[0],self.setup_key.name()) self.assertEqual(name_dict_result.values()[0].name,'test') #Check for integer based key e1 = TestModel(name='integer_test') k1 = pdb.put(e1) name_dict_result = pdb.get(k1,_result_type='name_dict') self.assertTrue(isinstance(name_dict_result, dict)) self.assertEqual(name_dict_result.keys()[0],str(k1.id())) self.assertEqual(name_dict_result.values()[0].name,'integer_test')
def test_result_type(self): single_result = pdb.get(self.setup_key) self.assertTrue(isinstance(single_result, db.Model)) dict_result = pdb.get(self.setup_key, _result_type='dict') self.assertTrue(isinstance(dict_result, dict)) self.assertEqual(dict_result.keys()[0], str(self.setup_key)) self.assertEqual(dict_result.values()[0].name, 'test') name_dict_result = pdb.get(self.setup_key, _result_type='name_dict') self.assertTrue(isinstance(name_dict_result, dict)) self.assertEqual(name_dict_result.keys()[0], self.setup_key.name()) self.assertEqual(name_dict_result.values()[0].name, 'test') #Check for integer based key e1 = TestModel(name='integer_test') k1 = pdb.put(e1) name_dict_result = pdb.get(k1, _result_type='name_dict') self.assertTrue(isinstance(name_dict_result, dict)) self.assertEqual(name_dict_result.keys()[0], str(k1.id())) self.assertEqual(name_dict_result.values()[0].name, 'integer_test')
def test_cascaded_cache_refresh(self): e1 = TestModel() k1 = db.put(e1) #Memcache refresh from datastore pdb.get(k1,_storage =['memcache','datastore'] ) e2 = pdb.get(k1,_storage ='memcache') self.assertEqual(e1.key(),e2.key()) #Local refresh from datastore pdb.get(k1,_storage =['local','datastore']) e2 = pdb.get(k1,_storage='local') self.assertEqual(e1.key(),e2.key()) #Local refresh from memcache e3 = TestModel(key_name='memcache_model') k3 = pdb.put(e3,_storage='memcache') pdb.get(k3, _storage=['local','memcache']) e4 = pdb.get(k3,_storage='local') self.assertEqual(e3.key(),e4.key())
def test_cascaded_cache_refresh(self): e1 = TestModel() k1 = db.put(e1) #Memcache refresh from datastore pdb.get(k1, _storage=['memcache', 'datastore']) e2 = pdb.get(k1, _storage='memcache') self.assertEqual(e1.key(), e2.key()) #Local refresh from datastore pdb.get(k1, _storage=['local', 'datastore']) e2 = pdb.get(k1, _storage='local') self.assertEqual(e1.key(), e2.key()) #Local refresh from memcache e3 = TestModel(key_name='memcache_model') k3 = pdb.put(e3, _storage='memcache') pdb.get(k3, _storage=['local', 'memcache']) e4 = pdb.get(k3, _storage='local') self.assertEqual(e3.key(), e4.key())
def test_cached_set(self): class RefModel(pdb.Model): reference = db.ReferenceProperty(PdbModel) models = [] for i in range(100): models.append(RefModel(reference=self.setup_key)) pdb.put(models) pdb_model = pdb.get(self.setup_key) #First call creates memcache index refs = pdb_model.cached_set('refmodel_set') self.assertEqual(len(refs), len(models))
def test_cached_set(self): class RefModel(pdb.Model): reference = db.ReferenceProperty(PdbModel) models = [] for i in range(100): models.append(RefModel(reference=self.setup_key)) pdb.put(models) pdb_model = pdb.get(self.setup_key) #First call creates memcache index refs = pdb_model.cached_set('refmodel_set') self.assertEqual(len(refs),len(models))
def test_get_local(self): entity = pdb.get(self.setup_key,_storage=['local']) self.assertEqual('test', entity.name)
def test_get_memcache(self): entity = pdb.get(self.setup_key,_storage=['memcache']) self.assertEqual('test', entity.name)
def test_get_db(self): entity = pdb.get(self.setup_key,_storage='datastore') self.assertEqual('test', entity.name)
def test_get_local(self): entity = pdb.get(self.setup_key, _storage=['local']) self.assertEqual('test', entity.name)
def test_get_memcache(self): entity = pdb.get(self.setup_key, _storage=['memcache']) self.assertEqual('test', entity.name)
def test_get_db(self): entity = pdb.get(self.setup_key, _storage='datastore') self.assertEqual('test', entity.name)