diff --git a/.github/workflows/integration-test.yaml b/.github/workflows/integration-test.yaml index c169664..0c6aeb4 100644 --- a/.github/workflows/integration-test.yaml +++ b/.github/workflows/integration-test.yaml @@ -27,18 +27,27 @@ jobs: LMS_HOST=local.edly.io CMS_HOST=studio.local.edly.io TUTOR_ROOT=$(pwd) + COURSE_KEY=course-v1:MITx+grading-library+course EOF shell: bash - - name: Install and prepare Tutor, Codejail and tests + - name: Install Tutor + run: pip install "tutor${{ matrix.tutor_version }}" + shell: bash + + - name: Install, enable and initialize Tutor Codejail Plugin run: | - pip install "tutor${{ matrix.tutor_version }}" pip install git+https://github.com/edunext/tutor-contrib-codejail - tutor config save tutor plugins enable codejail tutor local do init --limit codejail - tutor mounts add cms:mitx-grading-library/integration_tests/integration_test.py:/openedx/edx-platform/integration_test.py - tutor local launch -I + shell: bash + + - name: Mount Integration Test + run: tutor mounts add cms:mitx-grading-library/integration_tests/integration_test.py:/openedx/edx-platform/integration_test.py + shell: bash + + - name: Launch Tutor + run: tutor local launch -I shell: bash - name: Import MITx Demo Course @@ -48,5 +57,5 @@ jobs: - name: Run integration tests run: | - tutor local run cms python3 integration_test.py + tutor local run cms python integration_test.py "$COURSE_KEY" shell: bash diff --git a/integration_tests/integration_test.py b/integration_tests/integration_test.py index 6ee7ac0..dcd5ee7 100644 --- a/integration_tests/integration_test.py +++ b/integration_tests/integration_test.py @@ -4,13 +4,15 @@ to be able to use the python_lib.zip that contains the library. """ +import logging import os +import sys + import django -import logging +from opaque_keys.edx.keys import CourseKey from xmodule.capa.safe_exec import safe_exec -from xmodule.util.sandboxing import SandboxService from xmodule.contentstore.django import contentstore -from opaque_keys.edx.keys import CourseKey +from xmodule.util.sandboxing import SandboxService # Set up Django environment os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cms.envs.test") @@ -19,7 +21,7 @@ log = logging.getLogger(__name__) # Define the code to be executed -all_code = """ +GRADING_CLASSES_CODE = """ from mitxgraders import * # Grading Classes @@ -91,12 +93,11 @@ """ -def execute_code(all_code, course_key_str): +def execute_code(course_key_str): """ Executes the provided code in a sandboxed environment with the specified course context. Args: - all_code (str): The code to be executed. course_key_str (str): The string representation of the course key. Returns: @@ -105,7 +106,8 @@ def execute_code(all_code, course_key_str): course_key = CourseKey.from_string(course_key_str) sandbox_service = SandboxService( course_id=course_key, - contentstore=contentstore) + contentstore=contentstore + ) zip_lib = sandbox_service.get_python_lib_zip() extra_files = [] @@ -116,7 +118,7 @@ def execute_code(all_code, course_key_str): python_path.append("python_lib.zip") safe_exec( - all_code, + all_code=GRADING_CLASSES_CODE, globals_dict={}, python_path=python_path, extra_files=extra_files, @@ -127,5 +129,9 @@ def execute_code(all_code, course_key_str): if __name__ == "__main__": - course_key_str = "course-v1:MITx+grading-library+course" - execute_code(all_code, course_key_str) + if len(sys.argv) != 2: + print("Usage: python integration_test.py ") + sys.exit(1) + + course_key_str = sys.argv[1] + execute_code(course_key_str)