diff --git a/common/djangoapps/student/apps.py b/common/djangoapps/student/apps.py index 9498dd2ef1..4966cbb7b6 100644 --- a/common/djangoapps/student/apps.py +++ b/common/djangoapps/student/apps.py @@ -3,6 +3,8 @@ Configuration for the ``student`` Django application. """ from __future__ import absolute_import +import os + from django.apps import AppConfig from django.contrib.auth.signals import user_logged_in from django.db.models.signals import pre_save @@ -23,3 +25,11 @@ class StudentConfig(AppConfig): from django.contrib.auth.models import User from .signals.receivers import on_user_updated pre_save.connect(on_user_updated, sender=User) + + # The django-simple-history model on CourseEnrollment creates performance + # problems in testing, we mock it here so that the mock impacts all tests. + if os.environ.get('DISABLE_COURSEENROLLMENT_HISTORY', False): + import student.models as student_models + from mock import MagicMock + + student_models.CourseEnrollment.history = MagicMock() diff --git a/pavelib/paver_tests/test_paver_pytest_cmds.py b/pavelib/paver_tests/test_paver_pytest_cmds.py index b2bb55a3f5..a73ed11c0a 100644 --- a/pavelib/paver_tests/test_paver_pytest_cmds.py +++ b/pavelib/paver_tests/test_paver_pytest_cmds.py @@ -55,10 +55,12 @@ class TestPaverPytestCmd(unittest.TestCase): else: django_env_var_cmd = "export DJANGO_SETTINGS_MODULE='openedx.tests.settings'" + env_var_cmd = "{} DISABLE_COURSEENROLLMENT_HISTORY=1".format(django_env_var_cmd) + xdist_string = u'--tx {}*ssh="ubuntu@{} -o StrictHostKeyChecking=no"' \ '//python="source /edx/app/edxapp/edxapp_env; {}; python"' \ '//chdir="/edx/app/edxapp/edx-platform"' \ - .format(processes, ip, django_env_var_cmd) + .format(processes, ip, env_var_cmd) expected_statement.append(xdist_string) for rsync_dir in Env.rsync_dirs(): expected_statement.append(u'--rsyncdir {}'.format(rsync_dir)) diff --git a/pavelib/tests.py b/pavelib/tests.py index 7def944b1a..26ff37915a 100644 --- a/pavelib/tests.py +++ b/pavelib/tests.py @@ -70,6 +70,19 @@ __test__ = False # do not collect dest='disable_migrations', help="Create tables by applying migrations." ), + make_option( + '--disable_courseenrollment_history', + action='store_true', + dest='disable_courseenrollment_history', + help="Disable history on student.CourseEnrollent. Can also be used by exporting" + "DISABLE_COURSEENROLLMENT_HISTORY=1." + ), + make_option( + '--enable_courseenrollment_history', + action='store_false', + dest='disable_courseenrollment_history', + help="Enable django-simple-history on student.CourseEnrollment." + ), make_option( '--xdist_ip_addresses', dest='xdist_ip_addresses', @@ -230,6 +243,19 @@ def test_lib(options, passthrough_options): dest='disable_migrations', help="Create tables directly from apps' models. Can also be used by exporting DISABLE_MIGRATIONS=1." ), + make_option( + '--disable_courseenrollment_history', + action='store_true', + dest='disable_courseenrollment_history', + help="Disable history on student.CourseEnrollent. Can also be used by exporting" + "DISABLE_COURSEENROLLMENT_HISTORY=1." + ), + make_option( + '--enable_courseenrollment_history', + action='store_false', + dest='disable_courseenrollment_history', + help="Enable django-simple-history on student.CourseEnrollment." + ), ]) @PassthroughTask @timed diff --git a/pavelib/utils/test/suites/pytest_suite.py b/pavelib/utils/test/suites/pytest_suite.py index 4e21de11b6..3360d9a811 100644 --- a/pavelib/utils/test/suites/pytest_suite.py +++ b/pavelib/utils/test/suites/pytest_suite.py @@ -26,6 +26,7 @@ class PytestSuite(TestSuite): self.django_toxenv = None else: self.django_toxenv = 'py27-django{}'.format(django_version.replace('.', '')) + self.disable_courseenrollment_history = kwargs.get('disable_courseenrollment_history', '1') self.disable_capture = kwargs.get('disable_capture', None) self.report_dir = Env.REPORT_DIR / self.root @@ -36,6 +37,10 @@ class PytestSuite(TestSuite): if os.environ.get("SHARD", None): shard_str = "shard_{}".format(os.environ.get("SHARD")) self.report_dir = self.report_dir / shard_str + + if self.disable_courseenrollment_history: + os.environ['DISABLE_COURSEENROLLMENT_HISTORY'] = '1' + self.xunit_report = self.report_dir / "nosetests.xml" self.cov_args = kwargs.get('cov_args', '') @@ -161,13 +166,14 @@ class SystemTestSuite(PytestSuite): else: xdist_remote_processes = self.processes for ip in self.xdist_ip_addresses.split(','): - # The django settings runtime command does not propagate to xdist remote workers - django_env_var_cmd = u'export DJANGO_SETTINGS_MODULE={}' \ - .format('{}.envs.{}'.format(self.root, self.settings)) + # Propogate necessary env vars to xdist containers + env_var_cmd = u'export DJANGO_SETTINGS_MODULE={} DISABLE_COURSEENROLLMENT_HISTORY={}'\ + .format('{}.envs.{}'.format(self.root, self.settings), + self.disable_courseenrollment_history) xdist_string = u'--tx {}*ssh="ubuntu@{} -o StrictHostKeyChecking=no"' \ '//python="source /edx/app/edxapp/edxapp_env; {}; python"' \ '//chdir="/edx/app/edxapp/edx-platform"' \ - .format(xdist_remote_processes, ip, django_env_var_cmd) + .format(xdist_remote_processes, ip, env_var_cmd) cmd.append(xdist_string) for rsync_dir in Env.rsync_dirs(): cmd.append(u'--rsyncdir {}'.format(rsync_dir)) @@ -280,15 +286,19 @@ class LibTestSuite(PytestSuite): else: xdist_remote_processes = self.processes for ip in self.xdist_ip_addresses.split(','): - # The django settings runtime command does not propagate to xdist remote workers + # Propogate necessary env vars to xdist containers if 'pavelib/paver_tests' in self.test_id: django_env_var_cmd = "export DJANGO_SETTINGS_MODULE='lms.envs.test'" else: django_env_var_cmd = "export DJANGO_SETTINGS_MODULE='openedx.tests.settings'" + + env_var_cmd = u'{} DISABLE_COURSEENROLLMENT_HISTORY={}' \ + .format(django_env_var_cmd, self.disable_courseenrollment_history) + xdist_string = u'--tx {}*ssh="ubuntu@{} -o StrictHostKeyChecking=no"' \ '//python="source /edx/app/edxapp/edxapp_env; {}; python"' \ '//chdir="/edx/app/edxapp/edx-platform"' \ - .format(xdist_remote_processes, ip, django_env_var_cmd) + .format(xdist_remote_processes, ip, env_var_cmd) cmd.append(xdist_string) for rsync_dir in Env.rsync_dirs(): cmd.append(u'--rsyncdir {}'.format(rsync_dir))