예제 #1
0
    def test_skill_change_object_with_missing_attribute_in_cmd(self):
        # type: () -> None
        commit_dict = {
            'cmd': 'update_skill_property',
            'property_name': 'name',
        }
        invalid_commit_cmd_model = skill_models.SkillSnapshotMetadataModel(
            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(
                skill_validation.ValidateSkillSnapshotMetadataModel())
        )

        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')
            ])
예제 #2
0
    def test_exploration_rights_change_object_with_missing_attribute_in_cmd(
            self):
        invalid_commit_cmd_model = (
            exp_models.ExplorationRightsSnapshotMetadataModel(
                id='model_id-1',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                committer_id='committer_id',
                commit_type='create',
                commit_cmds=[{
                    'cmd': 'change_role',
                    'assignee_id': 'assignee_id',
                }]))

        output = (self.pipeline
                  | beam.Create([invalid_commit_cmd_model])
                  |
                  beam.ParDo(exp_validation.
                             ValidateExplorationRightsSnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, {
                    'cmd': 'change_role',
                    'assignee_id': 'assignee_id',
                }, 'The following required attributes are missing: '
                'new_role, old_role')
        ])
예제 #3
0
    def test_exploration_rights_change_object_with_invalid_status(self):
        invalid_commit_cmd_model = (
            exp_models.ExplorationRightsSnapshotMetadataModel(
                id='model_id-1',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                committer_id='committer_id',
                commit_type='create',
                commit_cmds=[{
                    'cmd': 'change_exploration_status',
                    'old_status': rights_domain.ACTIVITY_STATUS_PRIVATE,
                    'new_status': 'invalid'
                }]))

        output = (self.pipeline
                  | beam.Create([invalid_commit_cmd_model])
                  |
                  beam.ParDo(exp_validation.
                             ValidateExplorationRightsSnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, {
                    'cmd': 'change_exploration_status',
                    'old_status': rights_domain.ACTIVITY_STATUS_PRIVATE,
                    'new_status': 'invalid'
                }, 'Value for new_status in cmd change_exploration_status: '
                'invalid is not allowed')
        ])
예제 #4
0
    def test_subtopic_page_change_object_with_missing_attribute_in_cmd(
            self) -> None:
        invalid_commit_cmd_model = (
            subtopic_models.SubtopicPageSnapshotMetadataModel(
                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',
                    'property_name': '<p>page_contents_html</p>',
                    'subtopic_id': 'subtopic_id'
                }]))

        output = (self.pipeline
                  | beam.Create([invalid_commit_cmd_model])
                  | beam.ParDo(subtopic_validation.
                               ValidateSubtopicPageSnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, {
                    'cmd': 'update_subtopic_page_property',
                    'property_name': '<p>page_contents_html</p>',
                    'subtopic_id': 'subtopic_id'
                }, 'The following required attributes are missing: '
                'new_value, old_value')
        ])
예제 #5
0
    def test_subtopic_page_change_object_with_invalid_subtopic_page_property(
            self) -> None:
        invalid_commit_cmd_model = (
            subtopic_models.SubtopicPageSnapshotMetadataModel(
                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(subtopic_validation.
                               ValidateSubtopicPageSnapshotMetadataModel()))

        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')
        ])
예제 #6
0
    def test_param_change_object_missing_attribute_in_cmd_raises_exception(
            self):
        invalid_commit_cmd_model = (
            config_models.PlatformParameterSnapshotMetadataModel(
                id='model_id-1',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                committer_id='committer_id',
                commit_type='create',
                commit_cmds_user_ids=[
                    'commit_cmds_user_1_id', 'commit_cmds_user_2_id'],
                content_user_ids=['content_user_1_id', 'content_user_2_id'],
                commit_cmds=[{'cmd': self.CMD_EDIT_RULES}])
        )

        output = (
            self.pipeline
            | beam.Create([invalid_commit_cmd_model])
            | beam.ParDo(
                config_validation.ValidatePlatformParameterCommitCmdsSchema())
        )

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model,
                {'cmd': self.CMD_EDIT_RULES},
                'The following required attributes are missing: new_rules')
        ])
