diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml new file mode 100644 index 0000000..26ca486 --- /dev/null +++ b/.github/workflows/integration-test.yml @@ -0,0 +1,19 @@ +name: Tutor Integration Tests +on: [pull_request] + +jobs: + integration-test: + name: Tutor Integration Tests + runs-on: ubuntu-latest + strategy: + matrix: + tutor_version: ["<17.0.0", "<18.0.0"] + steps: + - uses: actions/checkout@v4 + with: + path: eox-tagging + - uses: eduNEXT/integration-test-in-tutor@main + with: + tutor_version: ${{ matrix.tutor_version }} + app_name: "eox-tagging" + shell_file_to_run: "eox_tagging/test/tutor/integration.sh" diff --git a/eox_tagging/edxapp_wrappers/backends/course_overview_i_v1.py b/eox_tagging/edxapp_wrappers/backends/course_overview_i_v1.py index 316b44a..59cba2d 100644 --- a/eox_tagging/edxapp_wrappers/backends/course_overview_i_v1.py +++ b/eox_tagging/edxapp_wrappers/backends/course_overview_i_v1.py @@ -2,11 +2,10 @@ Backend CourseOverview file, here are all the methods from openedx.core.djangoapps.content.course_overviews. """ +from openedx.core.djangoapps.content.course_overviews.models import \ + CourseOverview # pylint: disable=import-outside-toplevel, import-error def get_course_overview(): """Backend to get course overview.""" - from openedx.core.djangoapps.content.course_overviews.models import \ - CourseOverview # pylint: disable=import-outside-toplevel, import-error - return CourseOverview diff --git a/eox_tagging/edxapp_wrappers/backends/enrollment_l_v1.py b/eox_tagging/edxapp_wrappers/backends/enrollment_l_v1.py index 36d7a34..ccf5386 100644 --- a/eox_tagging/edxapp_wrappers/backends/enrollment_l_v1.py +++ b/eox_tagging/edxapp_wrappers/backends/enrollment_l_v1.py @@ -1,9 +1,9 @@ """ Backend for course enrollments valid for lilac release. """ +from common.djangoapps.student.models import CourseEnrollment # pylint: disable=C0415, E0401 def get_enrollment_object(): """Backend to get course enrollment.""" - from common.djangoapps.student.models import CourseEnrollment # pylint: disable=C0415, E0401 return CourseEnrollment diff --git a/eox_tagging/settings/test.py b/eox_tagging/settings/test.py index c6af13d..fc306d8 100644 --- a/eox_tagging/settings/test.py +++ b/eox_tagging/settings/test.py @@ -3,6 +3,11 @@ """ from __future__ import unicode_literals +import codecs +import os + +import yaml + from .common import * # pylint: disable=wildcard-import, unused-wildcard-import @@ -46,6 +51,13 @@ def plugin_settings(settings): # pylint: disable=function-redefined settings.EOX_TAGGING_GET_ENROLLMENT_OBJECT = "eox_tagging.edxapp_wrappers.backends.enrollment_l_v1_test" settings.TEST_SITE = 1 + # setup the databases used in the tutor local environment + lms_cfg = os.environ.get('LMS_CFG') + if lms_cfg: + with codecs.open(lms_cfg, encoding='utf-8') as file: + env_tokens = yaml.safe_load(file) + settings.DATABASES = env_tokens['DATABASES'] + SETTINGS = SettingsClass() plugin_settings(SETTINGS) diff --git a/eox_tagging/test/tutor/__init__.py b/eox_tagging/test/tutor/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/eox_tagging/test/tutor/conftest.py b/eox_tagging/test/tutor/conftest.py new file mode 100644 index 0000000..cf72ca9 --- /dev/null +++ b/eox_tagging/test/tutor/conftest.py @@ -0,0 +1,16 @@ +""" +The conftest module sets up the database connection for pytest-django. + +The integration tests will reuse the database from tutor local so a noop +django_db_setup is required. +See: https://pytest-django.readthedocs.io/en/latest/database.html +""" + +import pytest # pylint: disable=import-error + + +@pytest.fixture(scope='session') +def django_db_setup(): + """ + Makes the tests reuse the existing database + """ diff --git a/eox_tagging/test/tutor/integration.sh b/eox_tagging/test/tutor/integration.sh new file mode 100644 index 0000000..cdcee9e --- /dev/null +++ b/eox_tagging/test/tutor/integration.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# This script installs the package in the edxapp environment, installs test requirements from Open edX and runs the tests using the Tutor settings +echo "Install package" +pip install -e /openedx/eox-tagging + +echo "Install test-requirements" +make test-requirements + +echo "Install eox-core(requirement)" +pip install eox-core + +python manage.py lms makemigrations +python manage.py lms migrate + +echo "Run tests" +pytest -s --ds=lms.envs.tutor.test /openedx/eox-tagging/eox_tagging/test/tutor diff --git a/eox_tagging/test/tutor/integration_test_tutor.py b/eox_tagging/test/tutor/integration_test_tutor.py new file mode 100644 index 0000000..21ee496 --- /dev/null +++ b/eox_tagging/test/tutor/integration_test_tutor.py @@ -0,0 +1,19 @@ +""" +Test integration file. +""" +from django.test import TestCase + + +class TutorIntegrationTestCase(TestCase): + """ + Tests integration with openedx + """ + + # pylint: disable=import-outside-toplevel,unused-import + def test_current_settings_code_imports(self): + """ + Running this imports means that our backends import the right signature + """ + import eox_tagging.edxapp_wrappers.backends.course_overview_i_v1 # isort:skip + import eox_tagging.edxapp_wrappers.backends.bearer_authentication_i_v1 # isort:skip + import eox_tagging.edxapp_wrappers.backends.enrollment_l_v1 # isort:skip diff --git a/eox_tagging/test/tutor/pytest.ini b/eox_tagging/test/tutor/pytest.ini new file mode 100644 index 0000000..f3b7462 --- /dev/null +++ b/eox_tagging/test/tutor/pytest.ini @@ -0,0 +1,7 @@ +[pytest] +python_files = integration_test_*.py +filterwarnings = + default + # We ignore every warning while we actually get the testing infrastructure + # running for different version of tutor in gh actions + ignore: diff --git a/requirements/test.in b/requirements/test.in index e82e5ae..5bc1225 100644 --- a/requirements/test.in +++ b/requirements/test.in @@ -13,3 +13,4 @@ django-filter django-oauth2-provider djangorestframework-oauth mock +pyyaml