Ejemplo n.º 1
0
    def test_topic_rights_change_object_with_invalid_role(self):
        commit_dict = {
            'cmd': 'change_role',
            'assignee_id': 'assignee_id',
            'old_role': 'invalid',
            'new_role': topic_domain.ROLE_MANAGER
        }
        invalid_commit_cmd_model = (
            topic_models.TopicRightsSnapshotMetadataModel(
                id='123',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                committer_id='committer_id',
                commit_type='edit',
                commit_cmds=[commit_dict])
        )

        output = (
            self.pipeline
            | beam.Create([invalid_commit_cmd_model])
            | beam.ParDo(
                topic_validation.ValidateTopicRightsSnapshotMetadataModel())
        )

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model,
                commit_dict,
                'Value for old_role in cmd change_role: '
                'invalid is not allowed')
        ])
Ejemplo n.º 2
0
    def test_topic_rights_change_object_with_missing_attribute_in_cmd(self):
        commit_dict = {
            'cmd': 'change_role',
            'assignee_id': 'assignee_id',
        }
        invalid_commit_cmd_model = (
            topic_models.TopicRightsSnapshotMetadataModel(
                id='123',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                committer_id='committer_id',
                commit_type='edit',
                commit_cmds=[commit_dict])
        )

        output = (
            self.pipeline
            | beam.Create([invalid_commit_cmd_model])
            | beam.ParDo(
                topic_validation.ValidateTopicRightsSnapshotMetadataModel())
        )

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model,
                commit_dict,
                'The following required attributes are missing: '
                'new_role, old_role')
        ])
Ejemplo n.º 3
0
    def test_topic_rights_change_object_with_extra_attribute_in_cmd(self):
        commit_dict = {
            'cmd': 'publish_topic',
            'invalid': 'invalid'
        }
        invalid_commit_cmd_model = (
            topic_models.TopicRightsSnapshotMetadataModel(
                id='123',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                committer_id='committer_id',
                commit_type='create',
                commit_cmds=[commit_dict])
        )

        output = (
            self.pipeline
            | beam.Create([invalid_commit_cmd_model])
            | beam.ParDo(
                topic_validation.ValidateTopicRightsSnapshotMetadataModel())
        )

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model,
                commit_dict,
                'The following extra attributes are present: invalid')
        ])
Ejemplo n.º 4
0
    def test_topic_change_rights_object_with_invalid_cmd(self):
        invalid_commit_cmd_model = (
            topic_models.TopicRightsSnapshotMetadataModel(
                id='123',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                committer_id='committer_id',
                commit_type='delete',
                commit_cmds=[{'cmd': 'invalid'}])
        )

        output = (
            self.pipeline
            | beam.Create([invalid_commit_cmd_model])
            | beam.ParDo(
                topic_validation.ValidateTopicRightsSnapshotMetadataModel())
        )

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model,
                {'cmd': 'invalid'},
                'Command invalid is not allowed')
        ])