Skip to content

Commit 8c93f26

Browse files
committed
feat: add integration test for hosted files
1 parent 5f5f5fe commit 8c93f26

File tree

4 files changed

+80
-4
lines changed

4 files changed

+80
-4
lines changed

plugins/tutor-contrib-paragon/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ classifiers = [
2828
]
2929
dependencies = [
3030
"tutor>=19.0.0,<21.0.0",
31+
"tutor-mfe>=19.0.0,<21.0.0",
3132
]
3233

33-
optional-dependencies = { dev = ["tutor[dev]>=19.0.0,<21.0.0", "pytest>=8.3.4", "pytest-order>=1.3.0"] }
34+
optional-dependencies = { dev = ["tutor[dev]>=19.0.0,<21.0.0", "pytest>=8.3.4", "pytest-order>=1.3.0", "requests>=2.32.2"] }
3435

3536
# These fields will be set by hatch_build.py
3637
dynamic = ["version"]

plugins/tutor-contrib-paragon/tests/integration/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44
import subprocess
55

6-
from .helpers import PARAGON_NAME, PARAGON_IMAGE
6+
from .helpers import PARAGON_NAME, PARAGON_IMAGE, PARAGON_HOSTING_SERVICE
77

88

99
@pytest.fixture(scope="package", autouse=True)
@@ -15,7 +15,7 @@ def setup_tutor_paragon_plugin():
1515
"""
1616

1717
subprocess.run(
18-
["tutor", "plugins", "enable", PARAGON_NAME],
18+
["tutor", "plugins", "enable", PARAGON_NAME, PARAGON_HOSTING_SERVICE],
1919
check=True,
2020
capture_output=True,
2121
)
@@ -29,7 +29,7 @@ def setup_tutor_paragon_plugin():
2929
yield
3030

3131
subprocess.run(
32-
["tutor", "plugins", "disable", PARAGON_NAME],
32+
["tutor", "plugins", "disable", PARAGON_NAME, PARAGON_HOSTING_SERVICE],
3333
check=True,
3434
capture_output=True,
3535
)

plugins/tutor-contrib-paragon/tests/integration/helpers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
PARAGON_NAME = "paragon"
99
PARAGON_IMAGE = "paragon-builder"
1010
PARAGON_JOB = "paragon-build-tokens"
11+
PARAGON_HOSTING_SERVICE = "mfe"
1112
PARAGON_THEME_SOURCES_FOLDER = "env/plugins/paragon/theme-sources"
1213
PARAGON_COMPILED_THEMES_FOLDER = "env/plugins/paragon/compiled-themes"
1314

@@ -52,3 +53,14 @@ def get_tutor_root_path():
5253
raise RuntimeError("Failed to get Tutor root path: " + result.stderr)
5354

5455
return result.stdout.strip()
56+
57+
58+
def get_config_value(key: str) -> str:
59+
"""Get a configuration value from Tutor.
60+
61+
Returns:
62+
str: The value of the configuration key.
63+
"""
64+
result = execute_tutor_command(["config", "printvalue", key])
65+
assert result.returncode == 0, f"Error getting {key}: {result.stderr}"
66+
return result.stdout.strip()

plugins/tutor-contrib-paragon/tests/integration/plugin_functionality_test.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
import shutil
1111
import pytest
1212
import re
13+
import requests
14+
import time
1315

1416
from .helpers import (
1517
execute_tutor_command,
18+
get_config_value,
1619
get_tutor_root_path,
1720
PARAGON_JOB,
1821
PARAGON_COMPILED_THEMES_FOLDER,
@@ -145,3 +148,63 @@ def test_build_tokens_with_source_tokens_only():
145148
assert not os.path.exists(
146149
utility_classes_css
147150
), f"{utility_classes_css} should not exist when --source-tokens-only is used."
151+
152+
153+
@pytest.mark.order(6)
154+
def test_build_tokens_generates_minified_bundle():
155+
"""
156+
Ensure that the build-tokens job generates the minified bundle files for hosting.
157+
"""
158+
theme = "light"
159+
result = execute_tutor_command(["local", "do", PARAGON_JOB, "--themes", theme])
160+
assert result.returncode == 0, f"Error running build-tokens job: {result.stderr}"
161+
162+
tutor_root = get_tutor_root_path()
163+
compiled_path = os.path.join(tutor_root, PARAGON_COMPILED_THEMES_FOLDER)
164+
165+
minified_theme_bundle = os.path.join(
166+
compiled_path, "themes", theme, f"{theme}.min.css"
167+
)
168+
minified_core_bundle = os.path.join(compiled_path, "core", "core.min.css")
169+
170+
assert os.path.exists(
171+
minified_core_bundle
172+
), f"Minified core bundle file {minified_core_bundle} does not exist."
173+
assert os.path.exists(
174+
minified_theme_bundle
175+
), f"Minified theme bundle file {minified_theme_bundle} does not exist."
176+
177+
178+
@pytest.mark.order(7)
179+
def test_build_tokens_hosted_files():
180+
"""
181+
Verify that the compiled themes can be served through the tutor-mfe service.
182+
183+
This test builds tokens, starts the required services, and checks that the
184+
static files are accessible via HTTP requests.
185+
"""
186+
result = execute_tutor_command(["local", "do", PARAGON_JOB])
187+
assert result.returncode == 0, f"Error running build-tokens job: {result.stderr}"
188+
189+
static_url_prefix = get_config_value("PARAGON_STATIC_URL_PREFIX").lstrip("/")
190+
mfe_host = get_config_value("MFE_HOST")
191+
192+
services_result = execute_tutor_command(["local", "start", "-d", "caddy", "mfe"])
193+
assert services_result.returncode == 0, "Error starting hosting services"
194+
195+
time.sleep(1)
196+
197+
try:
198+
base_url = f"http://{mfe_host}/{static_url_prefix}"
199+
test_files = ["core/core.min.css", "themes/light/light.min.css"]
200+
201+
for test_file in test_files:
202+
url = f"{base_url}{test_file}"
203+
response = requests.get(url, timeout=2)
204+
205+
assert (
206+
response.status_code == 200
207+
), f"Expected status 200 for {url}, but got {response.status_code}. "
208+
209+
finally:
210+
execute_tutor_command(["local", "stop", "caddy", "mfe"])

0 commit comments

Comments
 (0)