def test_story_change_object_with_extra_attribute_in_cmd(self) -> 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(output, [ base_validation_errors.CommitCmdsValidateError( 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') ])
def test_story_change_object_with_invalid_story_contents_property( self) -> 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(output, [ base_validation_errors.CommitCmdsValidateError( invalid_commit_cmd_model, commit_dict, 'Value for property_name in cmd ' 'update_story_contents_property: invalid is not allowed') ])
def test_validate_change_domain_implemented(self) -> 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, [])
def test_story_change_object_with_invalid_cmd(self) -> 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(output, [ base_validation_errors.CommitCmdsValidateError( invalid_commit_cmd_model, {'invalid': 'data'}, 'Missing cmd key in change dict') ])
def test_story_change_object_with_missing_attribute_in_cmd(self) -> 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(output, [ base_validation_errors.CommitCmdsValidateError( invalid_commit_cmd_model, commit_dict, 'The following required attributes are missing: ' 'new_value, old_value') ])