def test_get_imports(self):
        from openapi_python_client.parser.properties import DateTimeProperty

        p = DateTimeProperty(name="test", required=True, default=None, nullable=False)
        assert p.get_imports(prefix="...") == {
            "import datetime",
            "from typing import cast",
            "from dateutil.parser import isoparse",
        }

        p = DateTimeProperty(name="test", required=False, default=None, nullable=False)
        assert p.get_imports(prefix="...") == {
            "import datetime",
            "from typing import cast",
            "from dateutil.parser import isoparse",
            "from typing import Union",
            "from ...types import UNSET, Unset",
        }

        p = DateTimeProperty(name="test", required=False, default=None, nullable=True)
        assert p.get_imports(prefix="...") == {
            "import datetime",
            "from typing import cast",
            "from dateutil.parser import isoparse",
            "from typing import Union",
            "from typing import Optional",
            "from ...types import UNSET, Unset",
        }
Beispiel #2
0
    def test_get_imports(self, mocker):
        from openapi_python_client.parser.properties import DateTimeProperty

        name = mocker.MagicMock()
        mocker.patch("openapi_python_client.utils.snake_case")
        p = DateTimeProperty(name=name, required=True, default=None)
        assert p.get_imports(prefix="") == {
            "import datetime",
            "from typing import cast",
        }

        p.required = False
        assert p.get_imports(prefix="") == {
            "from typing import Optional",
            "import datetime",
            "from typing import cast",
        }