Skip to content

Commit 472a052

Browse files
committed
feat: add integration tests for hosted files
1 parent 43e45ef commit 472a052

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

plugins/tutor-contrib-paragon/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dependencies = [
3030
"tutor>=19.0.0,<20.0.0",
3131
]
3232

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

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

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

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

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

0 commit comments

Comments
 (0)