def test_metadata_serialization(self): import time modelobject = ModelObject() modelobject.updateID = lambda *args: 'ModelObjectID' metadata = Metadata('') # {'create_time': 1417205460.253131, # 'creator': 'ninja_owner', # 'owner': 'ninja_owner', # 'update_time': 1417205460.253132, # 'update_user': '******'} modelobjectserialized = self.mapper.serialize(modelobject) metadataserialized = modelobjectserialized['metadata'] # if serialization fails, returns None self.assertNotEqual(modelobjectserialized, None, "Serialized ModelObejct shouldn't be None") # we check the cmd attributes self.assertEquals(modelobjectserialized.get("_id"), modelobject.getID(), "Serialized ID is not the same as metadata ID") self.assertEquals( metadataserialized.get("creator"), metadata.__getattribute__("creator"), "Serialized owner is not the same as metadata creator") self.assertEquals( metadataserialized.get("owner"), metadata.__getattribute__("owner"), "Serialized owner is not the same as metadata owner") self.assertTrue( isinstance(metadataserialized.get("create_time"), float), "Serialized create_time is not int") self.assertTrue( isinstance(metadataserialized.get("update_time"), float), "Serialized update_time is not int")
def test_metadata_deserialization(self): import time modelobject = ModelObject() modelobject.updateID = lambda *args: 'ModelObjectID' # {'create_time': 1417205460.253131, # 'creator': 'ninja_owner', # 'owner': 'ninja_owner', # 'update_time': 1417205460.253132, # 'update_user': '******'} modelobjectserialized = { 'name': '', 'parent': None, 'owner': '', '_id': None, 'type': 'ModelObject', 'metadata': { 'update_time': 1417207650.761777, 'update_user': '', 'update_action': 0, 'creator': '', 'create_time': 1417207650.761777, 'update_controller_action': 'No model controller call', 'owner': '' }, 'owned': False, 'description': '' } modelobject2 = self.mapper.unserialize(modelobject, modelobjectserialized) metadata = modelobject2._metadata metadataserialized = modelobjectserialized['metadata'] # if serialization fails, returns None self.assertNotEqual(modelobjectserialized, None, "Serialized ModelObejct shouldn't be None") # we check the cmd attributes self.assertEquals(modelobjectserialized.get("_id"), modelobject.getID(), "Serialized ID is not the same as metadata ID") import ipdb ipdb.set_trace() self.assertEquals( metadataserialized.get("owner"), metadata.__getattribute__("owner"), "Serialized owner is not the same as metadata owner") self.assertEquals( metadataserialized.get("creator"), metadata.__getattribute__("creator"), "Serialized owner is not the same as metadata creator") self.assertTrue( isinstance(metadataserialized.get("create_time"), float), "Serialized create_time is not int") self.assertTrue( isinstance(metadataserialized.get("update_time"), float), "Serialized update_time is not int")
def test_metadata_deserialization(self): import time modelobject = ModelObject() modelobject.updateID = lambda *args : 'ModelObjectID' # {'create_time': 1417205460.253131, # 'creator': 'ninja_owner', # 'owner': 'ninja_owner', # 'update_time': 1417205460.253132, # 'update_user': '******'} modelobjectserialized = {'name': '', 'parent': None, 'owner': '', '_id': None, 'type': 'ModelObject', 'metadata': {'update_time': 1417207650.761777, 'update_user': '', 'update_action': 0, 'creator': '', 'create_time': 1417207650.761777, 'update_controller_action': 'No model controller call', 'owner': ''}, 'owned': False, 'description': ''} modelobject2 = self.mapper.unserialize(modelobject, modelobjectserialized) metadata = modelobject2._metadata metadataserialized = modelobjectserialized['metadata'] # if serialization fails, returns None self.assertNotEqual( modelobjectserialized, None, "Serialized ModelObejct shouldn't be None") # we check the cmd attributes self.assertEquals( modelobjectserialized.get("_id"), modelobject.getID(), "Serialized ID is not the same as metadata ID") import ipdb; ipdb.set_trace() self.assertEquals( metadataserialized.get("owner"), metadata.__getattribute__("owner"), "Serialized owner is not the same as metadata owner") self.assertEquals( metadataserialized.get("creator"), metadata.__getattribute__("creator"), "Serialized owner is not the same as metadata creator") self.assertTrue( isinstance(metadataserialized.get("create_time"), float), "Serialized create_time is not int") self.assertTrue( isinstance(metadataserialized.get("update_time"), float), "Serialized update_time is not int")
def test_metadata_serialization(self): import time modelobject = ModelObject() modelobject.updateID = lambda *args : 'ModelObjectID' metadata = Metadata('') # {'create_time': 1417205460.253131, # 'creator': 'ninja_owner', # 'owner': 'ninja_owner', # 'update_time': 1417205460.253132, # 'update_user': '******'} modelobjectserialized = self.mapper.serialize(modelobject) metadataserialized = modelobjectserialized['metadata'] # if serialization fails, returns None self.assertNotEqual( modelobjectserialized, None, "Serialized ModelObejct shouldn't be None") # we check the cmd attributes self.assertEquals( modelobjectserialized.get("_id"), modelobject.getID(), "Serialized ID is not the same as metadata ID") self.assertEquals( metadataserialized.get("creator"), metadata.__getattribute__("creator"), "Serialized owner is not the same as metadata creator") self.assertEquals( metadataserialized.get("owner"), metadata.__getattribute__("owner"), "Serialized owner is not the same as metadata owner") self.assertTrue( isinstance(metadataserialized.get("create_time"), float), "Serialized create_time is not int") self.assertTrue( isinstance(metadataserialized.get("update_time"), float), "Serialized update_time is not int")