test_oidc_env_startup.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """The env provider is applied on startup, not merely appliable (#2593).
  2. test_oidc_env_apply.py calls apply_env_oidc_provider() directly, so it stays
  3. green even if nothing ever calls it -- deleting the lifespan call would leave
  4. the feature dead with a fully passing suite. These tests pin the call site.
  5. They read the lifespan's source rather than running it: the function is ~460
  6. lines and starts printer connections, MQTT and schedulers, so executing it
  7. here would test everything except the one line in question. That makes this a
  8. wiring check, not a behavioural one -- it proves the call exists and runs
  9. after migrations, and deliberately proves nothing about what it does. The
  10. behaviour is covered by test_oidc_env_apply.py.
  11. """
  12. from __future__ import annotations
  13. import inspect
  14. from backend.app.main import lifespan
  15. def _lifespan_source() -> str:
  16. return inspect.getsource(lifespan)
  17. def test_lifespan_applies_the_env_oidc_provider():
  18. assert "apply_env_oidc_provider(" in _lifespan_source()
  19. def test_it_runs_after_the_migrations():
  20. """is_env_managed does not exist until run_migrations has added it, so an
  21. upsert before init_db() would fail on every existing installation."""
  22. source = _lifespan_source()
  23. assert source.index("await init_db()") < source.index("apply_env_oidc_provider(")
  24. def test_the_apply_call_is_awaited():
  25. """apply_env_oidc_provider is a coroutine; calling it without await would
  26. return an un-awaited coroutine and silently apply nothing."""
  27. source = _lifespan_source()
  28. call = source.index("apply_env_oidc_provider(")
  29. line_start = source.rindex("\n", 0, call) + 1
  30. assert source[line_start:call].strip().endswith("await")