def process(self, input_model): """Function that checks if the composite entity id is valid Args: input_model: improvements_models.TaskEntryModel. Entity to validate. Yields: InvalidCompositeEntityError. Error for models with invalid composite entity. """ model = job_utils.clone_model(input_model) expected_composite_entity_id = ( improvements_models.TaskEntryModel.generate_composite_entity_id( model.entity_type, model.entity_id, model.entity_version)) if model.composite_entity_id != expected_composite_entity_id: yield improvements_validation_errors.InvalidCompositeEntityError( model)
def test_model_with_invalid_composite_entity(self): model = improvements_models.TaskEntryModel( id='123', entity_id='999', entity_type='exploration', entity_version=2, target_id='888', target_type='state', task_type='high_bounce_rate', status='open', composite_entity_id='invalid_id', created_on=self.NOW, last_updated=self.NOW, ) output = (self.pipeline | beam.Create([model]) | beam.ParDo( improvements_validation.ValidateCompositeEntityId())) self.assert_pcoll_equal(output, [ improvements_validation_errors.InvalidCompositeEntityError(model) ])
def test_message(self): model = improvements_models.TaskEntryModel( id='23', entity_id='999', entity_type='exploration', entity_version=2, target_id='888', target_type='state', task_type='high_bounce_rate', status='open', composite_entity_id='invalid', created_on=self.NOW, last_updated=self.NOW, ) error = improvements_validation_errors.InvalidCompositeEntityError( model) self.assertEqual( error.stderr, 'InvalidCompositeEntityError in TaskEntryModel(id="23"): model ' 'has invalid composite entity %s' % model.composite_entity_id)