示例#1
0
    def test_story_change_object_with_invalid_cmd(self):
        # type: () -> None
        invalid_commit_cmd_model = story_models.StorySnapshotMetadataModel(
            id='123',
            created_on=self.YEAR_AGO,
            last_updated=self.NOW,
            committer_id='committer_id',
            commit_type='create',
            commit_cmds=[{
                'invalid': 'data'
            }])

        output = (self.pipeline
                  | beam.Create([invalid_commit_cmd_model])
                  | beam.ParDo(
                      story_validation.ValidateStorySnapshotMetadataModel()))

        self.assert_pcoll_equal(  # type: ignore[no-untyped-call]
            output,
            [
                base_validation_errors.
                CommitCmdsValidateError(  # type: ignore[no-untyped-call]
                    invalid_commit_cmd_model, {'invalid': 'data'},
                    'Missing cmd key in change dict')
            ])
示例#2
0
    def test_story_change_object_with_extra_attribute_in_cmd(self):
        # type: () -> None
        invalid_commit_cmd_model = story_models.StorySnapshotMetadataModel(
            id='123',
            created_on=self.YEAR_AGO,
            last_updated=self.NOW,
            committer_id='committer_id',
            commit_type='create',
            commit_cmds=[{
                'cmd': 'add_story_node',
                'node_id': 'node_id',
                'invalid': 'invalid'
            }])

        output = (self.pipeline
                  | beam.Create([invalid_commit_cmd_model])
                  | beam.ParDo(
                      story_validation.ValidateStorySnapshotMetadataModel()))

        self.assert_pcoll_equal( # type: ignore[no-untyped-call]
            output, [
                base_validation_errors.CommitCmdsValidateError( # type: ignore[no-untyped-call]
                    invalid_commit_cmd_model,
                    {
                        'cmd': 'add_story_node',
                        'node_id': 'node_id',
                        'invalid': 'invalid'
                    },
                    'The following required attributes are missing: title, '
                    'The following extra attributes are present: invalid')
            ])
示例#3
0
    def test_story_change_object_with_invalid_story_contents_property(self):
        # type: () -> None
        commit_dict = {
            'cmd': 'update_story_contents_property',
            'property_name': 'invalid',
            'old_value': 'old_value',
            'new_value': 'new_value',
        }
        invalid_commit_cmd_model = story_models.StorySnapshotMetadataModel(
            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(
                      story_validation.ValidateStorySnapshotMetadataModel()))

        self.assert_pcoll_equal(  # type: ignore[no-untyped-call]
            output,
            [
                base_validation_errors.
                CommitCmdsValidateError(  # type: ignore[no-untyped-call]
                    invalid_commit_cmd_model, commit_dict,
                    'Value for property_name in cmd '
                    'update_story_contents_property: invalid is not allowed')
            ])
示例#4
0
    def test_story_change_object_with_missing_attribute_in_cmd(self):
        # type: () -> None
        commit_dict = {
            'cmd': 'update_story_property',
            'property_name': 'title',
        }
        invalid_commit_cmd_model = story_models.StorySnapshotMetadataModel(
            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(
                      story_validation.ValidateStorySnapshotMetadataModel()))

        self.assert_pcoll_equal(  # type: ignore[no-untyped-call]
            output,
            [
                base_validation_errors.
                CommitCmdsValidateError(  # type: ignore[no-untyped-call]
                    invalid_commit_cmd_model, commit_dict,
                    'The following required attributes are missing: '
                    'new_value, old_value')
            ])
示例#5
0
    def test_validate_change_domain_implemented(self):
        # type: () -> None
        valid_commit_cmd_model = story_models.StorySnapshotMetadataModel(
            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(
                      story_validation.ValidateStorySnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [])  # type: ignore[no-untyped-call]