Skip to content

Commit f563de5

Browse files
committed
fix smoke test fail
1 parent aafc901 commit f563de5

5 files changed

Lines changed: 35 additions & 22 deletions

File tree

tests/integration/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import pytest
1414

1515
from tests.integration.lib.docker_exec import docker_exec_python, docker_exec_read_file
16-
from tests.integration.lib.gh_repo import TestRepoManager, default_repo_name
16+
from tests.integration.lib.gh_repo import EphemeralGitHubRepo, default_repo_name
1717
from tests.integration.lib.http import base_url
1818
from tests.integration.lib.weblate_api import WeblateAPI
1919

@@ -55,14 +55,14 @@ def weblate_ssh_pubkey() -> str:
5555

5656

5757
@pytest.fixture(scope="session")
58-
def test_repo(weblate_ssh_pubkey: str) -> TestRepoManager:
58+
def test_repo(weblate_ssh_pubkey: str) -> EphemeralGitHubRepo:
5959
"""Ephemeral GitHub repo with fixture docs and Weblate deploy key."""
6060
token = os.environ.get("GH_TEST_REPO_TOKEN", "").strip()
6161
if not token:
6262
pytest.skip("GH_TEST_REPO_TOKEN is not set")
6363

6464
repo_name = default_repo_name()
65-
manager = TestRepoManager(token, repo_name)
65+
manager = EphemeralGitHubRepo(token, repo_name)
6666
try:
6767
manager.create_repo()
6868
manager.push_fixtures(FIXTURES_DIR, branch=TEST_BRANCH)

tests/integration/lib/docker_exec.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
_PYTHON = "/app/venv/bin/python"
1717

1818

19+
def _weblate_django_preamble() -> str:
20+
"""Weblate format modules need a configured Django app registry."""
21+
return (
22+
"import os; "
23+
'os.environ.setdefault("DJANGO_SETTINGS_MODULE", "weblate.settings_docker"); '
24+
"import django; "
25+
"django.setup(); "
26+
)
27+
28+
1929
def _compose_cmd(*args: str) -> list[str]:
2030
return [
2131
"docker",
@@ -28,10 +38,12 @@ def _compose_cmd(*args: str) -> list[str]:
2838
]
2939

3040

