4
0

test_quota_docker_runtime.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. """Focused Docker-runtime regression tests for quota file synchronization."""
  2. from types import SimpleNamespace
  3. from services.quota import quota_service
  4. def test_blocked_user_copy_uses_selected_docker_container(monkeypatch):
  5. """Do not send quota state to the legacy hard-coded squid_proxy name."""
  6. calls = []
  7. runtime = SimpleNamespace(
  8. kind="docker",
  9. executable="/usr/bin/docker",
  10. container_name="configured-squid",
  11. )
  12. def fake_run(command, **kwargs):
  13. calls.append((command, kwargs))
  14. monkeypatch.setattr(quota_service, "_find_squid_runtime", lambda: runtime)
  15. monkeypatch.setattr(quota_service.subprocess, "run", fake_run)
  16. assert quota_service._sync_blocked_file_to_docker(
  17. "/etc/squid/usuarios_bloqueados.txt"
  18. )
  19. assert calls == [
  20. (
  21. [
  22. "/usr/bin/docker",
  23. "cp",
  24. "/etc/squid/usuarios_bloqueados.txt",
  25. "configured-squid:/etc/squid/usuarios_bloqueados.txt",
  26. ],
  27. {"check": True, "capture_output": True, "timeout": 10},
  28. )
  29. ]
  30. def test_blocked_user_copy_does_not_target_docker_for_local_runtime(monkeypatch):
  31. """A local runtime must not mutate an unrelated Docker container."""
  32. runtime = SimpleNamespace(
  33. kind="local", executable="/usr/sbin/squid", container_name=None
  34. )
  35. monkeypatch.setattr(quota_service, "_find_squid_runtime", lambda: runtime)
  36. monkeypatch.setattr(
  37. quota_service.subprocess,
  38. "run",
  39. lambda *_args, **_kwargs: (_ for _ in ()).throw(AssertionError("must not run")),
  40. )
  41. assert not quota_service._sync_blocked_file_to_docker(
  42. "/etc/squid/usuarios_bloqueados.txt"
  43. )