コード例 #1
0
    def test_topic_change_object_with_invalid_subtopic_page_property(self):
        invalid_commit_cmd_model = topic_models.TopicSnapshotMetadataModel(
            id='123',
            created_on=self.YEAR_AGO,
            last_updated=self.NOW,
            committer_id='committer_id',
            commit_type='edit',
            commit_cmds=[{
                'cmd': 'update_subtopic_page_property',
                'subtopic_id': 'subtopic_id',
                'property_name': 'invalid',
                'old_value': 'old_value',
                'new_value': 'new_value',
            }])

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

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, {
                    'cmd': 'update_subtopic_page_property',
                    'subtopic_id': 'subtopic_id',
                    'property_name': 'invalid',
                    'old_value': 'old_value',
                    'new_value': 'new_value',
                },
                'Value for property_name in cmd update_subtopic_page_property: '
                'invalid is not allowed')
        ])
コード例 #2
0
    def test_topic_change_object_with_missing_attribute_in_cmd(self):
        invalid_commit_cmd_model = topic_models.TopicSnapshotMetadataModel(
            id='123',
            created_on=self.YEAR_AGO,
            last_updated=self.NOW,
            committer_id='committer_id',
            commit_type='edit',
            commit_cmds=[{
                'cmd': 'update_topic_property',
                'property_name': 'name',
            }])

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

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, {
                    'cmd': 'update_topic_property',
                    'property_name': 'name',
                }, 'The following required attributes are missing: '
                'new_value, old_value')
        ])
コード例 #3
0
    def test_topic_change_object_with_extra_attribute_in_cmd(self):
        invalid_commit_cmd_model = topic_models.TopicSnapshotMetadataModel(
            id='123',
            created_on=self.YEAR_AGO,
            last_updated=self.NOW,
            committer_id='committer_id',
            commit_type='create',
            commit_cmds=[{
                'cmd': 'add_subtopic',
                'title': 'title',
                'subtopic_id': 'subtopic_id',
                'invalid': 'invalid'
            }])

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

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, {
                    'cmd': 'add_subtopic',
                    'title': 'title',
                    'subtopic_id': 'subtopic_id',
                    'invalid': 'invalid'
                }, 'The following extra attributes are present: invalid')
        ])
コード例 #4
0
    def test_validate_change_domain_implemented(self):
        valid_commit_cmd_model = topic_models.TopicSnapshotMetadataModel(
            id='123',
            created_on=self.YEAR_AGO,
            last_updated=self.NOW,
            committer_id='committer_id',
            commit_type='delete',
            commit_cmds=[{
                'cmd': base_models.VersionedModel.CMD_DELETE_COMMIT
            }])

        output = (self.pipeline
                  | beam.Create([valid_commit_cmd_model])
                  | beam.ParDo(
                      topic_validation.ValidateTopicSnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [])
コード例 #5
0
    def test_topic_change_object_with_invalid_cmd(self):
        invalid_commit_cmd_model = topic_models.TopicSnapshotMetadataModel(
            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.ValidateTopicSnapshotMetadataModel()))

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