31-
def docker_exec_python(snippet: str) -> str:
41+
def docker_exec_python(snippet: str, *, timeout: float = 120.0) -> str:
3242
"""Run a Python snippet in the weblate container; return stdout (stripped)."""
43+
code = _weblate_django_preamble() + snippet
3344
result = subprocess.run(
34-
_compose_cmd("exec", "-T", "weblate", _PYTHON, "-c", snippet),
45+
_compose_cmd("exec", "-T", "weblate", _PYTHON, "-c", code),
46+
timeout=timeout,
3547
capture_output=True,
3648
text=True,
3749
check=False,
@@ -45,9 +57,9 @@ def docker_exec_python(snippet: str) -> str:
4557
return result.stdout.strip()
4658

4759

48-
def docker_exec_python_json(snippet: str) -> Any:
60+
def docker_exec_python_json(snippet: str, *, timeout: float = 120.0) -> Any:
4961
"""Run a Python snippet and parse stdout as JSON."""
50-
return json.loads(docker_exec_python(snippet))
62+
return json.loads(docker_exec_python(snippet, timeout=timeout))
5163

5264

5365
def docker_exec_read_file(path: str) -> str:

tests/integration/lib/gh_repo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ def _api_error_message(method: str, path: str, code: int, raw: bytes) -> str:
2222
return f"GitHub API {method} {path} failed: {code} {body}"
2323

2424

25-
class TestRepoManager:
25+
class EphemeralGitHubRepo:
2626
"""Create, populate, and destroy a temporary GitHub repo for integration tests."""
2727

28+
__test__ = False # not a pytest test class
29+
2830
def __init__(self, token: str, repo_name: str) -> None:
2931
self.token = token
3032
self.repo_name = repo_name

tests/integration/lib/weblate_api.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ def create_project(self, name: str, slug: str | None = None) -> dict[str, Any]:
6767
"POST",
6868
"/api/projects/",
6969
token=self.token,
70-
body={"name": name, "slug": slug},
70+
body={
71+
"name": name,
72+
"slug": slug,
73+
"web": f"{self._base}/",
74+
},
7175
)
7276
assert code == 200, f"create_project failed: {code} {body}"
7377
assert isinstance(body, dict)
@@ -225,13 +229,8 @@ def poll_celery_task(
225229
deadline = time.monotonic() + timeout
226230
snippet_template = """
227231
import json
228-
import os
229232
import time
230233
231-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "weblate.settings_docker")
232-
import django
233-
django.setup()
234-
235234
from celery.result import AsyncResult
236235
from weblate.utils.celery import app
237236
@@ -260,7 +259,7 @@ def poll_celery_task(
260259
interval=interval,
261260
)
262261
try:
263-
out = docker_exec_python(snippet)
262+
out = docker_exec_python(snippet, timeout=timeout)
264263
data = json.loads(out)
265264
return data.get("result")
266265
except (RuntimeError, json.JSONDecodeError, TimeoutError) as exc:

tests/integration/test_functional.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
TEST_LANG_CODE,
2121
TEST_VERSION,
2222
)
23-
from tests.integration.lib.gh_repo import TestRepoManager
23+
from tests.integration.lib.gh_repo import EphemeralGitHubRepo
2424
from tests.integration.lib.http import http_json
2525
from tests.integration.lib.weblate_api import WeblateAPI
2626

@@ -115,7 +115,7 @@ class TestBoostComponentServiceE2E:
115115

116116
@staticmethod
117117
def _service_snippet(
118-
test_repo: TestRepoManager,
118+
test_repo: EphemeralGitHubRepo,
119119
*,
120120
run_process_all: bool = False,
121121
run_twice: bool = False,
@@ -185,7 +185,7 @@ def _service_snippet(
185185
print(json.dumps(out))
186186
"""
187187

188-
def test_clone_and_scan(self, exec_python, test_repo: TestRepoManager) -> None:
188+
def test_clone_and_scan(self, exec_python, test_repo: EphemeralGitHubRepo) -> None:
189189
out = json.loads(
190190
exec_python(self._service_snippet(test_repo, run_process_all=False))
191191
)
@@ -195,7 +195,7 @@ def test_clone_and_scan(self, exec_python, test_repo: TestRepoManager) -> None:
195195
assert any(c["format"] == "asciidoc" for c in out["configs"])
196196

197197
def test_project_component_creation(
198-
self, exec_python, test_repo: TestRepoManager
198+
self, exec_python, test_repo: EphemeralGitHubRepo
199199
) -> None:
200200
"""Direct process_all on a DB with no prior components for this repo."""
201201
out = json.loads(
@@ -220,7 +220,7 @@ def test_project_component_creation(
220220
)
221221
assert check == "ok"
222222

223-
def test_idempotency(self, exec_python, test_repo: TestRepoManager) -> None:
223+
def test_idempotency(self, exec_python, test_repo: EphemeralGitHubRepo) -> None:
224224
out = json.loads(
225225
exec_python(
226226
self._service_snippet(test_repo, run_process_all=True, run_twice=True)
@@ -239,7 +239,7 @@ class TestAddOrUpdateCeleryFlow:
239239
"""POST /boost-endpoint/add-or-update/ and poll Celery completion."""
240240

241241
def test_add_or_update_returns_202(
242-
self, api_token: str, test_repo: TestRepoManager
242+
self, api_token: str, test_repo: EphemeralGitHubRepo
243243
) -> None:
244244
owner = test_repo.resolve_owner()
245245
body = {
@@ -260,7 +260,7 @@ def test_add_or_update_returns_202(
260260
type(self).task_id = str(data["task_id"])
261261

262262
def test_add_or_update_task_completes(
263-
self, weblate_api: WeblateAPI, test_repo: TestRepoManager
263+
self, weblate_api: WeblateAPI, test_repo: EphemeralGitHubRepo
264264
) -> None:
265265
task_id = getattr(self, "task_id", None)
266266
if not task_id:

0 commit comments

Comments
 (0)