Merge pull request #873 from DavidBord/fix-872
Fix #872: No module named 'django.utils.importlib' (Django dev)
This commit is contained in:
		| @@ -5,6 +5,7 @@ Changelog | |||||||
|  |  | ||||||
| Changes in 0.9.X - DEV | Changes in 0.9.X - DEV | ||||||
| ====================== | ====================== | ||||||
|  | - No module named 'django.utils.importlib' (Django dev) #872 | ||||||
| - Field Choices Now Accept Subclasses of Documents | - Field Choices Now Accept Subclasses of Documents | ||||||
| - Ensure Indexes before Each Save #812 | - Ensure Indexes before Each Save #812 | ||||||
| - Generate Unique Indices for Lists of EmbeddedDocuments #358 | - Generate Unique Indices for Lists of EmbeddedDocuments #358 | ||||||
|   | |||||||
| @@ -3,7 +3,11 @@ from django.contrib.auth.hashers import make_password | |||||||
| from django.contrib.auth.models import UserManager | from django.contrib.auth.models import UserManager | ||||||
| from django.core.exceptions import ImproperlyConfigured | from django.core.exceptions import ImproperlyConfigured | ||||||
| from django.db import models | from django.db import models | ||||||
| from django.utils.importlib import import_module | try: | ||||||
|  |     from django.utils.module_loading import import_module | ||||||
|  | except ImportError: | ||||||
|  |     """Handle older versions of Django""" | ||||||
|  |     from django.utils.importlib import import_module | ||||||
| from django.utils.translation import ugettext_lazy as _ | from django.utils.translation import ugettext_lazy as _ | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -19,9 +19,12 @@ settings.configure( | |||||||
|     AUTHENTICATION_BACKENDS = ('mongoengine.django.auth.MongoEngineBackend',) |     AUTHENTICATION_BACKENDS = ('mongoengine.django.auth.MongoEngineBackend',) | ||||||
| ) | ) | ||||||
|  |  | ||||||
| # For Django >= 1.7 | try: | ||||||
| if hasattr(django, 'setup'): |     # For Django >= 1.7 | ||||||
|  |     if hasattr(django, 'setup'): | ||||||
|         django.setup() |         django.setup() | ||||||
|  | except RuntimeError: | ||||||
|  |     pass | ||||||
|  |  | ||||||
| try: | try: | ||||||
|     from django.contrib.auth import authenticate, get_user_model |     from django.contrib.auth import authenticate, get_user_model | ||||||
| @@ -34,7 +37,6 @@ try: | |||||||
|     DJ15 = True |     DJ15 = True | ||||||
| except Exception: | except Exception: | ||||||
|     DJ15 = False |     DJ15 = False | ||||||
| from django.contrib.sessions.tests import SessionTestsMixin |  | ||||||
| from mongoengine.django.sessions import SessionStore, MongoSession | from mongoengine.django.sessions import SessionStore, MongoSession | ||||||
| from mongoengine.django.tests import MongoTestCase | from mongoengine.django.tests import MongoTestCase | ||||||
| from datetime import tzinfo, timedelta | from datetime import tzinfo, timedelta | ||||||
| @@ -226,13 +228,13 @@ class QuerySetTest(unittest.TestCase): | |||||||
|         self.assertEqual(t.render(c), "10") |         self.assertEqual(t.render(c), "10") | ||||||
|  |  | ||||||
|  |  | ||||||
| class MongoDBSessionTest(SessionTestsMixin, unittest.TestCase): | class _BaseMongoDBSessionTest(unittest.TestCase): | ||||||
|     backend = SessionStore |     backend = SessionStore | ||||||
|  |  | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         connect(db='mongoenginetest') |         connect(db='mongoenginetest') | ||||||
|         MongoSession.drop_collection() |         MongoSession.drop_collection() | ||||||
|         super(MongoDBSessionTest, self).setUp() |         super(_BaseMongoDBSessionTest, self).setUp() | ||||||
|  |  | ||||||
|     def assertIn(self, first, second, msg=None): |     def assertIn(self, first, second, msg=None): | ||||||
|         self.assertTrue(first in second, msg) |         self.assertTrue(first in second, msg) | ||||||
| @@ -259,6 +261,21 @@ class MongoDBSessionTest(SessionTestsMixin, unittest.TestCase): | |||||||
|         self.assertTrue('test_expire' in session, 'Session has expired before it is expected') |         self.assertTrue('test_expire' in session, 'Session has expired before it is expected') | ||||||
|  |  | ||||||
|  |  | ||||||
|  | try: | ||||||
|  |     # SessionTestsMixin isn't available for import on django > 1.8a1 | ||||||
|  |     from django.contrib.sessions.tests import SessionTestsMixin | ||||||
|  |  | ||||||
|  |     class _MongoDBSessionTest(SessionTestsMixin): | ||||||
|  |         pass | ||||||
|  |  | ||||||
|  |     class MongoDBSessionTest(_BaseMongoDBSessionTest): | ||||||
|  |         pass | ||||||
|  |  | ||||||
|  | except ImportError: | ||||||
|  |     class MongoDBSessionTest(_BaseMongoDBSessionTest): | ||||||
|  |         pass | ||||||
|  |  | ||||||
|  |  | ||||||
| class MongoAuthTest(unittest.TestCase): | class MongoAuthTest(unittest.TestCase): | ||||||
|     user_data = { |     user_data = { | ||||||
|         'username': 'user', |         'username': 'user', | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user