def test_collection_change_object_with_invalid_collection_property(
            self) -> None:
        invalid_commit_cmd_model = (
            collection_models.CollectionSnapshotMetadataModel(
                id='123',
                committer_id='committer_id',
                commit_type='create',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                commit_cmds=[{
                    'cmd': 'edit_collection_property',
                    'property_name': 'invalid',
                    'old_value': 'old_value',
                    'new_value': 'new_value',
                }]))

        output = (self.pipeline
                  | beam.Create([invalid_commit_cmd_model])
                  | beam.ParDo(collection_validation.
                               ValidateCollectionSnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, {
                    'cmd': 'edit_collection_property',
                    'property_name': 'invalid',
                    'old_value': 'old_value',
                    'new_value': 'new_value',
                }, 'Value for property_name in cmd edit_collection_property: '
                'invalid is not allowed')
        ])
    def test_collection_change_object_with_extra_attribute_in_cmd(
            self) -> None:
        invalid_commit_cmd_model = (
            collection_models.CollectionSnapshotMetadataModel(
                id='123',
                committer_id='committer_id',
                commit_type='create',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                commit_cmds=[{
                    'cmd': 'edit_collection_node_property',
                    'exploration_id': 'exploration_id',
                    'property_name': 'category',
                    'old_value': 'old_value',
                    'new_value': 'new_value',
                    'invalid': 'invalid'
                }]))

        output = (self.pipeline
                  | beam.Create([invalid_commit_cmd_model])
                  | beam.ParDo(collection_validation.
                               ValidateCollectionSnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, {
                    'cmd': 'edit_collection_node_property',
                    'exploration_id': 'exploration_id',
                    'property_name': 'category',
                    'old_value': 'old_value',
                    'new_value': 'new_value',
                    'invalid': 'invalid'
                }, 'The following extra attributes are present: invalid')
        ])
    def test_validate_change_domain_implemented(self) -> None:
        invalid_commit_cmd_model = (
            collection_models.CollectionSnapshotMetadataModel(
                id='model_id-1',
                committer_id='committer_id',
                commit_type='delete',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                commit_cmds=[{
                    'cmd':
                    base_models.VersionedModel.CMD_DELETE_COMMIT
                }]))

        output = (self.pipeline
                  | beam.Create([invalid_commit_cmd_model])
                  | beam.ParDo(collection_validation.
                               ValidateCollectionSnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [])
    def test_collection_change_object_with_missing_cmd(self) -> None:
        invalid_commit_cmd_model = (
            collection_models.CollectionSnapshotMetadataModel(
                id='123',
                committer_id='committer_id',
                commit_type='create',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                commit_cmds=[{
                    'invalid': 'data'
                }]))

        output = (self.pipeline
                  | beam.Create([invalid_commit_cmd_model])
                  | beam.ParDo(collection_validation.
                               ValidateCollectionSnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, {'invalid': 'data'},
                'Missing cmd key in change dict')
        ])