-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add duration field & expose max_digits/precision of FloatField (#211)
Changes: - add duration field - move field tests to fields - remove duplicate test file in run_sync - add duration field test - expand tests for InspectDB - expand tests for reflection - test harder the correct reflection of fields - expose max_digits for FloatField
- Loading branch information
Showing
14 changed files
with
375 additions
and
160 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
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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from datetime import timedelta | ||
|
||
import pytest | ||
|
||
import edgy | ||
from edgy.testclient import DatabaseTestClient | ||
from tests.settings import DATABASE_URL | ||
|
||
database = DatabaseTestClient(DATABASE_URL) | ||
models = edgy.Registry(database=edgy.Database(database, force_rollback=True)) | ||
|
||
pytestmark = pytest.mark.anyio | ||
|
||
|
||
class User(edgy.Model): | ||
name = edgy.CharField(max_length=100) | ||
language = edgy.CharField(max_length=200, null=True) | ||
age: timedelta = edgy.fields.DurationField(null=True) | ||
|
||
class Meta: | ||
registry = models | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="module") | ||
async def create_test_database(): | ||
async with database: | ||
await models.create_all() | ||
yield | ||
if not database.drop: | ||
await models.drop_all() | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="function") | ||
async def rollback_transactions(): | ||
async with models.database: | ||
yield | ||
|
||
|
||
async def test_model_save(): | ||
user = await User.query.create(name="Jane", age=timedelta(days=365 * 20)) | ||
|
||
assert user.age == timedelta(days=365 * 20) | ||
await user.save() | ||
|
||
user = await User.query.get(pk=user.pk) | ||
|
||
assert user.age == timedelta(days=365 * 20) | ||
|
||
|
||
async def test_model_save_without(): | ||
user = await User.query.create(name="Jane") | ||
|
||
assert user.age is None | ||
await user.save() | ||
|
||
user = await User.query.get(pk=user.pk) | ||
|
||
assert user.age is None |
Oops, something went wrong.