def test_model_invalid_id_error(self): 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.message, 'InvalidCommitTypeError in BaseCommitLogEntryModel(id=\'123\'): ' 'Commit type invalid-type is not allowed')
def process(self, input_model): """Function that defines how to process each element in a pipeline of models. Args: input_model: datastore_services.Model. Entity to validate. Yields: ModelCommitTypeError. Error for commit_type validation. """ model = job_utils.clone_model(input_model) if (model.commit_type not in base_models.VersionedModel.COMMIT_TYPE_CHOICES): yield base_validation_errors.InvalidCommitTypeError(model)
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), ])