def test_message_for_public_post_commit_status(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='public', post_commit_is_private=True, commit_cmds=[]) error = base_validation_errors.InvalidPrivateCommitStatusError(model) self.assertEqual( error.stderr, 'InvalidPrivateCommitStatusError in ' 'BaseCommitLogEntryModel(id="123"): post_commit_status=public ' 'but post_commit_is_private=True')
def test_validate_post_commit_is_private_when_status_is_private(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='private', post_commit_is_private=False, commit_cmds=[]) output = (self.pipeline | beam.Create([invalid_commit_status]) | beam.ParDo(base_validation.ValidatePostCommitIsPrivate())) self.assert_pcoll_equal(output, [ base_validation_errors.InvalidPrivateCommitStatusError( invalid_commit_status), ])
def process(self, entity): """Function validates that post_commit_is_private is true iff post_commit_status is private Args: entity: base_models.BaseCommitLogEntryModel. Entity to validate. Yields: InvalidPrivateCommitStatusError. Error for private commit_type validation. """ cloned_entity = job_utils.clone_model(entity) expected_post_commit_is_private = (cloned_entity.post_commit_status == feconf.POST_COMMIT_STATUS_PRIVATE) if (cloned_entity.post_commit_is_private != expected_post_commit_is_private): yield base_validation_errors.InvalidPrivateCommitStatusError( cloned_entity)