Ejemplo n.º 1
0
    def test_update_question_property_with_wrong_property_name(self) -> None:
        commit_dict = {
            'cmd': 'update_question_property',
            'property_name': 'wrong',
            'new_value': 'new_value',
            'old_value': 'old_value'
        }
        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='edit',
                commit_cmds=[commit_dict])
        )

        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,
                commit_dict,
                'Value for property_name in cmd update_question_property: '
                'wrong is not allowed')
        ])
Ejemplo n.º 2
0
    def test_change_dict_with_missing_attributes_in_cmd(self) -> None:
        commit_dict = {
            'cmd': 'update_question_property',
            'property_name': 'question_state_data',
            'old_value': 'old_value'
        }
        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='edit',
                commit_cmds=[commit_dict])
        )

        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,
                commit_dict,
                'The following required attributes are missing: new_value')
        ])
    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')
        ])
Ejemplo n.º 4
0
    def test_validate_change_domain_implemented(self) -> None:
        invalid_commit_cmd_model = (
            question_models.QuestionSnapshotMetadataModel(
                id='123',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                committer_id='commiter-id',
                commit_type='delete',
                commit_cmds=[{
                    'cmd': base_models.VersionedModel.CMD_DELETE_COMMIT}])
        )

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

        self.assert_pcoll_equal(output, [])
    def test_change_dict_with_invalid_cmd(self):
        invalid_commit_cmd_model = (
            question_models.QuestionSnapshotMetadataModel(
                id='123',
                created_on=self.YEAR_AGO,
                last_updated=self.NOW,
                committer_id='commiter-id',
                commit_type='delete',
                commit_cmds=[{
                    'cmd': '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': 'invalid'},
                'Command invalid is not allowed')
        ])