|
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, |
| 18 | + get_config_value, |
16 | 19 | get_tutor_root_path, |
17 | 20 | PARAGON_JOB, |
18 | 21 | PARAGON_COMPILED_THEMES_FOLDER, |
@@ -145,3 +148,68 @@ def test_build_tokens_with_source_tokens_only(): |
145 | 148 | assert not os.path.exists( |
146 | 149 | utility_classes_css |
147 | 150 | ), 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