예제 #7
0
    def test_collection_change_object_with_extra_attribute_in_cmd(self):
        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')
        ])
예제 #8
0
    def test_param_change_object_with_extra_attribute_in_cmd_raises_exception(
            self):
        commit_dict = {
            'cmd': self.CMD_EDIT_RULES,
            'new_rules': [],
            'invalid': 'invalid'
        }
        invalid_commit_cmd_model = (
            config_models.PlatformParameterSnapshotMetadataModel(
                id='model_id-1',
                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(config_validation.
                             ValidatePlatformParameterSnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, commit_dict,
                'The following extra attributes are present: invalid')
        ])
    def test_collection_change_object_with_invalid_cmd(self):
        invalid_commit_cmd_model = (
            collection_models.CollectionCommitLogEntryModel(
                id='123',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                commit_type='test-type',
                user_id='',
                collection_id='123',
                post_commit_status='private',
                commit_cmds=[{
                    'cmd': 'invalid'
                }]))

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

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, {'cmd': 'invalid'},
                'Command invalid is not allowed')
        ])
예제 #10
0
    def test_skill_change_object_with_extra_attribute_in_cmd(self) -> None:
        commit_dict = {
            'cmd':
            'add_skill_misconception',
            # Key new_misconception_dict stores a string because dict
            # keeps on rearranging themselves so tests are not passing.
            'new_misconception_dict':
            '{u\'id\': 0, u\'notes\': '
            'u\'<p>notes</p>\', u\'feedback\': '
            'u\'<p>default_feedback</p>\', '
            'u\'name\': u\'name\'}',
            'invalid':
            'invalid'
        }
        invalid_commit_cmd_model = skill_models.SkillSnapshotMetadataModel(
            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(
                      skill_validation.ValidateSkillSnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, commit_dict,
                'The following extra attributes are present: invalid')
        ])
예제 #11
0
    def test_skill_change_object_with_invalid_skill_misconceptions(
            self) -> None:
        commit_dict = {
            'cmd': 'update_skill_misconceptions_property',
            'misconception_id': 'id',
            'property_name': 'invalid',
            'old_value': 'old_value',
            'new_value': 'new_value',
        }
        invalid_commit_cmd_model = skill_models.SkillSnapshotMetadataModel(
            id='123',
            created_on=self.YEAR_AGO,
            last_updated=self.NOW,
            committer_id='committer-id',
            commit_type='create',
            commit_cmds_user_ids=[
                'commit_cmds_user_1_id', 'commit_cmds_user_2_id'
            ],
            content_user_ids=['content_user_1_id', 'content_user_2_id'],
            commit_cmds=[commit_dict])

        output = (self.pipeline
                  | beam.Create([invalid_commit_cmd_model])
                  | beam.ParDo(
                      skill_validation.ValidateSkillSnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, commit_dict,
                'Value for property_name in cmd '
                'update_skill_misconceptions_property: invalid is not '
                'allowed')
        ])
예제 #12
0
    def test_collection_rights_change_object_with_invalid_cmd(self):
        commit_dict = {'cmd': 'invalid'}
        invalid_commit_cmd_model = (
            collection_models.CollectionRightsSnapshotMetadataModel(
                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(
                collection_validation
                .ValidateCollectionRightsSnapshotMetadataModel())
        )

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model,
                commit_dict,
                'Command invalid is not allowed')
        ])
