tigrbl-tests 0.3.1__py3-none-any.whl → 0.3.2.dev1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tests/unit/test_base_columnspec_inheritance.py +29 -0
- tests/unit/test_include_model_columns_namespace.py +22 -0
- tests/unit/test_sqlite_uuid_type.py +70 -0
- tests/unit/test_verbosity.py +62 -0
- {tigrbl_tests-0.3.1.dist-info → tigrbl_tests-0.3.2.dev1.dist-info}/METADATA +1 -1
- {tigrbl_tests-0.3.1.dist-info → tigrbl_tests-0.3.2.dev1.dist-info}/RECORD +8 -4
- {tigrbl_tests-0.3.1.dist-info → tigrbl_tests-0.3.2.dev1.dist-info}/WHEEL +0 -0
- {tigrbl_tests-0.3.1.dist-info → tigrbl_tests-0.3.2.dev1.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import warnings
|
|
4
|
+
|
|
5
|
+
from sqlalchemy import Integer, String
|
|
6
|
+
from sqlalchemy.exc import SAWarning
|
|
7
|
+
|
|
8
|
+
from tigrbl.column import ColumnSpec, S
|
|
9
|
+
from tigrbl.table._base import Base
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_columnspec_inheritance_does_not_warn() -> None:
|
|
13
|
+
class Parent(Base):
|
|
14
|
+
__tablename__ = "test_parent"
|
|
15
|
+
__mapper_args__ = {
|
|
16
|
+
"polymorphic_identity": "parent",
|
|
17
|
+
"polymorphic_on": "kind",
|
|
18
|
+
}
|
|
19
|
+
id: int = ColumnSpec(storage=S(type_=Integer, primary_key=True))
|
|
20
|
+
kind: str = ColumnSpec(storage=S(type_=String))
|
|
21
|
+
|
|
22
|
+
with warnings.catch_warnings():
|
|
23
|
+
warnings.simplefilter("error", SAWarning)
|
|
24
|
+
|
|
25
|
+
class Child(Parent):
|
|
26
|
+
__mapper_args__ = {"polymorphic_identity": "child"}
|
|
27
|
+
|
|
28
|
+
# no extra columns, we just inherit Parent.id
|
|
29
|
+
pass
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from types import SimpleNamespace
|
|
2
|
+
|
|
3
|
+
from sqlalchemy import Integer, String
|
|
4
|
+
|
|
5
|
+
from tigrbl.bindings import include_model
|
|
6
|
+
from tigrbl.column import ColumnSpec, S
|
|
7
|
+
from tigrbl.table import Table
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Widget(Table):
|
|
11
|
+
__tablename__ = "widgets_columns_namespace"
|
|
12
|
+
|
|
13
|
+
id: int = ColumnSpec(storage=S(type_=Integer, primary_key=True))
|
|
14
|
+
name: str = ColumnSpec(storage=S(type_=String, nullable=False))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_include_model_coerces_columns_namespace() -> None:
|
|
18
|
+
api = SimpleNamespace()
|
|
19
|
+
|
|
20
|
+
include_model(api, Widget, mount_router=False)
|
|
21
|
+
|
|
22
|
+
assert api.columns["Widget"] == ("id", "name")
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from uuid import UUID, uuid4
|
|
4
|
+
|
|
5
|
+
from sqlalchemy.dialects import postgresql, sqlite
|
|
6
|
+
|
|
7
|
+
from tigrbl.types import SqliteUUID
|
|
8
|
+
from tigrbl.deps.sqlalchemy import String, _PgUUID
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_sqlite_uuid_python_type_flags() -> None:
|
|
12
|
+
assert SqliteUUID(as_uuid=True).python_type is UUID
|
|
13
|
+
assert SqliteUUID(as_uuid=False).python_type is str
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_sqlite_uuid_sqlite_bind_param_coerces_uuid_str() -> None:
|
|
17
|
+
dialect = sqlite.dialect()
|
|
18
|
+
type_ = SqliteUUID(as_uuid=True)
|
|
19
|
+
uid = uuid4()
|
|
20
|
+
|
|
21
|
+
assert type_.process_bind_param(uid, dialect) == str(uid)
|
|
22
|
+
assert type_.process_bind_param(uid.hex, dialect) == str(uid)
|
|
23
|
+
|
|
24
|
+
type_as_str = SqliteUUID(as_uuid=False)
|
|
25
|
+
assert type_as_str.process_bind_param(uid, dialect) == str(uid)
|
|
26
|
+
assert type_as_str.process_bind_param(uid.hex, dialect) == uid.hex
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_sqlite_uuid_postgres_bind_param_returns_uuid() -> None:
|
|
30
|
+
dialect = postgresql.dialect()
|
|
31
|
+
type_ = SqliteUUID(as_uuid=True)
|
|
32
|
+
uid = uuid4()
|
|
33
|
+
|
|
34
|
+
assert type_.process_bind_param(uid, dialect) is uid
|
|
35
|
+
assert type_.process_bind_param(str(uid), dialect) == uid
|
|
36
|
+
|
|
37
|
+
type_as_str = SqliteUUID(as_uuid=False)
|
|
38
|
+
assert type_as_str.process_bind_param(uid, dialect) == str(uid)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_sqlite_uuid_result_processing() -> None:
|
|
42
|
+
uid = uuid4()
|
|
43
|
+
sqlite_dialect = sqlite.dialect()
|
|
44
|
+
pg_dialect = postgresql.dialect()
|
|
45
|
+
|
|
46
|
+
type_ = SqliteUUID(as_uuid=True)
|
|
47
|
+
assert type_.process_result_value(str(uid), sqlite_dialect) == uid
|
|
48
|
+
assert type_.process_result_value(uid, pg_dialect) is uid
|
|
49
|
+
|
|
50
|
+
type_as_str = SqliteUUID(as_uuid=False)
|
|
51
|
+
assert type_as_str.process_result_value(uid, sqlite_dialect) == str(uid)
|
|
52
|
+
assert type_as_str.process_result_value(str(uid), pg_dialect) == str(uid)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_sqlite_uuid_dialect_impls() -> None:
|
|
56
|
+
sqlite_dialect = sqlite.dialect()
|
|
57
|
+
pg_dialect = postgresql.dialect()
|
|
58
|
+
|
|
59
|
+
type_as_uuid = SqliteUUID(as_uuid=True)
|
|
60
|
+
sqlite_impl = type_as_uuid.load_dialect_impl(sqlite_dialect)
|
|
61
|
+
pg_impl = type_as_uuid.load_dialect_impl(pg_dialect)
|
|
62
|
+
|
|
63
|
+
assert isinstance(sqlite_impl, String)
|
|
64
|
+
assert isinstance(pg_impl, _PgUUID)
|
|
65
|
+
assert pg_impl.as_uuid is True
|
|
66
|
+
|
|
67
|
+
type_as_str = SqliteUUID(as_uuid=False)
|
|
68
|
+
pg_impl_str = type_as_str.load_dialect_impl(pg_dialect)
|
|
69
|
+
assert isinstance(pg_impl_str, _PgUUID)
|
|
70
|
+
assert pg_impl_str.as_uuid is False
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from tigrbl.schema import collect as schema_collect
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class _ListHandler(logging.Handler):
|
|
7
|
+
def __init__(self, records):
|
|
8
|
+
super().__init__()
|
|
9
|
+
self._records = records
|
|
10
|
+
|
|
11
|
+
def emit(self, record: logging.LogRecord) -> None:
|
|
12
|
+
self._records.append(record)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _set_uvicorn_level(level: int) -> int:
|
|
16
|
+
logger = logging.getLogger("uvicorn")
|
|
17
|
+
previous = logger.level
|
|
18
|
+
logger.setLevel(level)
|
|
19
|
+
return previous
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_verbosity_level_does_not_force_debug() -> None:
|
|
23
|
+
previous_level = _set_uvicorn_level(logging.INFO)
|
|
24
|
+
try:
|
|
25
|
+
assert schema_collect.logger.name == "uvicorn"
|
|
26
|
+
assert logging.getLogger("uvicorn").level == logging.INFO
|
|
27
|
+
finally:
|
|
28
|
+
logging.getLogger("uvicorn").setLevel(previous_level)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_verbosity_situations_skip_debug_without_verbose() -> None:
|
|
32
|
+
previous_level = _set_uvicorn_level(logging.INFO)
|
|
33
|
+
logger = logging.getLogger("uvicorn")
|
|
34
|
+
records: list[logging.LogRecord] = []
|
|
35
|
+
handler = _ListHandler(records)
|
|
36
|
+
logger.addHandler(handler)
|
|
37
|
+
try:
|
|
38
|
+
schema_collect.logger.debug("tigrbl verbosity debug")
|
|
39
|
+
assert not records
|
|
40
|
+
finally:
|
|
41
|
+
logger.removeHandler(handler)
|
|
42
|
+
logging.getLogger("uvicorn").setLevel(previous_level)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_verbosity_formatting_uses_uvicorn_logger() -> None:
|
|
46
|
+
previous_level = _set_uvicorn_level(logging.DEBUG)
|
|
47
|
+
logger = logging.getLogger("uvicorn")
|
|
48
|
+
records: list[logging.LogRecord] = []
|
|
49
|
+
handler = _ListHandler(records)
|
|
50
|
+
logger.addHandler(handler)
|
|
51
|
+
try:
|
|
52
|
+
schema_collect.logger.debug("tigrbl formatting %s", "ok")
|
|
53
|
+
record = next(
|
|
54
|
+
record
|
|
55
|
+
for record in records
|
|
56
|
+
if record.getMessage() == "tigrbl formatting ok"
|
|
57
|
+
)
|
|
58
|
+
assert record.name == "uvicorn"
|
|
59
|
+
assert record.levelname == "DEBUG"
|
|
60
|
+
finally:
|
|
61
|
+
logger.removeHandler(handler)
|
|
62
|
+
logging.getLogger("uvicorn").setLevel(previous_level)
|
|
@@ -83,6 +83,7 @@ tests/unit/test_alias_ctx_op_attributes.py,sha256=hH8u8oUcSCMsZ7aN5MFaGmkKsuA7XL
|
|
|
83
83
|
tests/unit/test_api_level_set_auth.py,sha256=PFioS6Y3jWoBGm7SoVK06eJQ44QGZ4de597AfiltF2k,932
|
|
84
84
|
tests/unit/test_app_model_defaults.py,sha256=pAB_g4zPFuke8zYKX5bxITsS7RYXyXJBLScguIpZ4FU,724
|
|
85
85
|
tests/unit/test_app_reexport.py,sha256=hUeggDwnw6NE3t5gJpTF1pEKGjR8dTD6qN-Eux5OoWk,127
|
|
86
|
+
tests/unit/test_base_columnspec_inheritance.py,sha256=x7p3AaE9Hsgl3921F9cd5P9U00HtDmVNWtvFAcvL-VI,835
|
|
86
87
|
tests/unit/test_base_facade_initialize.py,sha256=iS571_e5aiVJRNRZss3GemwhNCvIPBUukiLYK-RJRwo,1655
|
|
87
88
|
tests/unit/test_build_list_params_spec_model.py,sha256=msi_7O1-TjbUx-Eoui_bg-7M4GPxCTZNESnLqZonME0,1029
|
|
88
89
|
tests/unit/test_bulk_body_annotation.py,sha256=StbnRqsw2KAGyYR6bpgxQdsbC6EiPqWjY3Pd8QkfZXo,818
|
|
@@ -109,6 +110,7 @@ tests/unit/test_hook_ctx_binding.py,sha256=DJlf43ALbdhZIANGRGFppILHXf5MUuXh-uHUS
|
|
|
109
110
|
tests/unit/test_hookz_empty_phase.py,sha256=Tl06JwI0WM4lsS-KMNEKI9cSsiM5qtE9PNBXyrPNLDg,855
|
|
110
111
|
tests/unit/test_hybrid_session_run_sync.py,sha256=6zidxhpUNfE81xtS5kzQYPn36SinMPJiukGKtIRdiM0,547
|
|
111
112
|
tests/unit/test_in_tx.py,sha256=Bzn5iTkJGUpXG8J0Uduj9b8OThgPGXl-jEKfmWyWkPY,549
|
|
113
|
+
tests/unit/test_include_model_columns_namespace.py,sha256=IQhuCZ168NanMHiTlhs_B1seQwYIkaq3WaBqiWkC67c,591
|
|
112
114
|
tests/unit/test_include_models_base_prefix.py,sha256=z8Rvl3bMjf8kMLpqLn7Ia08dR1KQORrHzBIrubyEq8s,813
|
|
113
115
|
tests/unit/test_initialize_cross_ddl.py,sha256=kaku7ZVX68rDAxNBbZRaVyXSiw4Op6Jb5ex-eNHKmjU,689
|
|
114
116
|
tests/unit/test_io_spec_attributes.py,sha256=Da9u7yjw-KVbHF1tpQhUvl7HSfooe9L1k5y-ceRVsaM,5662
|
|
@@ -171,6 +173,7 @@ tests/unit/test_spec_op.py,sha256=18wGspqhyd-xfwBYKh1kSF4Tzqbpv9KUqfuXl_lRcjY,95
|
|
|
171
173
|
tests/unit/test_spec_storage.py,sha256=QP6oSuFUXuAR21o75SXppfunCVmDnRLV7IaH7Y249fs,702
|
|
172
174
|
tests/unit/test_spec_table.py,sha256=rZceC_d-6E6P_zj5UmSmhqSgRCqzIoC9wmFys6hIwC4,602
|
|
173
175
|
tests/unit/test_sqlite_attachments.py,sha256=TmXPK6WGPPKYKHBsy9MNp48njkK0KlQcew6JStxZSA8,2035
|
|
176
|
+
tests/unit/test_sqlite_uuid_type.py,sha256=eDsWDRTKxZhAj3CTTX7gQ4t1YD_VuSULoooItL_nekI,2343
|
|
174
177
|
tests/unit/test_storage_spec_attributes.py,sha256=CAjwtFEiFo85uqWvTGaO5KkzDA9QM_DADaZDI_jtISQ,1824
|
|
175
178
|
tests/unit/test_sys_handler_crud.py,sha256=tOMGvjaP0giM0I-viKm4pjWI8K0JCLo7Dy90fqtuOP8,2708
|
|
176
179
|
tests/unit/test_sys_run_rollback.py,sha256=9XPGDVK1qkbPYOfzLZc7ulhDN2k9X-Q7mHgRAJsYDKk,1261
|
|
@@ -186,7 +189,8 @@ tests/unit/test_v3_op_alias.py,sha256=lSb8xpA9Asmaz7VefFDJLwbNBHP_mN4hSVJr1NVvOI
|
|
|
186
189
|
tests/unit/test_v3_op_ctx_attributes.py,sha256=ygRtYSYYtDFCTIRVHX2DFYTliP15NcmVinWN42HwmRo,2311
|
|
187
190
|
tests/unit/test_v3_schemas_and_decorators.py,sha256=1wmg7pmzQNjjbQPRjO8gkCM6BQpMRbeO2jmtDMSYXLU,3818
|
|
188
191
|
tests/unit/test_v3_storage_spec_attributes.py,sha256=iXpjD4GlLddhJ_jC2veND2s6usXdOm-S9sKKfQl9XK0,6540
|
|
189
|
-
|
|
190
|
-
tigrbl_tests-0.3.
|
|
191
|
-
tigrbl_tests-0.3.
|
|
192
|
-
tigrbl_tests-0.3.
|
|
192
|
+
tests/unit/test_verbosity.py,sha256=92dIDc-LBIzjR1d90aL077R29rYJztibKYQGTjI6G68,1945
|
|
193
|
+
tigrbl_tests-0.3.2.dev1.dist-info/METADATA,sha256=13f3TinTYP6fvcN7lqFmDg5dEkbs8C6ktVZiJyoz8FM,3300
|
|
194
|
+
tigrbl_tests-0.3.2.dev1.dist-info/WHEEL,sha256=3ny-bZhpXrU6vSQ1UPG34FoxZBp3lVcvK0LkgUz6VLk,88
|
|
195
|
+
tigrbl_tests-0.3.2.dev1.dist-info/licenses/LICENSE,sha256=djUXOlCxLVszShEpZXshZ7v33G-2qIC_j9KXpWKZSzQ,11359
|
|
196
|
+
tigrbl_tests-0.3.2.dev1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|