diff --git a/eox_hooks/edxapp_wrapper/backends/course_modes_j_v1.py b/eox_hooks/edxapp_wrapper/backends/course_modes_j_v1.py index a8e93ab..59a0f50 100644 --- a/eox_hooks/edxapp_wrapper/backends/course_modes_j_v1.py +++ b/eox_hooks/edxapp_wrapper/backends/course_modes_j_v1.py @@ -1,6 +1,7 @@ """ Backend file for Course Modes related objects. """ +from course_modes.models import CourseMode # pylint: disable=C0415, E0401 def get_all_course_modes(): @@ -10,6 +11,5 @@ def get_all_course_modes(): Returns: [list]: list of course modes. """ - from course_modes.models import CourseMode # pylint: disable=C0415, E0401 modes_for_course = CourseMode.ALL_MODES return modes_for_course diff --git a/eox_hooks/edxapp_wrapper/backends/course_modes_l_v1.py b/eox_hooks/edxapp_wrapper/backends/course_modes_l_v1.py index aff2aee..43caabf 100644 --- a/eox_hooks/edxapp_wrapper/backends/course_modes_l_v1.py +++ b/eox_hooks/edxapp_wrapper/backends/course_modes_l_v1.py @@ -1,6 +1,7 @@ """ Backend file for Course Modes related objects. """ +from common.djangoapps.course_modes.models import CourseMode # pylint: disable=C0415, E0401 def get_all_course_modes(): @@ -10,6 +11,5 @@ def get_all_course_modes(): Returns: [list]: list of course modes. """ - from common.djangoapps.course_modes.models import CourseMode # pylint: disable=C0415, E0401 modes_for_course = CourseMode.ALL_MODES return modes_for_course diff --git a/eox_hooks/edxapp_wrapper/backends/courses_j_v1.py b/eox_hooks/edxapp_wrapper/backends/courses_j_v1.py index a3d6ae2..d809891 100644 --- a/eox_hooks/edxapp_wrapper/backends/courses_j_v1.py +++ b/eox_hooks/edxapp_wrapper/backends/courses_j_v1.py @@ -1,6 +1,7 @@ """ Backend file for Course related objects. """ +from courseware.module_render import load_single_xblock # pylint: disable=C0415, E0401 def get_load_single_xblock(): @@ -10,7 +11,6 @@ def get_load_single_xblock(): Returns: [Function]: load_single_xblock function. """ - from courseware.module_render import load_single_xblock # pylint: disable=C0415, E0401 return load_single_xblock diff --git a/eox_hooks/edxapp_wrapper/backends/courses_l_v1.py b/eox_hooks/edxapp_wrapper/backends/courses_l_v1.py index bff3b7f..2b51760 100644 --- a/eox_hooks/edxapp_wrapper/backends/courses_l_v1.py +++ b/eox_hooks/edxapp_wrapper/backends/courses_l_v1.py @@ -1,6 +1,8 @@ """ Backend file for Course related objects. """ +from lms.djangoapps.courseware.module_render import load_single_xblock # pylint: disable=C0415, E0401 +from xmodule.modulestore.exceptions import ItemNotFoundError # pylint: disable=C0415, E0401 def get_load_single_xblock(): @@ -10,7 +12,6 @@ def get_load_single_xblock(): Returns: [Function]: load_single_xblock function. """ - from lms.djangoapps.courseware.module_render import load_single_xblock # pylint: disable=C0415, E0401 return load_single_xblock @@ -21,5 +22,4 @@ def get_item_not_found_exception(): Returns: [Class]: ItemNotFoundError exception. """ - from xmodule.modulestore.exceptions import ItemNotFoundError # pylint: disable=C0415, E0401 return ItemNotFoundError diff --git a/eox_hooks/edxapp_wrapper/backends/courses_p_v1.py b/eox_hooks/edxapp_wrapper/backends/courses_p_v1.py index 24184bc..0a68ac2 100644 --- a/eox_hooks/edxapp_wrapper/backends/courses_p_v1.py +++ b/eox_hooks/edxapp_wrapper/backends/courses_p_v1.py @@ -1,6 +1,8 @@ """ Backend file for Course related objects. """ +from lms.djangoapps.courseware.block_render import load_single_xblock # pylint: disable=C0415, E0401 +from xmodule.modulestore.exceptions import ItemNotFoundError # pylint: disable=C0415, E0401 def get_load_single_xblock(): @@ -10,7 +12,6 @@ def get_load_single_xblock(): Returns: [Function]: load_single_xblock function. """ - from lms.djangoapps.courseware.block_render import load_single_xblock # pylint: disable=C0415, E0401 return load_single_xblock @@ -21,5 +22,4 @@ def get_item_not_found_exception(): Returns: [Class]: ItemNotFoundError exception. """ - from xmodule.modulestore.exceptions import ItemNotFoundError # pylint: disable=C0415, E0401 return ItemNotFoundError diff --git a/eox_hooks/edxapp_wrapper/backends/enrollments_j_v1.py b/eox_hooks/edxapp_wrapper/backends/enrollments_j_v1.py index 4210249..bc01b7c 100644 --- a/eox_hooks/edxapp_wrapper/backends/enrollments_j_v1.py +++ b/eox_hooks/edxapp_wrapper/backends/enrollments_j_v1.py @@ -1,6 +1,7 @@ """ Backend file for Course Enrollment related objects. """ +from student.models import CourseEnrollment # pylint: disable=C0415, E0401 def get_course_enrollment(): @@ -10,5 +11,4 @@ def get_course_enrollment(): Returns: [Class]: Course Enrollment edxapp model. """ - from student.models import CourseEnrollment # pylint: disable=C0415, E0401 return CourseEnrollment diff --git a/eox_hooks/edxapp_wrapper/backends/enrollments_l_v1.py b/eox_hooks/edxapp_wrapper/backends/enrollments_l_v1.py index f2160ec..6a16a03 100644 --- a/eox_hooks/edxapp_wrapper/backends/enrollments_l_v1.py +++ b/eox_hooks/edxapp_wrapper/backends/enrollments_l_v1.py @@ -1,6 +1,7 @@ """ Backend file for Course Enrollment related objects. """ +from common.djangoapps.student.models import CourseEnrollment # pylint: disable=C0415, E0401 def get_course_enrollment(): @@ -10,5 +11,4 @@ def get_course_enrollment(): Returns: [Class]: Course Enrollment edxapp model. """ - from common.djangoapps.student.models import CourseEnrollment # pylint: disable=C0415, E0401 return CourseEnrollment diff --git a/eox_hooks/edxapp_wrapper/backends/models_j_v1.py b/eox_hooks/edxapp_wrapper/backends/models_j_v1.py index e02f331..0aedcac 100644 --- a/eox_hooks/edxapp_wrapper/backends/models_j_v1.py +++ b/eox_hooks/edxapp_wrapper/backends/models_j_v1.py @@ -1,15 +1,15 @@ """ Simple backend that returns the platform's models """ +from lms.djangoapps.certificates.models import GeneratedCertificate # pylint: disable=C0415, E0401 +from student.models import UserProfile # pylint: disable=C0415, E0401 def get_certificate_model(): """Return the GeneratedCertificate model class when called during runtime""" - from lms.djangoapps.certificates.models import GeneratedCertificate # pylint: disable=C0415, E0401 return GeneratedCertificate def get_user_profile_model(): """Return the UserProfile model class when called during runtime""" - from student.models import UserProfile # pylint: disable=C0415, E0401 return UserProfile diff --git a/eox_hooks/edxapp_wrapper/backends/models_l_v1.py b/eox_hooks/edxapp_wrapper/backends/models_l_v1.py index fdb0ab8..1f502bd 100644 --- a/eox_hooks/edxapp_wrapper/backends/models_l_v1.py +++ b/eox_hooks/edxapp_wrapper/backends/models_l_v1.py @@ -1,15 +1,15 @@ """ Simple backend that returns the platform's models """ +from common.djangoapps.student.models import UserProfile # pylint: disable=C0415, E0401 +from lms.djangoapps.certificates.models import GeneratedCertificate # pylint: disable=C0415, E0401 def get_certificate_model(): """Return the GeneratedCertificate model class when called during runtime""" - from lms.djangoapps.certificates.models import GeneratedCertificate # pylint: disable=C0415, E0401 return GeneratedCertificate def get_user_profile_model(): """Return the UserProfile model class when called during runtime""" - from common.djangoapps.student.models import UserProfile # pylint: disable=C0415, E0401 return UserProfile diff --git a/eox_hooks/settings/test.py b/eox_hooks/settings/test.py index 81dd7e1..cf6c317 100644 --- a/eox_hooks/settings/test.py +++ b/eox_hooks/settings/test.py @@ -1,7 +1,10 @@ """ Test Django settings for eox_hooks project. """ +import codecs +import os +import yaml from .common import * # pylint: disable=wildcard-import, unused-wildcard-import @@ -43,3 +46,14 @@ 'NAME': 'db.sqlite3', } } + + +def plugin_settings(settings): # pylint: disable=function-redefined + """ + For the platform tests + """ + # setup the databases used in the tutor local environment + if os.environ['LMS_CFG']: + 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_hooks/tests/tutor/__init__.py b/eox_hooks/tests/tutor/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/eox_hooks/tests/tutor/conftest.py b/eox_hooks/tests/tutor/conftest.py new file mode 100644 index 0000000..cf72ca9 --- /dev/null +++ b/eox_hooks/tests/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_hooks/tests/tutor/integration_test_tutor.py b/eox_hooks/tests/tutor/integration_test_tutor.py new file mode 100644 index 0000000..3cf8db6 --- /dev/null +++ b/eox_hooks/tests/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_hooks.edxapp_wrapper.backends.course_modes_l_v1 # isort:skip + import eox_hooks.edxapp_wrapper.backends.courses_p_v1 # isort:skip + import eox_hooks.edxapp_wrapper.backends.enrollments_l_v1 # isort:skip + import eox_hooks.edxapp_wrapper.backends.models_l_v1 # isort:skip diff --git a/eox_hooks/tests/tutor/pytest.ini b/eox_hooks/tests/tutor/pytest.ini new file mode 100644 index 0000000..f3b7462 --- /dev/null +++ b/eox_hooks/tests/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 1d18bc3..8a1cbe3 100644 --- a/requirements/test.in +++ b/requirements/test.in @@ -7,3 +7,4 @@ coverage mock testfixtures requests +pyyaml diff --git a/requirements/test.txt b/requirements/test.txt index 0a52ba8..639c419 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -113,6 +113,8 @@ pymongo==3.13.0 # via # -r requirements/base.txt # edx-opaque-keys +pyyaml==6.0.1 + # via -r requirements/test.in python-dateutil==2.8.2 # via # -r requirements/base.txt