forked from openedx/openedx-tutor-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(tests): add integration tests to tutor paragon plugin #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
380a6fc
feat: add Paragon build-tokens command using tutor custom jobs (#34)
Ang-m4 da690fd
fix: update paragon build command options (#37)
Ang-m4 c101d38
feat(tests): add integration test helpers and fixtures for Tutor Para…
Ang-m4 b141df0
feat(tests): add integration tests for Tutor Paragon plugin setup
Ang-m4 0b6f538
feat(tests): add integration tests for Tutor Paragon plugin functiona…
Ang-m4 363a0cf
feat(tests): update Makefile to include integration tests
Ang-m4 0c28171
feat(tests): add pytest-order and enhance error logging in command ex…
Ang-m4 af0ab37
feat(tests): enhance integration tests and add cleanup fixture for co…
Ang-m4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
35 changes: 35 additions & 0 deletions
35
plugins/tutor-contrib-paragon/tests/integration/conftest.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| """Common fixtures for integration tests.""" | ||
|
|
||
| import pytest | ||
| import subprocess | ||
|
|
||
| from .helpers import PARAGON_NAME, PARAGON_IMAGE | ||
|
|
||
|
|
||
| @pytest.fixture(scope="package", autouse=True) | ||
| def setup_tutor_paragon_plugin(): | ||
| """ | ||
| Fixture to set up the Tutor Paragon plugin for integration tests. | ||
| This fixture enables the Paragon plugin, builds the necessary Docker image, | ||
| and ensures that the plugin is disabled after the tests are complete. | ||
| """ | ||
|
|
||
| subprocess.run( | ||
| ["tutor", "plugins", "enable", PARAGON_NAME], | ||
| check=True, | ||
| capture_output=True, | ||
| ) | ||
|
|
||
| subprocess.run( | ||
| ["tutor", "images", "build", PARAGON_IMAGE], | ||
| check=True, | ||
| capture_output=True, | ||
| ) | ||
|
|
||
| yield | ||
|
|
||
| subprocess.run( | ||
| ["tutor", "plugins", "disable", PARAGON_NAME], | ||
| check=True, | ||
| capture_output=True, | ||
| ) |
54 changes: 54 additions & 0 deletions
54
plugins/tutor-contrib-paragon/tests/integration/helpers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| """Helper functions for integration tests of Paragon plugin.""" | ||
|
|
||
| import subprocess | ||
| import logging | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| PARAGON_NAME = "paragon" | ||
| PARAGON_IMAGE = "paragon-builder" | ||
| PARAGON_JOB = "paragon-build-tokens" | ||
| PARAGON_THEME_SOURCES_FOLDER = "env/plugins/paragon/theme-sources" | ||
| PARAGON_COMPILED_THEMES_FOLDER = "env/plugins/paragon/compiled-themes" | ||
|
|
||
|
|
||
| def execute_tutor_command(command: list[str]): | ||
| """Run a Tutor command and return the result. | ||
|
|
||
| Args: | ||
| command (list[str]): List of Tutor args, without the 'tutor' prefix. | ||
|
|
||
| Returns: | ||
| subprocess.CompletedProcess: Contains stdout, stderr, returncode. | ||
| """ | ||
| full_command = ["tutor"] + command | ||
| result = subprocess.run( | ||
| full_command, | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, | ||
| text=True, | ||
| check=False, | ||
| ) | ||
|
|
||
| if result.returncode != 0: | ||
| logger.error("Command failed: %s", " ".join(full_command)) | ||
| logger.error("stderr: %s", result.stderr.strip()) | ||
|
|
||
| return result | ||
|
|
||
|
|
||
| def get_tutor_root_path(): | ||
| """Get the root path of the Tutor project. | ||
|
|
||
| Raises: | ||
| RuntimeError: If the Tutor root path cannot be obtained. | ||
|
|
||
| Returns: | ||
| str: The path to the Tutor root directory. | ||
| """ | ||
| result = execute_tutor_command(["config", "printroot"]) | ||
|
|
||
| if result.returncode != 0: | ||
| raise RuntimeError("Failed to get Tutor root path: " + result.stderr) | ||
|
|
||
| return result.stdout.strip() | ||
147 changes: 147 additions & 0 deletions
147
plugins/tutor-contrib-paragon/tests/integration/plugin_functionality_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| """ | ||
| Integration tests for the Tutor Paragon plugin functionality. | ||
|
|
||
| This module contains tests to verify that the Paragon plugin for Tutor | ||
| is functioning correctly, including building tokens with and without options, | ||
| and handling invalid flags or parameters. | ||
| """ | ||
|
|
||
| import os | ||
| import shutil | ||
| import pytest | ||
| import re | ||
|
|
||
| from .helpers import ( | ||
| execute_tutor_command, | ||
| get_tutor_root_path, | ||
| PARAGON_JOB, | ||
| PARAGON_COMPILED_THEMES_FOLDER, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def clear_compiled_themes_folder(): | ||
| """ | ||
| Fixture to clear the PARAGON_COMPILED_THEMES_FOLDER after each test. | ||
| """ | ||
| yield | ||
| tutor_root = get_tutor_root_path() | ||
| compiled_path = os.path.join(tutor_root, PARAGON_COMPILED_THEMES_FOLDER) | ||
| if os.path.exists(compiled_path): | ||
| shutil.rmtree(compiled_path) | ||
|
|
||
|
|
||
| @pytest.mark.order(1) | ||
| def test_build_tokens_without_options(): | ||
| """ | ||
| Verify that running the build-tokens job without additional options | ||
| completes successfully and produces output in the compiled-themes folder. | ||
| """ | ||
|
|
||
| result = execute_tutor_command(["local", "do", PARAGON_JOB]) | ||
| assert result.returncode == 0, f"Error running build-tokens job: {result.stderr}" | ||
|
|
||
| tutor_root = get_tutor_root_path() | ||
| compiled_path = os.path.join(tutor_root, PARAGON_COMPILED_THEMES_FOLDER) | ||
|
|
||
| contents = os.listdir(compiled_path) | ||
| assert contents, f"No files were generated in {compiled_path}." | ||
|
|
||
|
|
||
| @pytest.mark.order(2) | ||
| def test_build_tokens_with_specific_theme(): | ||
| """ | ||
| Verify that running the build-tokens job with the --themes option | ||
| for a specific theme (e.g., 'indigo') produces the expected output. | ||
| """ | ||
| theme = "indigo" | ||
|
|
||
| result = execute_tutor_command(["local", "do", PARAGON_JOB, "--themes", theme]) | ||
| assert result.returncode == 0, f"Error building {theme} theme: {result.stderr}" | ||
|
|
||
| tutor_root = get_tutor_root_path() | ||
| compiled_path = os.path.join(tutor_root, PARAGON_COMPILED_THEMES_FOLDER, "themes") | ||
|
|
||
| entries = os.listdir(compiled_path) | ||
| assert theme in entries, f"'{theme}' theme not found in {compiled_path}." | ||
|
|
||
| theme_path = os.path.join(compiled_path, theme) | ||
| assert os.path.isdir(theme_path), f"Expected {theme_path} to be a directory." | ||
| assert os.listdir(theme_path), f"No files were generated inside {theme_path}." | ||
|
|
||
|
|
||
| @pytest.mark.order(3) | ||
| def test_build_tokens_excluding_core(): | ||
| """ | ||
| Verify that running the build-tokens job with the --exclude-core option | ||
| excludes the core theme from the output. | ||
| """ | ||
| result = execute_tutor_command(["local", "do", PARAGON_JOB, "--exclude-core"]) | ||
| assert result.returncode == 0, f"Error excluding core theme: {result.stderr}" | ||
|
|
||
| tutor_root = get_tutor_root_path() | ||
| compiled_path = os.path.join(tutor_root, PARAGON_COMPILED_THEMES_FOLDER) | ||
|
|
||
| entries = os.listdir(compiled_path) | ||
| assert "core" not in entries, "Core theme should be excluded but was found." | ||
|
|
||
|
|
||
| @pytest.mark.order(4) | ||
| def test_build_tokens_without_output_token_references(): | ||
| """ | ||
| Ensure that when the build-tokens job is run with --output-references=false, | ||
| the generated variables.css file does not contain any CSS variable references (var(--...)). | ||
| """ | ||
| result = execute_tutor_command( | ||
| ["local", "do", PARAGON_JOB, "--output-references=false"] | ||
| ) | ||
| assert ( | ||
| result.returncode == 0 | ||
| ), f"Error running build-tokens with --output-references=false: {result.stderr}" | ||
|
|
||
| tutor_root = get_tutor_root_path() | ||
| compiled_path = os.path.join(tutor_root, PARAGON_COMPILED_THEMES_FOLDER) | ||
|
|
||
| core_variables_css = os.path.join(compiled_path, "core", "variables.css") | ||
| theme_variables_css = os.path.join(compiled_path, "themes", "light", "variables.css") | ||
|
|
||
| assert os.path.exists(core_variables_css), f"{core_variables_css} does not exist." | ||
| assert os.path.exists(theme_variables_css), f"{theme_variables_css} does not exist." | ||
|
|
||
| with open(core_variables_css, "r", encoding="utf-8") as f: | ||
| core_content = f.read() | ||
| with open(theme_variables_css, "r", encoding="utf-8") as f: | ||
| theme_content = f.read() | ||
|
|
||
| token_reference_pattern = re.compile(r"var\(--.*?\)") | ||
| core_references = token_reference_pattern.findall(core_content) | ||
| theme_references = token_reference_pattern.findall(theme_content) | ||
|
|
||
| assert ( | ||
| not core_references | ||
| ), f"{core_variables_css} should not contain token references, but found: {core_references}" | ||
| assert ( | ||
| not theme_references | ||
| ), f"{theme_variables_css} should not contain token references, but found: {theme_references}" | ||
|
|
||
|
|
||
| @pytest.mark.order(5) | ||
| def test_build_tokens_with_source_tokens_only(): | ||
| """ | ||
| Ensure that when the build-tokens job is run with --source-tokens-only, | ||
| the utility-classes.css file is not generated. | ||
| """ | ||
| result = execute_tutor_command(["local", "do", PARAGON_JOB, "--source-tokens-only"]) | ||
| assert ( | ||
| result.returncode == 0 | ||
| ), f"Error running build-tokens with --source-tokens-only: {result.stderr}" | ||
|
|
||
| tutor_root = get_tutor_root_path() | ||
| light_theme_path = os.path.join( | ||
| tutor_root, PARAGON_COMPILED_THEMES_FOLDER, "themes", "light" | ||
| ) | ||
| utility_classes_css = os.path.join(light_theme_path, "utility-classes.css") | ||
|
|
||
| assert not os.path.exists( | ||
| utility_classes_css | ||
| ), f"{utility_classes_css} should not exist when --source-tokens-only is used." |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.