def test_conflicting_properties_same_types(self, model_property_factory,
                                               string_property_factory):
        from openapi_python_client.parser.properties import Schemas
        from openapi_python_client.parser.properties.model_property import _process_properties

        data = oai.Schema.construct(allOf=[
            oai.Reference.construct(ref="#/First"),
            oai.Reference.construct(ref="#/Second")
        ])
        schemas = Schemas(
            classes_by_reference={
                "/First":
                model_property_factory(optional_properties=[
                    string_property_factory(default="abc")
                ]),
                "/Second":
                model_property_factory(
                    optional_properties=[string_property_factory()]),
            })

        result = _process_properties(data=data,
                                     schemas=schemas,
                                     class_name="",
                                     config=Config())

        assert isinstance(result, PropertyError)
    def test_direct_properties_non_ref(self, string_property_factory):
        from openapi_python_client.parser.properties import Schemas
        from openapi_python_client.parser.properties.model_property import _process_properties

        data = oai.Schema.construct(allOf=[
            oai.Schema.construct(
                required=["first"],
                properties={
                    "first": oai.Schema.construct(type="string"),
                    "second": oai.Schema.construct(type="string"),
                },
            )
        ])
        schemas = Schemas()

        result = _process_properties(data=data,
                                     schemas=schemas,
                                     class_name="",
                                     config=MagicMock())

        assert result.optional_props == [
            string_property_factory(name="second",
                                    required=False,
                                    nullable=False)
        ]
        assert result.required_props == [
            string_property_factory(name="first",
                                    required=True,
                                    nullable=False)
        ]
    def test_allof_enum_incompatible_type(self, model_property_factory,
                                          enum_property_factory,
                                          int_property_factory):
        from openapi_python_client.parser.properties import Schemas
        from openapi_python_client.parser.properties.model_property import _process_properties

        data = oai.Schema.construct(allOf=[
            oai.Reference.construct(ref="#/First"),
            oai.Reference.construct(ref="#/Second")
        ])
        enum_property = enum_property_factory(
            values={"foo": 1},
            value_type=str,
        )
        schemas = Schemas(
            classes_by_reference={
                "/First":
                model_property_factory(
                    optional_properties=[int_property_factory()]),
                "/Second":
                model_property_factory(optional_properties=[enum_property]),
            })

        result = _process_properties(data=data,
                                     schemas=schemas,
                                     class_name="",
                                     config=Config())
        assert isinstance(result, PropertyError)
    def test_allof_int_enums(self, model_property_factory,
                             enum_property_factory):
        from openapi_python_client.parser.properties import Schemas
        from openapi_python_client.parser.properties.model_property import _process_properties

        data = oai.Schema.construct(allOf=[
            oai.Reference.construct(ref="#/First"),
            oai.Reference.construct(ref="#/Second")
        ])
        enum_property1 = enum_property_factory(
            name="an_enum",
            values={
                "foo": 1,
                "bar": 2
            },
            value_type=int,
        )
        enum_property2 = enum_property_factory(
            name="an_enum",
            values={"foo": 1},
            value_type=int,
        )
        schemas = Schemas(
            classes_by_reference={
                "/First":
                model_property_factory(optional_properties=[enum_property1]),
                "/Second":
                model_property_factory(optional_properties=[enum_property2]),
            })

        result = _process_properties(data=data,
                                     schemas=schemas,
                                     class_name="",
                                     config=Config())
        assert result.required_props[0] == enum_property2
