Exemple #1
0
    def test_unit__marshmallow_input_processor__ok__process_success(self):
        processor = MarshmallowInputProcessor()
        processor.schema = MySchema()

        tested_data = {
            'first_name': 'Alan',
            'last_name': 'Turing',
        }
        data = processor.process(tested_data)

        assert data == tested_data
Exemple #2
0
    def test_unit__marshmallow_input_processor__ok__completed_data(self):
        processor = MarshmallowInputProcessor()
        processor.schema = MySchema()

        tested_data = {
            'first_name': 'Alan',
        }

        data = processor.process(tested_data)
        assert {
            'first_name': 'Alan',
            'last_name': 'Doe',
        } == data
Exemple #3
0
    def test_unit__marshmallow_input_processor__error__validation_error_no_data_empty_string(
            self):  # nopep8
        processor = MarshmallowInputProcessor()
        processor.schema = MySchema()

        # Schema will not valid it because require first_name field
        tested_data = ''

        with pytest.raises(OutputValidationException):
            processor.process(tested_data)

        errors = processor.get_validation_error(tested_data)
        assert errors.details
        assert {'_schema': ['Invalid input type.']} == errors.details
Exemple #4
0
    def test_unit__marshmallow_input_processor__error__validation_error_no_data_none(
            self):  # nopep8
        processor = MarshmallowInputProcessor()
        processor.schema = MySchema()

        # Schema will not valid it because require first_name field
        tested_data = None

        with pytest.raises(OutputValidationException):
            processor.process(tested_data)

        errors = processor.get_validation_error(tested_data)
        assert errors.details
        assert 'first_name' in errors.details
Exemple #5
0
    def test_unit__marshmallow_input_processor__error__validation_error(self):
        processor = MarshmallowInputProcessor()
        processor.schema = MySchema()

        tested_data = {
            'last_name': 'Turing',
        }

        with pytest.raises(OutputValidationException):
            processor.process(tested_data)

        errors = processor.get_validation_error(tested_data)
        assert errors.error_details
        assert 'first_name' in errors.error_details
Exemple #6
0
    def input_forms(
        self,
        schema: typing.Any,
        processor: ProcessorInterface=None,
        context: ContextInterface=None,
        error_http_code: HTTPStatus = HTTPStatus.BAD_REQUEST,
        default_http_code: HTTPStatus = HTTPStatus.OK,
    ) -> typing.Callable[[typing.Callable[..., typing.Any]], typing.Any]:
        processor = processor or MarshmallowInputProcessor()
        processor.schema = schema
        context = context or self._context_getter

        decoration = InputBodyControllerWrapper(
            context=context,
            processor=processor,
            error_http_code=error_http_code,
            default_http_code=default_http_code,
        )

        def decorator(func):
            self._buffer.input_forms = InputFormsDescription(decoration)
            return decoration.get_wrapper(func)
        return decorator