def test_message_for_invalid_post_commit_status(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='invalid', post_commit_is_private=False, commit_cmds=[]) error = audit_errors.InvalidCommitStatusError(model) self.assertEqual( error.message, 'InvalidCommitStatusError in BaseCommitLogEntryModel(id=\'123\'): ' 'post_commit_status is invalid')
def process(self, input_model): """Function validates that post_commit_status is either public or private Args: input_model: base_models.BaseCommitLogEntryModel. Entity to validate. Yields: InvalidCommitStatusError. Error for commit_type validation. """ model = job_utils.clone_model(input_model) if model.post_commit_status not in [ feconf.POST_COMMIT_STATUS_PUBLIC, feconf.POST_COMMIT_STATUS_PRIVATE]: yield audit_errors.InvalidCommitStatusError(model)
def process(self, input_model): """Function validates that post_commit_is_private is true iff post_commit_status is private Args: input_model: base_models.BaseCommitLogEntryModel. Entity to validate. Yields: ModelInvalidCommitStatus. Error for commit_type validation. """ model = jobs_utils.clone_model(input_model) expected_post_commit_is_private = ( model.post_commit_status == feconf.POST_COMMIT_STATUS_PRIVATE) if model.post_commit_is_private != expected_post_commit_is_private: yield audit_errors.InvalidCommitStatusError(model)
def test_validate_post_commit_is_invalid(self): invalid_commit_status = base_models.BaseCommitLogEntryModel( id='123', created_on=self.YEAR_AGO, last_updated=self.NOW, commit_type='invalid-type', user_id='', post_commit_status='invalid', post_commit_is_private=False, commit_cmds=[]) output = (self.pipeline | beam.Create([invalid_commit_status]) | beam.ParDo(base_model_audits.ValidatePostCommitStatus())) self.assert_pcoll_equal(output, [ audit_errors.InvalidCommitStatusError(invalid_commit_status), ])