test(alerts): commit the test user before the rule's created_by FK
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -61,11 +61,13 @@ def test_firing_triggers_ansible_action(app, tmp_path):
|
|||||||
|
|
||||||
async def _go():
|
async def _go():
|
||||||
async with app.db_sessionmaker() as s:
|
async with app.db_sessionmaker() as s:
|
||||||
|
# User must be committed before the rule's created_by FK can reference it.
|
||||||
async with s.begin():
|
async with s.begin():
|
||||||
s.add(User(
|
s.add(User(
|
||||||
id=uid, username=f"u{uid[:8]}", email=f"{uid[:8]}@e.test",
|
id=uid, username=f"u{uid[:8]}", email=f"{uid[:8]}@e.test",
|
||||||
password_hash="x", role=UserRole.admin, is_active=True,
|
password_hash="x", role=UserRole.admin, is_active=True,
|
||||||
))
|
))
|
||||||
|
async with s.begin():
|
||||||
s.add(AlertRule(
|
s.add(AlertRule(
|
||||||
id=rule_id, name="cpu hot", source_module="host_agent",
|
id=rule_id, name="cpu hot", source_module="host_agent",
|
||||||
resource_name="srv1", metric_name="cpu_pct",
|
resource_name="srv1", metric_name="cpu_pct",
|
||||||
|
|||||||
Reference in New Issue
Block a user