From d6dc209569f27b2f6be5f660a8a13800f44e334f Mon Sep 17 00:00:00 2001
From: Jeremy Bowman <jbowman@edx.org>
Date: Wed, 15 Nov 2017 11:00:39 -0500
Subject: [PATCH] Fixes for common/lib tests in Django 1.9+

---
 common/lib/conftest.py                        |  8 -----
 common/lib/pytest.ini                         |  1 +
 .../xmodule/xmodule/tests/test_services.py    |  3 +-
 openedx/tests/settings.py                     | 33 +++++++++++++++++++
 tox.ini                                       |  4 ++-
 5 files changed, 39 insertions(+), 10 deletions(-)
 delete mode 100644 common/lib/conftest.py
 create mode 100644 openedx/tests/settings.py

diff --git a/common/lib/conftest.py b/common/lib/conftest.py
deleted file mode 100644
index 0295dabcc80..00000000000
--- a/common/lib/conftest.py
+++ /dev/null
@@ -1,8 +0,0 @@
-from django.conf import settings
-
-
-def pytest_configure():
-    """
-    Use Django's default settings for tests in common/lib.
-    """
-    settings.configure()
diff --git a/common/lib/pytest.ini b/common/lib/pytest.ini
index bcdab593515..349b1dff15e 100644
--- a/common/lib/pytest.ini
+++ b/common/lib/pytest.ini
@@ -1,4 +1,5 @@
 [pytest]
+DJANGO_SETTINGS_MODULE = openedx.tests.settings
 addopts = --nomigrations --reuse-db --durations=20
 norecursedirs = .cache
 python_classes =
diff --git a/common/lib/xmodule/xmodule/tests/test_services.py b/common/lib/xmodule/xmodule/tests/test_services.py
index 16a25d4d6f2..01f8416e8a4 100644
--- a/common/lib/xmodule/xmodule/tests/test_services.py
+++ b/common/lib/xmodule/xmodule/tests/test_services.py
@@ -23,7 +23,8 @@ class DummyConfig(ConfigurationModel):
     """
     Dummy Configuration
     """
-    pass
+    class Meta:
+        app_label = 'xmoduletestservices'
 
 
 class DummyUnexpected(object):
diff --git a/openedx/tests/settings.py b/openedx/tests/settings.py
new file mode 100644
index 00000000000..5ff68cf9906
--- /dev/null
+++ b/openedx/tests/settings.py
@@ -0,0 +1,33 @@
+"""
+Minimal Django settings for tests of common/lib.
+Required in Django 1.9+ due to imports of models in stock Django apps.
+"""
+
+from __future__ import absolute_import, unicode_literals
+
+import tempfile
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.sqlite3',
+        'NAME': 'default.db',
+        'USER': '',
+        'PASSWORD': '',
+        'HOST': '',
+        'PORT': '',
+    }
+}
+
+INSTALLED_APPS = (
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'openedx.core.djangoapps.video_config',
+    'edxval',
+)
+
+MEDIA_ROOT = tempfile.mkdtemp()
+
+SECRET_KEY = 'insecure-secret-key'
+
+USE_TZ = True
diff --git a/tox.ini b/tox.ini
index 58131058378..7712615aad9 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = py27-django{18,111}
+envlist = py27-django{18,19,110,111}
 
 [testenv]
 setenv =
@@ -9,6 +9,8 @@ passenv =
     EDXAPP_TEST_MONGO_HOST
 deps =
     django18: Django>=1.8,<1.9
+    django19: Django>=1.9,<1.10
+    django110: Django>=1.10,<1.11
     django111: Django>=1.11,<2
     -rrequirements/edx/pre.txt
     -rrequirements/edx/github.txt
-- 
GitLab