From a68ee91533d5040bbc787e5e19d8847e6e867f24 Mon Sep 17 00:00:00 2001 From: Luis Felipe Castano Date: Tue, 4 Jun 2024 18:32:51 -0500 Subject: [PATCH 01/11] feat: add tutor integration test --- .github/workflows/integration-test.yml | 18 +++++++++++++++++ .../backends/course_overview_i_v1.py | 5 ++--- .../backends/enrollment_l_v1.py | 2 +- eox_tagging/settings/test.py | 12 +++++++++++ eox_tagging/test/tutor/__init__.py | 0 eox_tagging/test/tutor/conftest.py | 16 +++++++++++++++ eox_tagging/test/tutor/integration.sh | 11 ++++++++++ .../test/tutor/integration_test_tutor.py | 20 +++++++++++++++++++ eox_tagging/test/tutor/pytest.ini | 7 +++++++ requirements/test.in | 1 + 10 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/integration-test.yml create mode 100644 eox_tagging/test/tutor/__init__.py create mode 100644 eox_tagging/test/tutor/conftest.py create mode 100644 eox_tagging/test/tutor/integration.sh create mode 100644 eox_tagging/test/tutor/integration_test_tutor.py create mode 100644 eox_tagging/test/tutor/pytest.ini diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml new file mode 100644 index 00000000..65e5376c --- /dev/null +++ b/.github/workflows/integration-test.yml @@ -0,0 +1,18 @@ +name: Tutor Integration Tests +on: [pull_request] + +jobs: + integration-test: + 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" \ No newline at end of file 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 316b44a2..26909283 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 36d7a346..ccf5386b 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 c6af13de..b616ab14 100644 --- a/eox_tagging/settings/test.py +++ b/eox_tagging/settings/test.py @@ -1,6 +1,11 @@ """ Test Django settings for eox_tagging project. """ +import codecs +import os + +import yaml + from __future__ import unicode_literals 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 00000000..e69de29b diff --git a/eox_tagging/test/tutor/conftest.py b/eox_tagging/test/tutor/conftest.py new file mode 100644 index 00000000..cf72ca93 --- /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 00000000..b917202f --- /dev/null +++ b/eox_tagging/test/tutor/integration.sh @@ -0,0 +1,11 @@ +#!/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 ../eox-tagging + +echo "Install test-requirements" +make test-requirements + +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 00000000..d21998d7 --- /dev/null +++ b/eox_tagging/test/tutor/integration_test_tutor.py @@ -0,0 +1,20 @@ +""" +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.bearer_authentication_i_v1 # isort:skip + 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 00000000..f3b74624 --- /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 e82e5aea..c998fbc8 100644 --- a/requirements/test.in +++ b/requirements/test.in @@ -13,3 +13,4 @@ django-filter django-oauth2-provider djangorestframework-oauth mock +pyyaml \ No newline at end of file From 238134a4a8f73114668f219753f77303a654750d Mon Sep 17 00:00:00 2001 From: Luis Felipe Castano Date: Tue, 4 Jun 2024 18:37:41 -0500 Subject: [PATCH 02/11] feat: add tutor integration test --- .github/workflows/integration-test.yml | 2 +- requirements/test.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 65e5376c..17a54d44 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -15,4 +15,4 @@ jobs: with: tutor_version: ${{ matrix.tutor_version }} app_name: "eox-tagging" - shell_file_to_run: "eox_tagging/test/tutor/integration.sh" \ No newline at end of file + shell_file_to_run: "eox_tagging/test/tutor/integration.sh" diff --git a/requirements/test.in b/requirements/test.in index c998fbc8..5bc1225b 100644 --- a/requirements/test.in +++ b/requirements/test.in @@ -13,4 +13,4 @@ django-filter django-oauth2-provider djangorestframework-oauth mock -pyyaml \ No newline at end of file +pyyaml From 37dbec9beb4a882021bcca4df8123043ccb72fa0 Mon Sep 17 00:00:00 2001 From: Luis Felipe Castano Date: Tue, 4 Jun 2024 18:58:43 -0500 Subject: [PATCH 03/11] feat: add tutor integration test --- eox_tagging/settings/test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eox_tagging/settings/test.py b/eox_tagging/settings/test.py index b616ab14..fc306d88 100644 --- a/eox_tagging/settings/test.py +++ b/eox_tagging/settings/test.py @@ -1,13 +1,13 @@ """ Test Django settings for eox_tagging project. """ +from __future__ import unicode_literals + import codecs import os import yaml -from __future__ import unicode_literals - from .common import * # pylint: disable=wildcard-import, unused-wildcard-import From 45d2647d1abd4036699411a5923f0e6500c424ee Mon Sep 17 00:00:00 2001 From: Luis Felipe Castano Date: Tue, 4 Jun 2024 19:03:49 -0500 Subject: [PATCH 04/11] fix: quality changes --- eox_tagging/edxapp_wrappers/backends/course_overview_i_v1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 26909283..59cba2d3 100644 --- a/eox_tagging/edxapp_wrappers/backends/course_overview_i_v1.py +++ b/eox_tagging/edxapp_wrappers/backends/course_overview_i_v1.py @@ -3,7 +3,7 @@ openedx.core.djangoapps.content.course_overviews. """ from openedx.core.djangoapps.content.course_overviews.models import \ - CourseOverview # pylint: disable=import-outside-toplevel, import-error + CourseOverview # pylint: disable=import-outside-toplevel, import-error def get_course_overview(): From e1cee93a8b0c98eace1a6d46c420298f200b9006 Mon Sep 17 00:00:00 2001 From: Luis Felipe Castano Date: Tue, 4 Jun 2024 19:06:32 -0500 Subject: [PATCH 05/11] fix: quality changes --- eox_tagging/test/tutor/integration_test_tutor.py | 1 - 1 file changed, 1 deletion(-) diff --git a/eox_tagging/test/tutor/integration_test_tutor.py b/eox_tagging/test/tutor/integration_test_tutor.py index d21998d7..21ee496c 100644 --- a/eox_tagging/test/tutor/integration_test_tutor.py +++ b/eox_tagging/test/tutor/integration_test_tutor.py @@ -14,7 +14,6 @@ def test_current_settings_code_imports(self): """ Running this imports means that our backends import the right signature """ - import eox_tagging.edxapp_wrappers.backends.bearer_authentication_i_v1 # isort:skip 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 From 8ac271389429096067d3329ecac627a9e2c1ae76 Mon Sep 17 00:00:00 2001 From: Luis Felipe Castano Date: Tue, 4 Jun 2024 23:14:14 -0500 Subject: [PATCH 06/11] fix: eox-core requirement --- eox_tagging/test/tutor/integration.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eox_tagging/test/tutor/integration.sh b/eox_tagging/test/tutor/integration.sh index b917202f..28dc3a83 100644 --- a/eox_tagging/test/tutor/integration.sh +++ b/eox_tagging/test/tutor/integration.sh @@ -1,6 +1,9 @@ #!/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 eox-core(requirement)" +pip install eox-core + echo "Install package" pip install -e ../eox-tagging From 3b323ddd824d948d37b514f8d2e9efe0d7227ee9 Mon Sep 17 00:00:00 2001 From: Luis Felipe Castano Date: Wed, 5 Jun 2024 18:39:10 -0500 Subject: [PATCH 07/11] fix: eox-core requirement --- requirements/test.in | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements/test.in b/requirements/test.in index 5bc1225b..2091ba49 100644 --- a/requirements/test.in +++ b/requirements/test.in @@ -14,3 +14,4 @@ django-oauth2-provider djangorestframework-oauth mock pyyaml +eox-core From 2d1b41a0d5a52f14802d5d473c2b91d1ad6e43bf Mon Sep 17 00:00:00 2001 From: Luis Felipe Castano Date: Thu, 6 Jun 2024 00:41:51 -0500 Subject: [PATCH 08/11] fix: eox-core requirement --- eox_tagging/test/tutor/integration.sh | 2 +- requirements/test.in | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/eox_tagging/test/tutor/integration.sh b/eox_tagging/test/tutor/integration.sh index 28dc3a83..bf7c2a5d 100644 --- a/eox_tagging/test/tutor/integration.sh +++ b/eox_tagging/test/tutor/integration.sh @@ -5,7 +5,7 @@ echo "Install eox-core(requirement)" pip install eox-core echo "Install package" -pip install -e ../eox-tagging +pip install -e /openedx/eox-tagging echo "Install test-requirements" make test-requirements diff --git a/requirements/test.in b/requirements/test.in index 2091ba49..5bc1225b 100644 --- a/requirements/test.in +++ b/requirements/test.in @@ -14,4 +14,3 @@ django-oauth2-provider djangorestframework-oauth mock pyyaml -eox-core From c0b35e2ced63376b9ac3ddbd7ee42fe04eb1e34c Mon Sep 17 00:00:00 2001 From: Luis Felipe Castano Date: Thu, 6 Jun 2024 01:03:31 -0500 Subject: [PATCH 09/11] fix: eox-core requirement --- eox_tagging/test/tutor/integration.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eox_tagging/test/tutor/integration.sh b/eox_tagging/test/tutor/integration.sh index bf7c2a5d..ca843ed9 100644 --- a/eox_tagging/test/tutor/integration.sh +++ b/eox_tagging/test/tutor/integration.sh @@ -1,14 +1,14 @@ #!/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 eox-core(requirement)" -pip install eox-core - 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 + echo "Run tests" pytest -s --ds=lms.envs.tutor.test /openedx/eox-tagging/eox_tagging/test/tutor From fe07f0ad6a610f1627fefcb0010e01999a740297 Mon Sep 17 00:00:00 2001 From: Luis Felipe Castano Date: Thu, 6 Jun 2024 18:13:13 -0500 Subject: [PATCH 10/11] fix: quality changes --- .github/workflows/integration-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 17a54d44..26ca4867 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -3,6 +3,7 @@ on: [pull_request] jobs: integration-test: + name: Tutor Integration Tests runs-on: ubuntu-latest strategy: matrix: From 89b1ea766a4d9c84112b7f70bcd49385489048a1 Mon Sep 17 00:00:00 2001 From: Luis Felipe Castano Date: Fri, 7 Jun 2024 11:09:09 -0500 Subject: [PATCH 11/11] fix: add migrations --- eox_tagging/test/tutor/integration.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eox_tagging/test/tutor/integration.sh b/eox_tagging/test/tutor/integration.sh index ca843ed9..cdcee9ec 100644 --- a/eox_tagging/test/tutor/integration.sh +++ b/eox_tagging/test/tutor/integration.sh @@ -10,5 +10,8 @@ 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