def test_model_invalid_id_error(self) -> None: model = base_models.BaseCommitLogEntryModel(id='123', created_on=self.YEAR_AGO, last_updated=self.NOW, commit_type='invalid-type', user_id='', post_commit_status='', commit_cmds=[]) error = base_validation_errors.InvalidCommitTypeError(model) self.assertEqual( error.stderr, 'InvalidCommitTypeError in BaseCommitLogEntryModel(id="123"): ' 'Commit type invalid-type is not allowed')
def process(self, entity): """Function that defines how to process each entity in a pipeline of models. Args: entity: datastore_services.Model. Entity to validate. Yields: ModelCommitTypeError. Error for commit_type validation. """ cloned_entity = job_utils.clone_model(entity) if (cloned_entity.commit_type not in base_models.VersionedModel.COMMIT_TYPE_CHOICES): yield base_validation_errors.InvalidCommitTypeError(cloned_entity)
def test_validate_commit_type(self): invalid_commit_type_model = base_models.BaseCommitLogEntryModel( id='123', created_on=self.YEAR_AGO, last_updated=self.NOW, commit_type='invalid-type', user_id='', post_commit_status='', commit_cmds=[]) output = (self.pipeline | beam.Create([invalid_commit_type_model]) | beam.ParDo(base_validation.ValidateCommitType())) self.assert_pcoll_equal(output, [ base_validation_errors.InvalidCommitTypeError( invalid_commit_type_model), ])