From 5de9eed420f0e84db1383403f932e48e98c89df8 Mon Sep 17 00:00:00 2001 From: Robert Raposa Date: Thu, 23 Apr 2020 14:04:29 -0400 Subject: [PATCH] ARCHBOM-1093: Fix unit test enable-migrations (#23789) * fix old migrations * fix a test * fix enable-migrations cmd argument * enhance verbose logging to log migrations * update testing doc with help --- cms/envs/test.py | 5 ----- docs/guides/testing/testing.rst | 4 ++++ .../0001_data__add_ecommerce_service_user.py | 7 +++++++ .../courseware/migrations/0011_csm_id_bigint.py | 3 +++ lms/envs/test.py | 5 ----- openedx/core/lib/api/tests/test_authentication.py | 1 - pavelib/utils/test/suites/pytest_suite.py | 14 +++++++++++--- 7 files changed, 25 insertions(+), 14 deletions(-) diff --git a/cms/envs/test.py b/cms/envs/test.py index a94687c008..9d273a9177 100644 --- a/cms/envs/test.py +++ b/cms/envs/test.py @@ -132,11 +132,6 @@ DATABASES = { }, } -if os.environ.get('DISABLE_MIGRATIONS'): - # Create tables directly from apps' models. This can be removed once we upgrade - # to Django 1.9, which allows setting MIGRATION_MODULES to None in order to skip migrations. - MIGRATION_MODULES = NoOpMigrationModules() - LMS_BASE = "localhost:8000" LMS_ROOT_URL = "http://{}".format(LMS_BASE) FEATURES['PREVIEW_LMS_BASE'] = "preview.localhost" diff --git a/docs/guides/testing/testing.rst b/docs/guides/testing/testing.rst index a7b0825b9a..9f7f098a9f 100644 --- a/docs/guides/testing/testing.rst +++ b/docs/guides/testing/testing.rst @@ -161,6 +161,10 @@ against a database created by applying the migrations instead, use the paver test_system -s lms --enable-migrations +To see the migration output, use:: + + paver test_system -s lms --enable-migrations --verbose --disable_capture + To run a single django test class use this command:: paver test_system -t lms/djangoapps/courseware/tests/tests.py::ActivateLoginTest diff --git a/lms/djangoapps/commerce/migrations/0001_data__add_ecommerce_service_user.py b/lms/djangoapps/commerce/migrations/0001_data__add_ecommerce_service_user.py index 468c3d9843..0ebf5b6fe0 100644 --- a/lms/djangoapps/commerce/migrations/0001_data__add_ecommerce_service_user.py +++ b/lms/djangoapps/commerce/migrations/0001_data__add_ecommerce_service_user.py @@ -2,6 +2,7 @@ from django.conf import settings +from django.contrib.auth import get_user_model from django.contrib.auth.models import User from django.db import migrations, models @@ -10,6 +11,7 @@ EMAIL = USERNAME + '@fake.email' def forwards(apps, schema_editor): """Add the service user.""" + User = get_user_model() user, created = User.objects.get_or_create(username=USERNAME, email=EMAIL) if created: user.set_unusable_password() @@ -21,6 +23,11 @@ def backwards(apps, schema_editor): class Migration(migrations.Migration): + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('user_api', '0002_retirementstate_userretirementstatus'), + ] + operations = [ migrations.RunPython(forwards, backwards), ] diff --git a/lms/djangoapps/courseware/migrations/0011_csm_id_bigint.py b/lms/djangoapps/courseware/migrations/0011_csm_id_bigint.py index 03d7b7b6ea..047261f614 100644 --- a/lms/djangoapps/courseware/migrations/0011_csm_id_bigint.py +++ b/lms/djangoapps/courseware/migrations/0011_csm_id_bigint.py @@ -15,6 +15,9 @@ class CsmBigInt(AlterField): level and the coursewarehistoryextended_studentmodulehistoryextended table is in a different database ''' def database_forwards(self, app_label, schema_editor, from_state, to_state): + if schema_editor.connection.is_in_memory_db(): + # sqlite3 doesn't support 'MODIFY', so skipping during tests + return to_model = to_state.apps.get_model(app_label, self.model_name) if schema_editor.connection.alias == 'student_module_history': if settings.FEATURES["ENABLE_CSMH_EXTENDED"]: diff --git a/lms/envs/test.py b/lms/envs/test.py index 6a998548ed..f0f2208803 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -193,11 +193,6 @@ DATABASES = { }, } -if os.environ.get('DISABLE_MIGRATIONS'): - # Create tables directly from apps' models. This can be removed once we upgrade - # to Django 1.9, which allows setting MIGRATION_MODULES to None in order to skip migrations. - MIGRATION_MODULES = NoOpMigrationModules() - CACHES = { # This is the cache used for most things. # In staging/prod envs, the sessions also live here. diff --git a/openedx/core/lib/api/tests/test_authentication.py b/openedx/core/lib/api/tests/test_authentication.py index 0c973e94c3..61a627958c 100644 --- a/openedx/core/lib/api/tests/test_authentication.py +++ b/openedx/core/lib/api/tests/test_authentication.py @@ -45,7 +45,6 @@ class MockView(APIView): # pylint: disable=missing-docstring urlpatterns = [ - url(r'^oauth2/', include(('provider.oauth2.urls', 'oauth2'), namespace='oauth2')), url( r'^oauth2-inactive-test/$', MockView.as_view(authentication_classes=[authentication.BearerAuthenticationAllowInactiveUser]) diff --git a/pavelib/utils/test/suites/pytest_suite.py b/pavelib/utils/test/suites/pytest_suite.py index 1e96ec2ec2..c1c6f6c933 100644 --- a/pavelib/utils/test/suites/pytest_suite.py +++ b/pavelib/utils/test/suites/pytest_suite.py @@ -126,7 +126,7 @@ class SystemTestSuite(PytestSuite): self.eval_attr = kwargs.get('eval_attr', None) self.test_id = kwargs.get('test_id', self._default_test_id) self.fasttest = kwargs.get('fasttest', False) - + self.disable_migrations = kwargs.get('disable_migrations', True) self.processes = kwargs.get('processes', None) self.randomize = kwargs.get('randomize', None) self.settings = kwargs.get('settings', Env.TEST_SETTINGS) @@ -168,10 +168,16 @@ class SystemTestSuite(PytestSuite): if self.verbosity < 1: cmd.append("--quiet") elif self.verbosity > 1: - cmd.append("--verbose") + # currently only two verbosity settings are supported, so using `-vvv` + # in place of `--verbose`, because it is needed to see migrations. + cmd.append("-vvv") if self.disable_capture: cmd.append("-s") + + if not self.disable_migrations: + cmd.append("--migrations") + if self.xdist_ip_addresses: cmd.append('--dist=loadscope') if self.processes <= 0: @@ -289,7 +295,9 @@ class LibTestSuite(PytestSuite): if self.verbosity < 1: cmd.append("--quiet") elif self.verbosity > 1: - cmd.append("--verbose") + # currently only two verbosity settings are supported, so using `-vvv` + # in place of `--verbose`, because it is needed to see migrations. + cmd.append("-vvv") if self.disable_capture: cmd.append("-s")