Example #1
0
    def test_get_protobuf_from_entity_using_dict(self):
        entity_1 = FooModel(name='foo', age=15, married=False)
        entity_1.put()
        entity_2 = FooModel(name='bar', age=30, married=True)
        entity_2.put()
        entity_3 = FooModel(name='baz', age=45, married=False)
        entity_3.put()

        entity_dict = {
            'entity_1': entity_1,
            'entity_2': entity_2,
            'entity_3': entity_3,
        }

        pbs = ext_db.get_protobuf_from_entity(entity_dict)

        entities = ext_db.get_entity_from_protobuf(pbs)
        entity_1 = entities['entity_1']
        entity_2 = entities['entity_2']
        entity_3 = entities['entity_3']

        self.assertEqual(isinstance(entity_1, FooModel), True)
        self.assertEqual(entity_1.name, 'foo')
        self.assertEqual(entity_1.age, 15)
        self.assertEqual(entity_1.married, False)

        self.assertEqual(isinstance(entity_2, FooModel), True)
        self.assertEqual(entity_2.name, 'bar')
        self.assertEqual(entity_2.age, 30)
        self.assertEqual(entity_2.married, True)

        self.assertEqual(isinstance(entity_3, FooModel), True)
        self.assertEqual(entity_3.name, 'baz')
        self.assertEqual(entity_3.age, 45)
        self.assertEqual(entity_3.married, False)
Example #2
0
    def test_many_models_to_and_from_protobuf(self):
        entity_1 = FooModel(name='foo', age=15, married=False)
        entity_1.put()
        entity_2 = FooModel(name='bar', age=30, married=True)
        entity_2.put()
        entity_3 = FooModel(name='baz', age=45, married=False)
        entity_3.put()

        pbs = ext_db.get_protobuf_from_entity([entity_1, entity_2, entity_3])
        self.assertEqual(len(pbs), 3)

        entity_1, entity_2, entity_3 = ext_db.get_entity_from_protobuf(pbs)
        self.assertEqual(isinstance(entity_1, FooModel), True)
        self.assertEqual(entity_1.name, 'foo')
        self.assertEqual(entity_1.age, 15)
        self.assertEqual(entity_1.married, False)

        self.assertEqual(isinstance(entity_2, FooModel), True)
        self.assertEqual(entity_2.name, 'bar')
        self.assertEqual(entity_2.age, 30)
        self.assertEqual(entity_2.married, True)

        self.assertEqual(isinstance(entity_3, FooModel), True)
        self.assertEqual(entity_3.name, 'baz')
        self.assertEqual(entity_3.age, 45)
        self.assertEqual(entity_3.married, False)
Example #3
0
    def test_many_models_to_and_from_protobuf(self):
        entity_1 = FooModel(name='foo', age=15, married=False)
        entity_1.put()
        entity_2 = FooModel(name='bar', age=30, married=True)
        entity_2.put()
        entity_3 = FooModel(name='baz', age=45, married=False)
        entity_3.put()

        pbs = ext_db.get_protobuf_from_entity([entity_1, entity_2, entity_3])
        self.assertEqual(len(pbs), 3)

        entity_1, entity_2, entity_3 = ext_db.get_entity_from_protobuf(pbs)
        self.assertEqual(isinstance(entity_1, FooModel), True)
        self.assertEqual(entity_1.name, 'foo')
        self.assertEqual(entity_1.age, 15)
        self.assertEqual(entity_1.married, False)

        self.assertEqual(isinstance(entity_2, FooModel), True)
        self.assertEqual(entity_2.name, 'bar')
        self.assertEqual(entity_2.age, 30)
        self.assertEqual(entity_2.married, True)

        self.assertEqual(isinstance(entity_3, FooModel), True)
        self.assertEqual(entity_3.name, 'baz')
        self.assertEqual(entity_3.age, 45)
        self.assertEqual(entity_3.married, False)
Example #4
0
    def test_get_protobuf_from_entity_using_dict(self):
        entity_1 = FooModel(name='foo', age=15, married=False)
        entity_1.put()
        entity_2 = FooModel(name='bar', age=30, married=True)
        entity_2.put()
        entity_3 = FooModel(name='baz', age=45, married=False)
        entity_3.put()

        entity_dict = {'entity_1': entity_1, 'entity_2': entity_2, 'entity_3': entity_3,}

        pbs = ext_db.get_protobuf_from_entity(entity_dict)

        entities = ext_db.get_entity_from_protobuf(pbs)
        entity_1 = entities['entity_1']
        entity_2 = entities['entity_2']
        entity_3 = entities['entity_3']

        self.assertEqual(isinstance(entity_1, FooModel), True)
        self.assertEqual(entity_1.name, 'foo')
        self.assertEqual(entity_1.age, 15)
        self.assertEqual(entity_1.married, False)

        self.assertEqual(isinstance(entity_2, FooModel), True)
        self.assertEqual(entity_2.name, 'bar')
        self.assertEqual(entity_2.age, 30)
        self.assertEqual(entity_2.married, True)

        self.assertEqual(isinstance(entity_3, FooModel), True)
        self.assertEqual(entity_3.name, 'baz')
        self.assertEqual(entity_3.age, 45)
        self.assertEqual(entity_3.married, False)
Example #5
0
    def test_one_model_to_and_from_protobuf(self):
        entity_1 = FooModel(name='foo', age=15, married=False)
        entity_1.put()

        pb_1 = ext_db.get_protobuf_from_entity(entity_1)

        entity_1 = ext_db.get_entity_from_protobuf(pb_1)
        self.assertEqual(isinstance(entity_1, FooModel), True)
        self.assertEqual(entity_1.name, 'foo')
        self.assertEqual(entity_1.age, 15)
        self.assertEqual(entity_1.married, False)
Example #6
0
    def test_one_model_to_and_from_protobuf(self):
        entity_1 = FooModel(name='foo', age=15, married=False)
        entity_1.put()

        pb_1 = ext_db.get_protobuf_from_entity(entity_1)

        entity_1 = ext_db.get_entity_from_protobuf(pb_1)
        self.assertEqual(isinstance(entity_1, FooModel), True)
        self.assertEqual(entity_1.name, 'foo')
        self.assertEqual(entity_1.age, 15)
        self.assertEqual(entity_1.married, False)
Example #7
0
 def test_no_entity_from_protobuf(self):
     res_1 = ext_db.get_entity_from_protobuf([])
     self.assertEqual(res_1, None)
Example #8
0
 def get_cache(cls, sid):
     data = memcache.get(sid)
     if data:
         return get_entity_from_protobuf(data)
Example #9
0
 def test_no_entity_from_protobuf(self):
     res_1 = ext_db.get_entity_from_protobuf([])
     self.assertEqual(res_1, None)
Example #10
0
 def get_cache(cls, sid):
     data = memcache.get(sid)
     if data:
         return get_entity_from_protobuf(data)