예제 #13
0
    def test_subtopic_page_change_object_with_invalid_cmd(self):
        # type: () -> None
        invalid_commit_cmd_model = (
            subtopic_models.SubtopicPageSnapshotMetadataModel(
                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(
                subtopic_validation.ValidateSubtopicPageSnapshotMetadataModel())
        )

        self.assert_pcoll_equal( # type: ignore[no-untyped-call]
            output, [
                base_validation_errors.CommitCmdsValidateError( # type: ignore[no-untyped-call]
                    invalid_commit_cmd_model,
                    {'cmd': 'invalid'},
                    'Command invalid is not allowed')
            ])
예제 #14
0
    def test_change_dict_with_extra_attributes_in_cmd(self):
        invalid_commit_cmd_model = (
            question_models.QuestionSnapshotMetadataModel(
                id='model_id-1',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                committer_id='commiter-id',
                commit_type='create',
                commit_cmds=[{
                    'cmd': 'create_new',
                    'invalid': 'invalid'
                }]))

        output = (
            self.pipeline
            | beam.Create([invalid_commit_cmd_model])
            | beam.ParDo(
                question_validation.ValidateQuestionSnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, {
                    'cmd': 'create_new',
                    'invalid': 'invalid'
                }, 'The following extra attributes are present: invalid')
        ])
예제 #15
0
    def test_config_property_change_object_with_extra_attribute_in_cmd(self):
        invalid_commit_cmd_model = (
            config_models.ConfigPropertySnapshotMetadataModel(
                id='model_id-1',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                committer_id='committer_id',
                commit_type='create',
                commit_cmds_user_ids=[
                    'commit_cmds_user_1_id', 'commit_cmds_user_2_id'],
                content_user_ids=['content_user_1_id', 'content_user_2_id'],
                commit_cmds=[{
                    'cmd': 'change_property_value',
                    'new_value': 'new_value',
                    'invalid': 'invalid'
                }])
        )

        output = (
            self.pipeline
            | beam.Create([invalid_commit_cmd_model])
            | beam.ParDo(
                config_validation.ValidateConfigCommitCmdsSchema())
        )

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model,
                {
                    'cmd': 'change_property_value',
                    'new_value': 'new_value',
                    'invalid': 'invalid'
                },
                'The following extra attributes are present: invalid')
        ])
예제 #16
0
    def process(self, input_model):
        """Validates schema of commit commands in commit_cmds dict.

        Args:
            input_model: datastore_services.Model. Entity to validate.

        Yields:
            CommitCmdsNoneError. Error for invalid commit cmds id.
            CommitCmdsValidateError. Error for wrong commit cmds.
        """
        change_domain_object = self._get_change_domain_class(input_model)
        if change_domain_object is None:
            # This is for cases where id of the entity is invalid
            # and no commit command domain object is found for the entity.
            # For example, if a CollectionCommitLogEntryModel does
            # not have id starting with collection/rights, there is
            # no commit command domain object defined for this model.
            yield base_validation_errors.CommitCmdsNoneError(input_model)
            return
        for commit_cmd_dict in input_model.commit_cmds:
            if not commit_cmd_dict:
                continue
            try:
                change_domain_object(commit_cmd_dict)
            except Exception as e:
                yield base_validation_errors.CommitCmdsValidateError(
                    input_model, commit_cmd_dict, e)
예제 #17
0
    def test_param_change_object_with_invalid_cmd_raises_exception(self):
        invalid_commit_cmd_model = (
            config_models.PlatformParameterSnapshotMetadataModel(
                id='model_id-1',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                committer_id='committer_id',
                commit_type='create',
                commit_cmds_user_ids=[
                    'commit_cmds_user_1_id', 'commit_cmds_user_2_id'],
                content_user_ids=['content_user_1_id', 'content_user_2_id'],
                commit_cmds=[{'cmd': 'invalid'}])
        )

        output = (
            self.pipeline
            | beam.Create([invalid_commit_cmd_model])
            | beam.ParDo(
                config_validation.ValidatePlatformParameterCommitCmdsSchema())
        )

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model,
                {'cmd': 'invalid'},
                'Command invalid is not allowed')
        ])
예제 #18
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')
        ])
