Commits

Chris Hasenpflug  committed f268673

Tests cleanup. djang.setup() required to avoid Django 1.7 "App registry isn't ready yet." error

  • Participants
  • Parent commits 1327ee3

Comments (0)

Files changed (3)

 import os
 import sys
 
+import django
 from django.conf import settings
 
 BASE_DIR = os.path.dirname(os.path.dirname(__file__))
 if not settings.configured:
     settings.configure(
         INSTALLED_APPS=('django.contrib.auth', 'xenforo'),
-        DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR,'db_test.sqlite3')},}
+        DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR,'db_test.sqlite3')},},
+        PASSWORD_HASHERS = [
+            'xenforo.hashers.XenForoCore12PasswordHasher',
+            'xenforo.hashers.XenForoSHA256PasswordHasher',
+            'xenforo.hashers.XenForoSHA1PasswordHasher',
+            'xenforo.hashers.VBulletinPasswordHasher',
+        ]
     )
-
+try:
+    django.setup()
+except AttributeError:
+    pass
 
 def runtests(args=None):
     import pytest

File xenforo/tests/test_hashers.py

 
 from unittest import TestCase, skipUnless
 
-from django.conf.global_settings import PASSWORD_HASHERS as default_hashers
 from django.contrib.auth.hashers import (is_password_usable,
     check_password, load_hashers, make_password, identify_hasher)
 
     bcrypt = None
 
 class TestHashers(TestCase):
-    def setUp(self):
-        load_hashers(password_hashers=default_hashers + (
-            'xenforo.hashers.XenForoCore12PasswordHasher',
-            'xenforo.hashers.XenForoSHA256PasswordHasher',
-            'xenforo.hashers.XenForoSHA1PasswordHasher',
-            'xenforo.hashers.VBulletinPasswordHasher',
-        ))
-
     def test_xenforo_sha256(self):
         encoded = make_password('lètmein', 'seasalt', 'xenforo_sha256')
         self.assertEqual(encoded,

File xenforo/tests/test_middleware.py

         self.request.META = {settings.XENFORO_IP_ADDRESS_KEY: '192.0.2.30',}
         self.request.xf_session = {'user_id': 123, 'ip': 3221226014}
         with patch('xenforo.middleware.connections') as mockdb:
-            mockdb[settings.XENFORO_DATABASE].cursor().fetchone.return_value = None
+            mockdb[settings.XENFORO_DATABASE].cursor().fetchall.return_value = ()
             mockdb[settings.XENFORO_DATABASE].cursor().description.return_value = (('user_id',),('username',))
             self.middleware.process_request(self.request)
         self.assertEqual(self.request.xf_user_id, None)