Beispiel #5
0
    def test_mixed_requirements(
        self, model_property_factory, first_nullable, second_nullable, first_required, second_required
    ):
        from openapi_python_client.parser.properties import Schemas
        from openapi_python_client.parser.properties.model_property import _process_properties

        data = oai.Schema.construct(
            allOf=[oai.Reference.construct(ref="#/First"), oai.Reference.construct(ref="#/Second")]
        )
        schemas = Schemas(
            classes_by_reference={
                "/First": model_property_factory(
                    optional_properties=[string_property(required=first_required, nullable=first_nullable)]
                ),
                "/Second": model_property_factory(
                    optional_properties=[string_property(required=second_required, nullable=second_nullable)]
                ),
            }
        )

        result = _process_properties(data=data, schemas=schemas, class_name="", config=MagicMock())

        nullable = first_nullable and second_nullable
        required = first_required or second_required
        expected_prop = string_property(
            nullable=nullable,
            required=required,
        )

        if nullable or not required:
            assert result.optional_props == [expected_prop]
        else:
            assert result.required_props == [expected_prop]
    def test_allof_string_enum_and_string(self, model_property_factory,
                                          enum_property_factory,
                                          string_property_factory):
        from openapi_python_client.parser.properties import Schemas
        from openapi_python_client.parser.properties.model_property import _process_properties

        data = oai.Schema.construct(allOf=[
            oai.Reference.construct(ref="#/First"),
            oai.Reference.construct(ref="#/Second")
        ])
        enum_property = enum_property_factory(
            required=False,
            nullable=True,
            values={"foo": "foo"},
        )
        schemas = Schemas(
            classes_by_reference={
                "/First":
                model_property_factory(optional_properties=[enum_property]),
                "/Second":
                model_property_factory(optional_properties=[
                    string_property_factory(required=False, nullable=True)
                ]),
            })

        result = _process_properties(data=data,
                                     schemas=schemas,
                                     class_name="",
                                     config=Config())
        assert result.optional_props[0] == enum_property
Beispiel #7
0
    def test_invalid_reference(self, model_property_factory):
        from openapi_python_client.parser.properties import Schemas
        from openapi_python_client.parser.properties.model_property import _process_properties

        data = oai.Schema.construct(allOf=[oai.Reference.construct(ref="ThisIsNotGood")])
        schemas = Schemas()

        result = _process_properties(data=data, schemas=schemas, class_name="", config=Config())

        assert isinstance(result, PropertyError)
Beispiel #8
0
    def test_non_model_reference(self, enum_property_factory):
        from openapi_python_client.parser.properties import Schemas
        from openapi_python_client.parser.properties.model_property import _process_properties

        data = oai.Schema.construct(allOf=[oai.Reference.construct(ref="#/First")])
        schemas = Schemas(
            classes_by_reference={
                "/First": enum_property_factory(),
            }
        )

        result = _process_properties(data=data, schemas=schemas, class_name="", config=Config())

        assert isinstance(result, PropertyError)
    def test_process_properties_reference_not_exist(self):
        from openapi_python_client.parser.properties import Schemas
        from openapi_python_client.parser.properties.model_property import _process_properties

        data = oai.Schema(properties={
            "bad":
            oai.Reference.construct(ref="#/components/schema/NotExist"),
        }, )

        result = _process_properties(data=data,
                                     class_name="",
                                     schemas=Schemas(),
                                     config=Config())

        assert isinstance(result, PropertyError)
Beispiel #10
0
    def test_duplicate_properties(self, model_property_factory):
        from openapi_python_client.parser.properties import Schemas
        from openapi_python_client.parser.properties.model_property import _process_properties

        data = oai.Schema.construct(
            allOf=[oai.Reference.construct(ref="#/First"), oai.Reference.construct(ref="#/Second")]
        )
        prop = string_property()
        schemas = Schemas(
            classes_by_reference={
                "/First": model_property_factory(optional_properties=[prop]),
                "/Second": model_property_factory(optional_properties=[prop]),
            }
        )

        result = _process_properties(data=data, schemas=schemas, class_name="", config=Config())

        assert result.optional_props == [prop], "There should only be one copy of duplicate properties"
Beispiel #11
0
    def test_conflicting_properties_different_types(self, model_property_factory):
        from openapi_python_client.parser.properties import Schemas
        from openapi_python_client.parser.properties.model_property import _process_properties

        data = oai.Schema.construct(
            allOf=[oai.Reference.construct(ref="#/First"), oai.Reference.construct(ref="#/Second")]
        )
        schemas = Schemas(
            classes_by_reference={
                "/First": model_property_factory(
                    optional_properties=[StringProperty(name="prop", required=True, nullable=True, default=None)]
                ),
                "/Second": model_property_factory(
                    optional_properties=[DateTimeProperty(name="prop", required=True, nullable=True, default=None)]
                ),
            }
        )

        result = _process_properties(data=data, schemas=schemas, class_name="", config=Config())

        assert isinstance(result, PropertyError)