예제 #19
0
    def test_config_property_change_object_with_missing_cmd(self):
        invalid_commit_cmd_model = (
            config_models.ConfigPropertySnapshotMetadataModel(
                id='model_id-1',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                committer_id='committer_id',
                commit_type='create',
                commit_cmds_user_ids=[
                    'commit_cmds_user_1_id', 'commit_cmds_user_2_id'],
                content_user_ids=['content_user_1_id', 'content_user_2_id'],
                commit_cmds=[{'invalid': 'data'}])
        )

        output = (
            self.pipeline
            | beam.Create([invalid_commit_cmd_model])
            | beam.ParDo(
                config_validation.ValidateConfigCommitCmdsSchema())
        )

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model,
                {'invalid': 'data'},
                'Missing cmd key in change dict')
        ])
예제 #20
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')
        ])
예제 #21
0
    def test_collection_rights_change_object_with_invalid_role(self):
        commit_dict = {
            'cmd': 'change_role',
            'assignee_id': 'assignee_id',
            'old_role': rights_domain.ROLE_OWNER,
            'new_role': 'invalid',
        }
        invalid_commit_cmd_model = (
            collection_models.CollectionRightsSnapshotMetadataModel(
                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(collection_validation.
                             ValidateCollectionRightsSnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, commit_dict,
                'Value for new_role in cmd change_role: '
                'invalid is not allowed')
        ])
예제 #22
0
    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')
        ])
예제 #23
0
    def test_subtopic_page_change_object_with_extra_attribute_in_cmd(
            self) -> None:
        invalid_commit_cmd_model = (
            subtopic_models.SubtopicPageSnapshotMetadataModel(
                id='123',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                committer_id='committer_id',
                commit_type='create',
                commit_cmds=[{
                    'cmd': 'create_new',
                    'topic_id': 'topic_id',
                    'subtopic_id': 'subtopic_id',
                    'invalid': 'invalid'
                }]))

        output = (self.pipeline
                  | beam.Create([invalid_commit_cmd_model])
                  | beam.ParDo(subtopic_validation.
                               ValidateSubtopicPageSnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, {
                    'cmd': 'create_new',
                    'topic_id': 'topic_id',
                    'subtopic_id': 'subtopic_id',
                    'invalid': 'invalid'
                }, 'The following extra attributes are present: invalid')
        ])
예제 #24
0
    def test_story_change_object_with_invalid_story_property(self) -> None:
        commit_dict = {
            'cmd': 'update_story_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_property: '
                'invalid is not allowed')
        ])
예제 #25
0
    def test_validate_exp_model_object_with_extra_attribute_in_cmd(self):
        invalid_commit_cmd_model = exp_models.ExplorationSnapshotMetadataModel(
            id='model_id-1',
            created_on=self.YEAR_AGO,
            last_updated=self.NOW,
            committer_id='committer_id',
            commit_type='create',
            commit_cmds_user_ids=[
                'commit_cmds_user_1_id', 'commit_cmds_user_2_id'
            ],
            content_user_ids=['content_user_1_id', 'content_user_2_id'],
            commit_cmds=[{
                'cmd': 'rename_state',
                'old_state_name': 'old_state_name',
                'new_state_name': 'new_state_name',
                'invalid': 'invalid'
            }])

        output = (
            self.pipeline
            | beam.Create([invalid_commit_cmd_model])
            | beam.ParDo(
                exp_validation.ValidateExplorationSnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, {
                    'cmd': 'rename_state',
                    'old_state_name': 'old_state_name',
                    'new_state_name': 'new_state_name',
                    'invalid': 'invalid'
                }, 'The following extra attributes are present: invalid')
        ])
예제 #26
0
    def test_change_dict_with_missing_attributes_in_cmd(self):
        invalid_commit_cmd_model = (
            question_models.QuestionSnapshotMetadataModel(
                id='model_id-1',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                committer_id='committer_id',
                commit_type='create',
                commit_cmds_user_ids=[
                    'commit_cmds_user_1_id', 'commit_cmds_user_2_id'
                ],
                content_user_ids=['content_user_1_id', 'content_user_2_id'],
                commit_cmds=[{
                    'cmd': 'update_question_property',
                    'property_name': 'question_state_data',
                    'old_value': 'old_value'
                }]))

        output = (self.pipeline
                  | beam.Create([invalid_commit_cmd_model])
                  | beam.ParDo(
                      question_validation.ValidateQuestionCommitCmdsSchema()))

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, {
                    'cmd': 'update_question_property',
                    'property_name': 'question_state_data',
                    'old_value': 'old_value'
                }, 'The following required attributes are missing: new_value')
        ])
