|
10 | 10 | import shutil |
11 | 11 | import pytest |
12 | 12 | import re |
| 13 | +import requests |
| 14 | +import time |
13 | 15 |
|
14 | 16 | from .helpers import ( |
15 | 17 | execute_tutor_command, |
@@ -145,3 +147,75 @@ def test_build_tokens_with_source_tokens_only(): |
145 | 147 | assert not os.path.exists( |
146 | 148 | utility_classes_css |
147 | 149 | ), 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