|
| 1 | +""" |
| 2 | +Integration tests for the Tutor Paragon plugin functionality. |
| 3 | +
|
| 4 | +This module contains tests to verify that the Paragon plugin for Tutor |
| 5 | +is functioning correctly, including building tokens with and without options, |
| 6 | +and handling invalid flags or parameters. |
| 7 | +""" |
| 8 | + |
| 9 | +import pytest |
| 10 | +import os |
| 11 | +import shutil |
| 12 | + |
| 13 | +from .helpers import ( |
| 14 | + execute_tutor_command, |
| 15 | + get_tutor_root_path, |
| 16 | + PARAGON_JOB, |
| 17 | + PARAGON_COMPILED_THEMES_FOLDER, |
| 18 | +) |
| 19 | + |
| 20 | + |
| 21 | +@pytest.fixture(autouse=True) |
| 22 | +def clean_compiled_themes_folder(): |
| 23 | + """ |
| 24 | + Ensure the compiled-themes folder is empty before each test. |
| 25 | + """ |
| 26 | + tutor_root = get_tutor_root_path() |
| 27 | + compiled_path = os.path.join(tutor_root, PARAGON_COMPILED_THEMES_FOLDER) |
| 28 | + |
| 29 | + if os.path.isdir(compiled_path): |
| 30 | + shutil.rmtree(compiled_path) |
| 31 | + |
| 32 | + os.makedirs(compiled_path, exist_ok=True) |
| 33 | + |
| 34 | + |
| 35 | +def test_build_tokens_without_options(): |
| 36 | + """ |
| 37 | + Verify that running the build-tokens job without additional options |
| 38 | + completes successfully and produces output in the compiled-themes folder. |
| 39 | + """ |
| 40 | + |
| 41 | + result = execute_tutor_command(["local", "do", PARAGON_JOB]) |
| 42 | + assert result.returncode == 0, f"Error running build-tokens job: {result.stderr}" |
| 43 | + |
| 44 | + tutor_root = get_tutor_root_path() |
| 45 | + compiled_path = os.path.join(tutor_root, PARAGON_COMPILED_THEMES_FOLDER) |
| 46 | + |
| 47 | + contents = os.listdir(compiled_path) |
| 48 | + assert contents, f"No files were generated in {compiled_path}." |
| 49 | + |
| 50 | + |
| 51 | +def test_build_tokens_with_specific_theme(): |
| 52 | + """ |
| 53 | + Verify that running the build-tokens job with the --themes option |
| 54 | + for a specific theme (e.g., 'indigo') produces the expected output. |
| 55 | + """ |
| 56 | + theme = "indigo" |
| 57 | + |
| 58 | + result = execute_tutor_command(["local", "do", PARAGON_JOB, "--themes", theme]) |
| 59 | + assert result.returncode == 0, f"Error building {theme} theme: {result.stderr}" |
| 60 | + |
| 61 | + tutor_root = get_tutor_root_path() |
| 62 | + compiled_path = os.path.join(tutor_root, PARAGON_COMPILED_THEMES_FOLDER, "themes") |
| 63 | + |
| 64 | + entries = os.listdir(compiled_path) |
| 65 | + assert theme in entries, f"'{theme}' theme not found in {compiled_path}." |
| 66 | + |
| 67 | + theme_path = os.path.join(compiled_path, theme) |
| 68 | + assert os.path.isdir(theme_path), f"Expected {theme_path} to be a directory." |
| 69 | + assert os.listdir(theme_path), f"No files were generated inside {theme_path}." |
| 70 | + |
| 71 | + |
| 72 | +def test_build_tokens_with_invalid_flag_or_parameter(): |
| 73 | + """ |
| 74 | + Verify that running the build-tokens job with an invalid flag or parameter |
| 75 | + returns a non-zero exit code and does not produce any files. |
| 76 | + """ |
| 77 | + result = execute_tutor_command(["local", "do", PARAGON_JOB, "--invalid-flag"]) |
| 78 | + assert ( |
| 79 | + result.returncode != 0 |
| 80 | + ), "Expected non-zero return code when using an invalid flag." |
| 81 | + |
| 82 | + tutor_root = get_tutor_root_path() |
| 83 | + compiled_path = os.path.join(tutor_root, PARAGON_COMPILED_THEMES_FOLDER) |
| 84 | + |
| 85 | + contents = os.listdir(compiled_path) |
| 86 | + assert not contents, f"Expected no files in {compiled_path} after invalid command." |
0 commit comments