Exemple #1
0
    def test__string_based_property_date_format(self, mocker):
        name = mocker.MagicMock()
        required = mocker.MagicMock()
        data = oai.Schema.construct(type="string", schema_format="date")
        DateProperty = mocker.patch(f"{MODULE_NAME}.DateProperty")

        from openapi_python_client.parser.properties import _string_based_property

        p = _string_based_property(name=name, required=required, data=data)
        DateProperty.assert_called_once_with(name=name,
                                             required=required,
                                             default=None)
        assert p == DateProperty.return_value

        # Test optional values
        DateProperty.reset_mock()
        data.default = mocker.MagicMock()

        _string_based_property(
            name=name,
            required=required,
            data=data,
        )
        DateProperty.assert_called_once_with(name=name,
                                             required=required,
                                             default=data.default)
Exemple #2
0
    def test__string_based_property_unsupported_format(self, mocker):
        name = mocker.MagicMock()
        required = mocker.MagicMock()
        data = oai.Schema.construct(type="string", schema_format=mocker.MagicMock())
        data.nullable = mocker.MagicMock()
        StringProperty = mocker.patch(f"{MODULE_NAME}.StringProperty")

        from openapi_python_client.parser.properties import _string_based_property

        p = _string_based_property(name=name, required=required, data=data)

        StringProperty.assert_called_once_with(
            name=name, required=required, pattern=None, default=None, nullable=data.nullable
        )
        assert p == StringProperty.return_value

        # Test optional values
        StringProperty.reset_mock()
        data.default = mocker.MagicMock()
        data.pattern = mocker.MagicMock()

        _string_based_property(
            name=name, required=required, data=data,
        )
        StringProperty.assert_called_once_with(
            name=name, required=required, pattern=data.pattern, default=data.default, nullable=data.nullable
        )
    def test__string_based_property_date_format(self):
        from openapi_python_client.parser.properties import DateProperty, _string_based_property

        name = "date_prop"
        required = True
        data = oai.Schema.construct(type="string", schema_format="date", nullable=True, default="2020-11-06")

        p = _string_based_property(name=name, required=required, data=data)

        assert p == DateProperty(name=name, required=required, nullable=True, default="isoparse('2020-11-06').date()")

        # Test bad default
        data.default = "a"
        with pytest.raises(ValidationError):
            _string_based_property(name=name, required=required, data=data)
    def test__string_based_property_binary_format(self):
        from openapi_python_client.parser.properties import FileProperty, _string_based_property

        name = "file_prop"
        required = True
        data = oai.Schema.construct(type="string", schema_format="binary", nullable=True, default="a")

        p = _string_based_property(name=name, required=required, data=data)
        assert p == FileProperty(name=name, required=required, nullable=True, default=None)
    def test__string_based_property_unsupported_format(self, mocker):
        from openapi_python_client.parser.properties import StringProperty, _string_based_property

        name = "unknown"
        required = True
        data = oai.Schema.construct(type="string", schema_format="blah", nullable=True)

        p = _string_based_property(name=name, required=required, data=data)

        assert p == StringProperty(name=name, required=required, nullable=True, default=None)
    def test__string_based_property_no_format(self):
        from openapi_python_client.parser.properties import StringProperty

        name = "some_prop"
        required = True
        data = oai.Schema.construct(type="string", nullable=True, default='"hello world"')

        from openapi_python_client.parser.properties import _string_based_property

        p = _string_based_property(name=name, required=required, data=data)

        assert p == StringProperty(name=name, required=required, nullable=True, default="'\\\\\"hello world\\\\\"'")

        data.pattern = "abcdef"
        data.nullable = False

        p = _string_based_property(
            name=name,
            required=required,
            data=data,
        )
        assert p == StringProperty(
            name=name, required=required, nullable=False, default="'\\\\\"hello world\\\\\"'", pattern="abcdef"
        )