-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run the ruff linter over the code as configured by pyproject.toml.
- Loading branch information
1 parent
0fe023b
commit 4cbd66e
Showing
10 changed files
with
60 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
from typing import Optional | ||
|
||
import pytest | ||
from pydantic import ConfigDict | ||
from testapp.models import Configuration, Listing, Preference, Record, Searchable, User, NullableChar, NullableFK | ||
|
||
from packaging import version | ||
from pydantic import ( | ||
ConfigDict, | ||
ValidationError, | ||
ValidationInfo, | ||
field_validator, | ||
ValidationError, | ||
) | ||
from testapp.models import ( | ||
Configuration, | ||
Listing, | ||
NullableChar, | ||
NullableFK, | ||
Preference, | ||
Record, | ||
Searchable, | ||
User, | ||
) | ||
|
||
from djantic import ModelSchema | ||
|
@@ -43,25 +52,21 @@ class UserSchema(ModelSchema): | |
|
||
@pytest.mark.django_db | ||
def test_context_for_field(): | ||
|
||
def get_context(): | ||
return {'check_title': lambda x: x.istitle()} | ||
return {"check_title": lambda x: x.istitle()} | ||
|
||
class UserSchema(ModelSchema): | ||
model_config = ConfigDict( | ||
model=User, | ||
revalidate_instances='always' | ||
) | ||
model_config = ConfigDict(model=User, revalidate_instances="always") | ||
|
||
@field_validator('first_name', mode="before", check_fields=False) | ||
@field_validator("first_name", mode="before", check_fields=False) | ||
@classmethod | ||
def validate_first_name(cls, v: str, info: ValidationInfo): | ||
if not info.context: | ||
return v | ||
|
||
check_title = info.context.get('check_title') | ||
check_title = info.context.get("check_title") | ||
if check_title and not check_title(v): | ||
raise ValueError('First name needs to be a title') | ||
raise ValueError("First name needs to be a title") | ||
return v | ||
|
||
user = User.objects.create(first_name="hello", email="[email protected]") | ||
|
@@ -533,11 +538,11 @@ class ListingSchema(ModelSchema): | |
@pytest.mark.django_db | ||
def test_nullable_fk(): | ||
class NullableCharSchema(ModelSchema): | ||
model_config = ConfigDict(model=NullableChar, include='value') | ||
model_config = ConfigDict(model=NullableChar, include="value") | ||
|
||
class NullableFKSchema(ModelSchema): | ||
nullable_char: Optional[NullableCharSchema] = None | ||
model_config = ConfigDict(model=NullableFK, include='nullable_char') | ||
model_config = ConfigDict(model=NullableFK, include="nullable_char") | ||
|
||
nullable_char = NullableChar(value="test") | ||
nullable_char.save() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#!/usr/bin/env python | ||
"""Django's command-line utility for administrative tasks.""" | ||
|
||
import os | ||
import sys | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters