diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml new file mode 100644 index 00000000..c43f0bbc --- /dev/null +++ b/.github/workflows/integration.yml @@ -0,0 +1,33 @@ +name: Integration Tests Quince, Palm + +on: + push: + branches: + - 'fmo/**' + +jobs: + edx-platform-integration-test: + name: Integration with Tutor + strategy: + matrix: # quince palm olive + # tutor_version: ["<18.0.0", "<17.0.0", "<16.0.0"] + tutor_version: ["<18.0.0", "<17.0.0"] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + path: eox-tenant + + - name: Prepare Tutor & launch + run: | + pip install "tutor${{ matrix.tutor_version }}" + TUTOR_ROOT="$(pwd)" tutor --version + TUTOR_ROOT="$(pwd)" tutor config save + TUTOR_ROOT="$(pwd)" tutor mounts add lms,cms,lms-worker,cms-worker:$(pwd)/eox-tenant:/openedx/eox-tenant + chmod 777 . -R + TUTOR_ROOT="$(pwd)" tutor local launch -I + + - name: Run integration tests in lms + run: | + TUTOR_ROOT="$(pwd)" tutor local run lms bash /openedx/eox-tenant/eox_tenant/test/tutor/integration.sh diff --git a/.github/workflows/integration_tutor_nightly.yml b/.github/workflows/integration_tutor_nightly.yml new file mode 100644 index 00000000..b12382d7 --- /dev/null +++ b/.github/workflows/integration_tutor_nightly.yml @@ -0,0 +1,45 @@ +name: Integration Tests with openedx.master + +on: + push: + branches: + - 'fmo/**' + +jobs: + edx-platform-integration-test: + name: Integration with Tutor nightly + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + path: eox-tenant + + - name: Get Tutor + run: | + pip install virtualenv + virtualenv venv + source venv/bin/activate + git clone --branch=nightly --depth=1 https://github.com/overhangio/tutor.git + chmod 777 tutor -R + pip install -e "./tutor[full]" + + - name: Prepare Tutor + run: | + source venv/bin/activate + TUTOR_ROOT="$(pwd)" tutor --version + TUTOR_ROOT="$(pwd)" tutor config save + TUTOR_ROOT="$(pwd)" tutor plugins disable mfe + TUTOR_ROOT="$(pwd)" tutor mounts add lms,cms,lms-worker,cms-worker:$(pwd)/eox-tenant:/openedx/eox-tenant + chmod 777 . -R + TUTOR_ROOT="$(pwd)" tutor images build openedx # ~11 min + + - name: Launch Tutor + run: | + source venv/bin/activate + TUTOR_ROOT="$(pwd)" tutor local launch -I + + - name: Run integration tests in lms + run: | + source venv/bin/activate + TUTOR_ROOT="$(pwd)" tutor local run lms bash /openedx/eox-tenant/eox_tenant/test/tutor/integration.sh diff --git a/eox_tenant/settings/test.py b/eox_tenant/settings/test.py index b4a9f1f5..c984e892 100644 --- a/eox_tenant/settings/test.py +++ b/eox_tenant/settings/test.py @@ -3,6 +3,11 @@ """ from __future__ import absolute_import, unicode_literals +import codecs +import os + +import yaml + from .common import * # pylint: disable=wildcard-import,unused-wildcard-import @@ -90,3 +95,8 @@ def plugin_settings(settings): # pylint: disable=function-redefined settings.OAUTH2_PROVIDER['OAUTH2_VALIDATOR_CLASS'] = ( 'openedx.core.djangoapps.oauth_dispatch.dot_overrides.validators.EdxOAuth2Validator' ) + + # setup the databases used in the tutor local environment + with codecs.open(os.environ['LMS_CFG'], encoding='utf-8') as f: + env_tokens = yaml.safe_load(f) + settings.DATABASES = env_tokens['DATABASES'] diff --git a/eox_tenant/tenant_aware_functions/enrollments.py b/eox_tenant/tenant_aware_functions/enrollments.py index b7e1f794..06a66aa9 100644 --- a/eox_tenant/tenant_aware_functions/enrollments.py +++ b/eox_tenant/tenant_aware_functions/enrollments.py @@ -18,8 +18,7 @@ def filter_enrollments(enrollments): # If test setting is true, returns the same enrollments, # or if we do not have a microsite context, there is nothing we can do. if test_skip or not theming_helpers.is_request_in_themed_site(): - for enrollment in enrollments: - yield enrollment + yield from enrollments return configuration_helpers = get_configuration_helpers() diff --git a/eox_tenant/test/tutor/__init__.py b/eox_tenant/test/tutor/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/eox_tenant/test/tutor/conftest.py b/eox_tenant/test/tutor/conftest.py new file mode 100644 index 00000000..cf72ca93 --- /dev/null +++ b/eox_tenant/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_tenant/test/tutor/integration.sh b/eox_tenant/test/tutor/integration.sh new file mode 100755 index 00000000..24857972 --- /dev/null +++ b/eox_tenant/test/tutor/integration.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# install the package in the edxapp env +echo "Install package" +pip install -e ../eox-tenant + +# test that the commands for eox-tenant are being listed at the lms +echo "Tests django commands" +is_command_installed=$(./manage.py lms help | grep eox | wc -l) +if [ $is_command_installed == 0 ] ; then + echo 'package was not installed correctly' + exit -1; +fi + +# run migrations +echo "Run migrations" +./manage.py lms migrate eox_tenant + +# install pytest +echo "Install test-requirements" +make test-requirements + +# running the tests using the tutor settings +echo "Install test-requirements" +pytest -s --ds=lms.envs.tutor.test /openedx/eox-tenant/eox_tenant/test/tutor diff --git a/eox_tenant/test/tutor/integration_test_tutor.py b/eox_tenant/test/tutor/integration_test_tutor.py new file mode 100644 index 00000000..8dce3585 --- /dev/null +++ b/eox_tenant/test/tutor/integration_test_tutor.py @@ -0,0 +1,35 @@ +""" +Test views file. +""" +from django.test import TestCase + + +class TutorIntegrationTestCase(TestCase): + """ + POC code to run tests that cover the integration with openedx + """ + + def test_runs_code(self): + """ + Just to make sure our test infrastructure is behaving + """ + assert True + + # 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_tenant.edxapp_wrapper.backends.oauth_dispatch_j_v1 # isort:skip + import eox_tenant.edxapp_wrapper.backends.branding_api_l_v1 # isort:skip + # fixme: needs to be properly removed if unused at the latest version # pylint: disable=fixme + # import eox_tenant.edxapp_wrapper.backends.certificates_module_i_v1 + import eox_tenant.edxapp_wrapper.backends.site_configuration_module_i_v1 # isort:skip + import eox_tenant.edxapp_wrapper.backends.theming_helpers_h_v1 # isort:skip + # fixme: needs to be properly removed if unused at the latest version # pylint: disable=fixme + # import eox_tenant.edxapp_wrapper.backends.edx_auth_i_v1 + import eox_tenant.edxapp_wrapper.backends.users_l_v1 # isort:skip + import eox_tenant.edxapp_wrapper.backends.bearer_authentication_l_v1 # isort:skip + import eox_tenant.edxapp_wrapper.backends.edxmako_l_v1 # isort:skip + # fixme: needs to be properly removed if unused at the latest version # pylint: disable=fixme + # import eox_tenant.edxapp_wrapper.backends.util_h_v1 # fixme diff --git a/eox_tenant/test/tutor/pytest.ini b/eox_tenant/test/tutor/pytest.ini new file mode 100644 index 00000000..f3b74624 --- /dev/null +++ b/eox_tenant/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/base.txt b/requirements/base.txt index 458b9bf4..3d719ead 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -8,7 +8,7 @@ asgiref==3.7.2 # via django backports-zoneinfo==0.2.1 # via django -django==4.2.10 +django==4.2.11 # via # -c requirements/constraints.txt # -r requirements/base.in @@ -39,9 +39,9 @@ six==1.16.0 # via -r requirements/base.in sqlparse==0.4.4 # via django -stevedore==5.1.0 +stevedore==5.2.0 # via edx-opaque-keys -typing-extensions==4.9.0 +typing-extensions==4.10.0 # via # asgiref # edx-opaque-keys diff --git a/requirements/django42.txt b/requirements/django42.txt index 1facfe28..db03776f 100644 --- a/requirements/django42.txt +++ b/requirements/django42.txt @@ -1 +1 @@ -django==4.2.10 +django==4.2.11 diff --git a/requirements/pip-tools.txt b/requirements/pip-tools.txt index 0e882265..01d695ac 100644 --- a/requirements/pip-tools.txt +++ b/requirements/pip-tools.txt @@ -4,18 +4,20 @@ # # make upgrade # -build==1.0.3 +build==1.1.1 # via pip-tools click==8.1.7 # via pip-tools -importlib-metadata==7.0.1 +importlib-metadata==7.0.2 # via build packaging==23.2 # via build -pip-tools==7.3.0 +pip-tools==7.4.1 # via -r requirements/pip-tools.in pyproject-hooks==1.0.0 - # via build + # via + # build + # pip-tools tomli==2.0.1 # via # build diff --git a/requirements/test.in b/requirements/test.in index 1b846abb..bd60164e 100644 --- a/requirements/test.in +++ b/requirements/test.in @@ -9,3 +9,4 @@ coverage mock testfixtures path.py +pyyaml diff --git a/requirements/test.txt b/requirements/test.txt index 794de185..56c3de2c 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -8,15 +8,15 @@ asgiref==3.7.2 # via # -r requirements/base.txt # django -astroid==3.0.3 +astroid==3.1.0 # via pylint backports-zoneinfo==0.2.1 # via # -r requirements/base.txt # django -coverage==7.4.1 +coverage==7.4.3 # via -r requirements/test.in -ddt==1.7.1 +ddt==1.7.2 # via -r requirements/test.in dill==0.3.8 # via pylint @@ -37,9 +37,7 @@ django-mysql==4.12.0 djangorestframework==3.14.0 # via -r requirements/base.txt edx-opaque-keys[django]==2.5.1 - # via - # -r requirements/base.txt - # edx-opaque-keys + # via -r requirements/base.txt isort==5.13.2 # via pylint jsonfield==3.1.0 @@ -62,7 +60,7 @@ platformdirs==4.2.0 # via pylint pycodestyle==2.11.1 # via -r requirements/test.in -pylint==3.0.3 +pylint==3.1.0 # via -r requirements/test.in pymongo==3.13.0 # via @@ -72,23 +70,25 @@ pytz==2024.1 # via # -r requirements/base.txt # djangorestframework +pyyaml==6.0.1 + # via -r requirements/test.in six==1.16.0 # via -r requirements/base.txt sqlparse==0.4.4 # via # -r requirements/base.txt # django -stevedore==5.1.0 +stevedore==5.2.0 # via # -r requirements/base.txt # edx-opaque-keys -testfixtures==7.2.2 +testfixtures==8.1.0 # via -r requirements/test.in tomli==2.0.1 # via pylint -tomlkit==0.12.3 +tomlkit==0.12.4 # via pylint -typing-extensions==4.9.0 +typing-extensions==4.10.0 # via # -r requirements/base.txt # asgiref diff --git a/requirements/tox.txt b/requirements/tox.txt index 28261f31..95caf24c 100644 --- a/requirements/tox.txt +++ b/requirements/tox.txt @@ -4,7 +4,7 @@ # # make upgrade # -cachetools==5.3.2 +cachetools==5.3.3 # via tox chardet==5.2.0 # via tox @@ -32,7 +32,7 @@ tomli==2.0.1 # via # pyproject-api # tox -tox==4.12.1 +tox==4.14.1 # via -r requirements/tox.in -virtualenv==20.25.0 +virtualenv==20.25.1 # via tox