예제 #27
0
    def test_exploration_rights_change_object_with_extra_attribute_in_cmd(
            self):
        invalid_commit_cmd_model = (
            exp_models.ExplorationRightsSnapshotMetadataModel(
                id='model_id-1',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                committer_id='committer_id',
                commit_type='create',
                commit_cmds=[{
                    'cmd': 'change_private_viewability',
                    'old_viewable_if_private': 'old_viewable_if_private',
                    'new_viewable_if_private': 'new_viewable_if_private',
                    'invalid': 'invalid'
                }]))

        output = (self.pipeline
                  | beam.Create([invalid_commit_cmd_model])
                  |
                  beam.ParDo(exp_validation.
                             ValidateExplorationRightsSnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, {
                    'cmd': 'change_private_viewability',
                    'old_viewable_if_private': 'old_viewable_if_private',
                    'new_viewable_if_private': 'new_viewable_if_private',
                    'invalid': 'invalid'
                }, 'The following extra attributes are present: invalid')
        ])
예제 #28
0
    def test_update_question_property_with_wrong_property_name(self):
        invalid_commit_cmd_model = (
            question_models.QuestionSnapshotMetadataModel(
                id='model_id-1',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                committer_id='committer_id',
                commit_type='create',
                commit_cmds_user_ids=[
                    'commit_cmds_user_1_id', 'commit_cmds_user_2_id'
                ],
                content_user_ids=['content_user_1_id', 'content_user_2_id'],
                commit_cmds=[{
                    'cmd': 'update_question_property',
                    'property_name': 'wrong',
                    'new_value': 'new_value',
                    'old_value': 'old_value'
                }]))

        output = (self.pipeline
                  | beam.Create([invalid_commit_cmd_model])
                  | beam.ParDo(
                      question_validation.ValidateQuestionCommitCmdsSchema()))

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, {
                    'cmd': 'update_question_property',
                    'property_name': 'wrong',
                    'new_value': 'new_value',
                    'old_value': 'old_value'
                }, 'Value for property_name in cmd update_question_property: '
                'wrong is not allowed')
        ])
예제 #29
0
    def test_validate_exp_model_object_with_invalid_cmd(self):
        invalid_commit_cmd_model = exp_models.ExplorationSnapshotMetadataModel(
            id='model_id-1',
            created_on=self.YEAR_AGO,
            last_updated=self.NOW,
            committer_id='committer_id',
            commit_type='create',
            commit_cmds_user_ids=[
                'commit_cmds_user_1_id', 'commit_cmds_user_2_id'
            ],
            content_user_ids=['content_user_1_id', 'content_user_2_id'],
            commit_cmds=[{
                'cmd': 'invalid'
            }])

        output = (
            self.pipeline
            | beam.Create([invalid_commit_cmd_model])
            | beam.ParDo(
                exp_validation.ValidateExplorationSnapshotMetadataModel()))

        self.assert_pcoll_equal(output, [
            base_validation_errors.CommitCmdsValidateError(
                invalid_commit_cmd_model, {'cmd': 'invalid'},
                'Command invalid is not allowed')
        ])
예제 #30
0
    def test_story_change_object_with_invalid_story_node_property(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='edit',
            commit_cmds=[{
                'cmd': 'update_story_node_property',
                'node_id': 'node_id',
                'property_name': 'invalid',
                'old_value': 'old_value',
                'new_value': 'new_value',
            }]
        )

        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,
                    '{u\'node_id\': u\'node_id\', u\'new_value\': '
                    'u\'new_value\', u\'cmd\': '
                    'u\'update_story_node_property\', u\'old_value\': '
                    'u\'old_value\', u\'property_name\': u\'invalid\'}',
                    'Value for property_name in cmd '
                    'update_story_node_property: invalid is not allowed')
            ])