def _coerce_type(fields): """ A coerce method masked in a validation one, as coerce has some bugs in Cerberus 0.96. Warning: Do not read from @type in other validations as this method changes the value. """ # todo move it to a coerce method when Cerberus 0.10 is out if fields: coerce_type(fields)
def _test_erase_sectors(self, fixture_name): snapshot = self.get_fixture(self.SNAPSHOT, fixture_name) # We do a Snapshot 2 times device_id = self.creation(snapshot, self.get_num_events(snapshot)) full_device, _ = self.get(self.DEVICES, '?embedded={"components": 1}', device_id) found = False for component in full_device['components']: if 'erasures' in component: hard_drive, _ = self.get(self.DEVICES, '?embedded={"erasures":1}', component['_id']) # erasure is a writeonly value self.assertNotIn('erasure', hard_drive) # erasures must exist and contain an array with 2 erasures, which are the same coerce_type(snapshot) # We add prefix to types in snapshot erasure = next((c for c in snapshot['components'] if 'serialNumber' in c and c['serialNumber'] == component['serialNumber']))['erasure'] self.assertLen(hard_drive['erasures'], 2) assert_that(erasure).is_subset_of(hard_drive['erasures'][0]) assert_that(erasure).is_subset_of(hard_drive['erasures'][1]) found = True self.assertTrue(found, 'Any component has erasures!')