Skip to content

Commit

Permalink
Merge pull request #15 from eadwinCode/fixing_get_schema_v2
Browse files Browse the repository at this point in the history
fix: CI tests
  • Loading branch information
eadwinCode authored Nov 19, 2024
2 parents 150d36a + 00cc0d7 commit 13c8266
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
6 changes: 3 additions & 3 deletions ninja_schema/orm/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

from django.db.models import Model

from ninja_schema.errors import ConfigError
from ninja_schema.pydanticutils import IS_PYDANTIC_V1
from ninja_schema.types import DictStrAny

from ..errors import ConfigError
from ..types import DictStrAny
from .schema_registry import SchemaRegister
from .schema_registry import registry as schema_registry

Expand Down Expand Up @@ -89,7 +89,7 @@ def _get_schema_v2(
cls, name: str, model_config_kwargs: typing.Dict, model_type: typing.Type
) -> Union[Type["ModelSchema"], Type["Schema"]]:
model_config = cls.get_model_config(**model_config_kwargs)
new_schema_result = {}
new_schema_result = {} # type:ignore[var-annotated]
new_schema_string = f"""class {name}(model_type):
class Config(model_config):
pass """
Expand Down
1 change: 0 additions & 1 deletion ninja_schema/pydanticutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

PYDANTIC_VERSION = list(map(int, _PYDANTIC_VERSION.split(".")))[:2]
IS_PYDANTIC_V1 = PYDANTIC_VERSION[0] == 1
IS_PYDANTIC_V292_OR_GREATER = PYDANTIC_VERSION[0] >= 2 and PYDANTIC_VERSION[1] >= 9


def is_valid_field_name(name: str) -> bool:
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
"Framework :: Django",
"Framework :: Django :: 3.0",
Expand Down Expand Up @@ -56,8 +57,8 @@ test = [
"pytest-cov",
"pytest-django",
"pytest-asyncio",
"mypy == 1.7.1",
"ruff ==0.1.7",
"mypy == 1.11.1",
"ruff == 0.7.4",
"django-stubs",
]
dev = [
Expand Down
12 changes: 5 additions & 7 deletions tests/test_v2_pydantic/test_custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from pydantic import ValidationError

from ninja_schema import ModelSchema
from ninja_schema.pydanticutils import IS_PYDANTIC_V1, IS_PYDANTIC_V292_OR_GREATER
from ninja_schema.pydanticutils import IS_PYDANTIC_V1
from tests.models import Student, StudentEmail


class TestCustomFields:
@pytest.mark.skipif(IS_PYDANTIC_V1 and not IS_PYDANTIC_V292_OR_GREATER, reason="requires pydantic == 2.1.x and pydantic < 2.9.2")
@pytest.mark.skipif(IS_PYDANTIC_V1, reason="requires pydantic == 2.1.x")
def test_enum_field(self):
class StudentSchema(ModelSchema):
model_config = {"model": Student, "include": "__all__"}
Expand All @@ -31,7 +31,7 @@ class StudentSchema(ModelSchema):
"title": "Id",
},
"semester": {
"allOf": [{"$ref": "#/$defs/SemesterEnum"}],
"$ref": "#/$defs/SemesterEnum",
"default": "1",
"description": "",
"title": "Semester",
Expand All @@ -45,9 +45,8 @@ class StudentSchema(ModelSchema):
with pytest.raises(ValidationError):
StudentSchema(semester="something")


@pytest.mark.skipif(not IS_PYDANTIC_V292_OR_GREATER, reason="requires pydantic == 2.1.x and pydantic < 2.9.2")
def test_enum_field_v292_or_greater(self):
@pytest.mark.skipif(IS_PYDANTIC_V1, reason="requires pydantic == 2.1.x")
def test_enum_field_or_greater(self):
class StudentSchema(ModelSchema):
model_config = {"model": Student, "include": "__all__"}

Expand Down Expand Up @@ -82,7 +81,6 @@ class StudentSchema(ModelSchema):
with pytest.raises(ValidationError):
StudentSchema(semester="something")


@pytest.mark.skipif(IS_PYDANTIC_V1, reason="requires pydantic == 2.1.x")
def test_email_field(self):
class StudentEmailSchema(ModelSchema):
Expand Down

0 comments on commit 13c8266

Please sign in to comment.