def test_parse_multipart_body_existing_schema(self, mocker, model_property_factory):
        from openapi_python_client.parser.openapi import Endpoint, Schemas
        from openapi_python_client.parser.properties import Class

        class_info = Class(name="class_name", module_name="module_name")
        prop_before = model_property_factory(class_info=class_info, is_multipart_body=False)
        schemas_before = Schemas(classes_by_name={class_info.name: prop_before})

        schema = mocker.MagicMock()
        body = oai.RequestBody.construct(
            content={"multipart/form-data": oai.MediaType.construct(media_type_schema=schema)}
        )
        config = MagicMock()
        property_from_data = mocker.patch(
            f"{MODULE_NAME}.property_from_data", return_value=(prop_before, schemas_before)
        )

        result = Endpoint.parse_multipart_body(body=body, schemas=schemas_before, parent_name="parent", config=config)

        property_from_data.assert_called_once_with(
            name="multipart_data",
            required=True,
            data=schema,
            schemas=schemas_before,
            parent_name="parent",
            config=config,
        )
        prop_after = model_property_factory(class_info=class_info, is_multipart_body=True)
        schemas_after = Schemas(classes_by_name={class_info.name: prop_after})
        assert result == (prop_after, schemas_after)
Пример #2
0
    def test_parse_multipart_body_no_data(self):
        body = oai.RequestBody.construct(content={})

        from openapi_python_client.parser.openapi import Endpoint

        result = Endpoint.parse_multipart_body(body)

        assert result is None
    def test_parse_multipart_body_no_data(self):
        from openapi_python_client.parser.openapi import Endpoint, Schemas

        body = oai.RequestBody.construct(content={})
        schemas = Schemas()

        prop, schemas = Endpoint.parse_multipart_body(
            body=body, schemas=schemas, parent_name="parent", config=MagicMock()
        )

        assert prop is None
Пример #4
0
    def test_parse_multipart_body(self, mocker):
        ref = mocker.MagicMock()
        body = oai.RequestBody.construct(
            content={"multipart/form-data": oai.MediaType.construct(media_type_schema=oai.Reference.construct(ref=ref))}
        )
        from_string = mocker.patch(f"{MODULE_NAME}.Class.from_string")
        config = MagicMock()

        from openapi_python_client.parser.openapi import Endpoint

        result = Endpoint.parse_multipart_body(body=body, config=config)

        from_string.assert_called_once_with(string=ref, config=config)
        assert result == from_string.return_value
Пример #5
0
    def test_parse_multipart_body(self, mocker):
        ref = mocker.MagicMock()
        body = oai.RequestBody.construct(
            content={
                "multipart/form-data":
                oai.MediaType.construct(
                    media_type_schema=oai.Reference.construct(ref=ref))
            })
        from_ref = mocker.patch(f"{MODULE_NAME}.Reference.from_ref")

        from openapi_python_client.parser.openapi import Endpoint

        result = Endpoint.parse_multipart_body(body)

        from_ref.assert_called_once_with(ref)
        assert result == from_ref()