jigkit 0.3.0__tar.gz → 0.4.0__tar.gz
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.
- {jigkit-0.3.0 → jigkit-0.4.0}/PKG-INFO +1 -1
- {jigkit-0.3.0 → jigkit-0.4.0}/pyproject.toml +1 -1
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/logging.py +3 -2
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/testing/migrations.py +13 -2
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_heartbeat.py +20 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_migrations.py +29 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/.gitignore +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/LICENSE +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/README.md +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/__init__.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/db.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/delivery.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/healthcheck.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/heartbeat.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/influx/__init__.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/influx/lineprotocol.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/influx/sink.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/migrations.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/models.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/notify.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/py.typed +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/ratelimit.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/scheduler.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/secrets.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/settings.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/sinks.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/spool.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/testing/__init__.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/testing/http.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/testing/notify.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/web/__init__.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/web/guard.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/web/health.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/web/manifest.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/web/server.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/src/jigkit/web/spa.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/conftest.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/sample_app/alembic/env.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/sample_app/alembic/script.py.mako +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/sample_app/alembic/versions/0001_initial.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/sample_app/alembic.ini +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/sample_app/sample_schema.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_db.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_delivery.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_healthcheck.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_influx_lineprotocol.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_influx_read.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_influx_sink.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_logging.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_models.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_notify.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_ratelimit.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_scheduler.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_secrets.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_settings.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_sinks.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_spool.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_testing_plugin.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_version.py +0 -0
- {jigkit-0.3.0 → jigkit-0.4.0}/tests/test_web.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: jigkit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: The shared foundations of small self-hosted web apps: settings, database, migrations, logging, health checks and test fixtures
|
|
5
5
|
Project-URL: Homepage, https://github.com/jmerhar/jigkit
|
|
6
6
|
Project-URL: Changelog, https://github.com/jmerhar/jigkit/blob/main/CHANGELOG.md
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "jigkit"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.4.0"
|
|
8
8
|
description = "The shared foundations of small self-hosted web apps: settings, database, migrations, logging, health checks and test fixtures"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.14"
|
|
@@ -30,8 +30,9 @@ FOLLOW_ROOT = ("uvicorn", "uvicorn.access", "uvicorn.error")
|
|
|
30
30
|
|
|
31
31
|
#: Loggers held at WARNING however low the application goes. httpx logs every request's URL at
|
|
32
32
|
#: INFO and httpcore logs headers at DEBUG, and URLs and headers carry credentials: push-monitor
|
|
33
|
-
#: tokens, bot tokens, session cookies.
|
|
34
|
-
|
|
33
|
+
#: tokens, bot tokens, session cookies. httpx2 and httpcore2, which jigkit's own HTTP clients
|
|
34
|
+
#: use, log the same under their own names.
|
|
35
|
+
QUIET = ("httpx", "httpcore", "httpx2", "httpcore2")
|
|
35
36
|
|
|
36
37
|
# Marks the handlers this module installed, so a repeated call replaces them rather than stacking
|
|
37
38
|
# a second copy that logs every line twice.
|
|
@@ -27,7 +27,7 @@ import shutil
|
|
|
27
27
|
import subprocess
|
|
28
28
|
import sys
|
|
29
29
|
import uuid
|
|
30
|
-
from collections.abc import Mapping
|
|
30
|
+
from collections.abc import Mapping, Sequence
|
|
31
31
|
from dataclasses import dataclass, field
|
|
32
32
|
from datetime import UTC, date, datetime, time, timedelta
|
|
33
33
|
from decimal import Decimal
|
|
@@ -167,6 +167,7 @@ class MigrationProject:
|
|
|
167
167
|
data_dir: Path,
|
|
168
168
|
scratch: Path,
|
|
169
169
|
overrides: Mapping[str, Mapping[str, Any]] | None = None,
|
|
170
|
+
extra_rows: Mapping[str, Sequence[Mapping[str, Any]]] | None = None,
|
|
170
171
|
) -> None:
|
|
171
172
|
"""Fail if rebuilding a table that others point at loses or orphans their rows.
|
|
172
173
|
|
|
@@ -178,6 +179,13 @@ class MigrationProject:
|
|
|
178
179
|
|
|
179
180
|
Rows are invented from column types. ``overrides`` supplies values for columns whose
|
|
180
181
|
type or constraints the generator cannot satisfy: ``{"table": {"column": value}}``.
|
|
182
|
+
``extra_rows`` adds further rows to a table after its synthetic one, each a synthetic row
|
|
183
|
+
with the given values on top, for a constraint one row per table cannot meet -- two
|
|
184
|
+
different households for a row that must name two, say::
|
|
185
|
+
|
|
186
|
+
extra_rows={"household": [{"id": 2}]},
|
|
187
|
+
overrides={"settlement": {"to_id": 2}},
|
|
188
|
+
|
|
181
189
|
``scratch`` is an empty directory for the copy of the migrations.
|
|
182
190
|
"""
|
|
183
191
|
parents = sorted(
|
|
@@ -190,7 +198,10 @@ class MigrationProject:
|
|
|
190
198
|
try:
|
|
191
199
|
with engine.begin() as connection:
|
|
192
200
|
for table in metadata.sorted_tables:
|
|
193
|
-
|
|
201
|
+
row = synthetic_row(table, overrides)
|
|
202
|
+
connection.execute(table.insert().values(**row))
|
|
203
|
+
for extra in (extra_rows or {}).get(table.name, ()):
|
|
204
|
+
connection.execute(table.insert().values(**(row | dict(extra))))
|
|
194
205
|
before = _row_counts(engine, metadata)
|
|
195
206
|
|
|
196
207
|
copy = self._copy_with_rebuild(scratch, parents)
|
|
@@ -168,3 +168,23 @@ async def test_each_call_reports_whether_it_got_through() -> None:
|
|
|
168
168
|
await heartbeat.call()
|
|
169
169
|
|
|
170
170
|
assert results == [False, True]
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
async def test_at_info_the_push_token_never_reaches_the_log(
|
|
174
|
+
caplog: pytest.LogCaptureFixture,
|
|
175
|
+
) -> None:
|
|
176
|
+
"""The HTTP client logs each request's URL at INFO; jigkit's logging keeps it below that."""
|
|
177
|
+
from jigkit.logging import QUIET, apply_level
|
|
178
|
+
|
|
179
|
+
levels = {name: logging.getLogger(name).level for name in QUIET}
|
|
180
|
+
apply_level("INFO")
|
|
181
|
+
try:
|
|
182
|
+
with caplog.at_level(logging.INFO):
|
|
183
|
+
async with serving(StubServer(status=200)) as stub, httpx2.AsyncClient() as client:
|
|
184
|
+
await Heartbeat(client, stub.url + "/api/push/T0KEN", interval_seconds=60).call()
|
|
185
|
+
finally:
|
|
186
|
+
for name, level in levels.items():
|
|
187
|
+
logging.getLogger(name).setLevel(level)
|
|
188
|
+
|
|
189
|
+
assert stub.requests[0].path == "/api/push/T0KEN"
|
|
190
|
+
assert "T0KEN" not in caplog.text
|
|
@@ -153,6 +153,35 @@ class TestParentRebuilds:
|
|
|
153
153
|
with pytest.raises(AssertionError, match=r"'pets': \(1, 0\)"):
|
|
154
154
|
project.assert_parent_rebuilds_keep_children(sample_metadata(), data_dir, tmp_path)
|
|
155
155
|
|
|
156
|
+
def test_extra_rows_meet_a_constraint_one_row_per_table_cannot(
|
|
157
|
+
self, data_dir: Path, tmp_path: Path
|
|
158
|
+
) -> None:
|
|
159
|
+
# A note that must not belong to the owner of pet 1: the second owner is an extra row,
|
|
160
|
+
# and the note points at it.
|
|
161
|
+
project = copy_project(tmp_path / "project")
|
|
162
|
+
add_migration(
|
|
163
|
+
project,
|
|
164
|
+
"0002",
|
|
165
|
+
"0001",
|
|
166
|
+
"op.execute('CREATE TRIGGER different BEFORE INSERT ON notes WHEN NEW.owner_id = 1 "
|
|
167
|
+
"BEGIN SELECT RAISE(ABORT, \\'the first owner takes no notes\\'); END')",
|
|
168
|
+
)
|
|
169
|
+
scratch = tmp_path / "scratch"
|
|
170
|
+
scratch.mkdir()
|
|
171
|
+
|
|
172
|
+
with pytest.raises(Exception, match="the first owner takes no notes"):
|
|
173
|
+
project.assert_parent_rebuilds_keep_children(sample_metadata(), data_dir, scratch)
|
|
174
|
+
|
|
175
|
+
again = tmp_path / "again"
|
|
176
|
+
again.mkdir()
|
|
177
|
+
project.assert_parent_rebuilds_keep_children(
|
|
178
|
+
sample_metadata(),
|
|
179
|
+
tmp_path / "data2",
|
|
180
|
+
again,
|
|
181
|
+
extra_rows={"owners": [{"id": 2, "name": "second"}]},
|
|
182
|
+
overrides={"notes": {"owner_id": 2}},
|
|
183
|
+
)
|
|
184
|
+
|
|
156
185
|
def test_needs_a_table_that_something_points_at(self, data_dir: Path, tmp_path: Path) -> None:
|
|
157
186
|
metadata = MetaData()
|
|
158
187
|
Table("alone", metadata, Column("id", Integer, primary_key=True))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|