Skip to content

Commit 3a4dbd3

Browse files
committed
feat: add integration tests for hosted files
1 parent 218879c commit 3a4dbd3

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

plugins/tutor-contrib-paragon/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dependencies = [
3131
"tutor-mfe @ git+https://github.com/overhangio/tutor-mfe.git@release",
3232
]
3333

34-
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"] }
3535

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

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,14 @@ def get_tutor_root_path():
5353
raise RuntimeError("Failed to get Tutor root path: " + result.stderr)
5454

5555
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: 68 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,68 @@ 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 = "apps.local.openedx.io"
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+
content_type = response.headers.get("Content-Type", "")
210+
assert "text/css" in content_type.lower(), (
211+
f"Expected 'text/css' Content-Type for {url}, but got '{content_type}'."
212+
)
213+
214+
finally:
215+
execute_tutor_command(["local", "stop", "caddy", "mfe"])

0 commit comments

Comments
 (0)