def test_unit_of_work_roundtrip(self): unit = UnitOfWork(None) loc = Location(10, 11) loc.name = "Loc 1" unit.insert(loc) unit_dict = self.marshaller.obj_to_dict(unit) self.assertEquals("unit_of_work", unit_dict["class"]) unit2 = self.marshaller.dict_to_obj(unit_dict) self.assertEquals(10.0, unit2._to_insert[0].latitude) self.assertEquals(11.0, unit2._to_insert[0].longitude)
def test_location_persist(self): loc = Location(10.0, 11.0) loc.name = "Location" loc1 = self.service.persist(loc) self.assertEquals(1, loc1.version) loc1.version = 0 self.assertRaises(StaleObjectError, self.service.persist, loc1) loc1.version = 1 loc2 = self.service.persist(loc1) self.assertEquals(2, loc2.version)
def test_listeners(self): # Use a list to beat the closure called = [False] def loc_listener(obj, var, value): # The listener will be called when the object is posted # and when it is committed, so we want to filter out the # post call if var == "_id" and value > 0: called.remove(False) called.append(True) loc = Location() loc.name = "Test Loc1" loc.set_listener(loc_listener) work = self.ingester_platform.createUnitOfWork() work.post(loc) work.commit() self.assertTrue(called[0])
def test_dataset_persist(self): schema = DataEntrySchema("base1") schema.addAttr(FileDataType("file")) schema = self.service.persist(schema) loc = Location(10.0, 11.0) loc.name = "Location" loc = self.service.persist(loc) dataset = Dataset() dataset.schema = schema.id dataset.location = loc.id dataset1 = self.service.persist(dataset) self.assertEquals(1, dataset1.version) dataset1.version = 0 self.assertRaises(StaleObjectError, self.service.persist, dataset1) dataset1.version = 1 dataset2 = self.service.persist(dataset1) self.assertEquals(2, dataset2.version)
def test_dataset_data_source_unit(self): """This test creates a simple schema hierarchy, and tests updates, etc""" unit = UnitOfWork(None) schema1 = DataEntrySchema("base1") schema1.addAttr(FileDataType("file")) schema_id = unit.post(schema1) loc = Location(10.0, 11.0) loc.name = "Location" loc_id = unit.post(loc) dataset1 = Dataset() dataset1.schema = schema_id dataset1.location = loc_id dataset1_id = unit.post(dataset1) dataset2 = Dataset() dataset2.schema = schema_id dataset2.location = loc_id dataset2.data_source = DatasetDataSource(dataset1_id, "") dataset2_id = unit.post(dataset2) ret = self.service.commit(unit, None) found = False for r in ret: if isinstance(r, Dataset) and dataset1_id == r.correlationid: dataset1_id = r.id elif isinstance(r, Dataset) and dataset2_id == r.correlationid: self.assertEquals(dataset1_id, r.data_source.dataset_id, "Data source dataset_id was not updated") found = True self.assertTrue( found, "Didn't find the dataset with the dataset data source")
def test_unit_of_work_validation(self): unit = UnitOfWork(None) loc = Location(10, 11) self.assertRaises(InvalidObjectError, unit.insert, loc) loc.name = "test" unit.insert(loc) # Should work now.