-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved testclient & databasez support >= 0.9 (#167)
- improve testclient - fix tests - support databasez >= 0.9 * bump databasez requirement
- Loading branch information
Showing
10 changed files
with
117 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,55 @@ | ||
from databasez.testclient import DatabaseTestClient as DatabaseTestClient # noqa | ||
import os | ||
import typing | ||
from typing import TYPE_CHECKING, Any | ||
|
||
from databasez.testclient import DatabaseTestClient as _DatabaseTestClient | ||
|
||
if TYPE_CHECKING: | ||
import sqlalchemy | ||
from databasez import Database, DatabaseURL | ||
|
||
# TODO: move this to the settings | ||
default_test_prefix: str = "test_" | ||
# for allowing empty | ||
if "SAFFIER_TESTCLIENT_TEST_PREFIX" in os.environ: | ||
default_test_prefix = os.environ["SAFFIER_TESTCLIENT_TEST_PREFIX"] | ||
|
||
default_use_existing: bool = ( | ||
os.environ.get("SAFFIER_TESTCLIENT_USE_EXISTING") or "" | ||
).lower() == "true" | ||
default_drop_database: bool = ( | ||
os.environ.get("SAFFIER_TESTCLIENT_DROP_DATABASE") or "" | ||
).lower() == "true" | ||
|
||
|
||
class DatabaseTestClient(_DatabaseTestClient): | ||
""" | ||
Adaption of DatabaseTestClient for saffier. | ||
Note: the default of lazy_setup is True here. This enables the simple Registry syntax. | ||
""" | ||
|
||
testclient_lazy_setup: bool = ( | ||
os.environ.get("SAFFIER_TESTCLIENT_LAZY_SETUP", "true") or "" | ||
).lower() == "true" | ||
testclient_force_rollback: bool = ( | ||
os.environ.get("SAFFIER_TESTCLIENT_FORCE_ROLLBACK") or "" | ||
).lower() == "true" | ||
|
||
# TODO: replace by testclient default overwrites | ||
def __init__( | ||
self, | ||
url: typing.Union[str, "DatabaseURL", "sqlalchemy.URL", "Database"], | ||
*, | ||
use_existing: bool = default_use_existing, | ||
drop_database: bool = default_drop_database, | ||
test_prefix: str = default_test_prefix, | ||
**options: Any, | ||
): | ||
super().__init__( | ||
url, | ||
use_existing=use_existing, | ||
drop_database=drop_database, | ||
test_prefix=test_prefix, | ||
**options, | ||
) |
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