summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurélien Bompard <aurelien@bompard.org>2013-07-23 11:45:40 +0200
committerAurélien Bompard <aurelien@bompard.org>2013-07-23 11:45:40 +0200
commit8333abc9062ff0e7345dec41db972c0992c534e0 (patch)
treee47334f27f56e86eca6e01812a21cfee9292959f
parentbf2de4165365d96dcafdfc769ac6020348a45c6e (diff)
downloadhyperkitty-8333abc9062ff0e7345dec41db972c0992c534e0.tar.gz
hyperkitty-8333abc9062ff0e7345dec41db972c0992c534e0.tar.xz
hyperkitty-8333abc9062ff0e7345dec41db972c0992c534e0.zip
Centralize settings modifications for unittests in a single class
-rw-r--r--hyperkitty.spec3
-rw-r--r--hyperkitty/tests/test_lib.py2
-rw-r--r--hyperkitty/tests/test_models.py2
-rw-r--r--hyperkitty/tests/test_templatetags.py2
-rw-r--r--hyperkitty/tests/test_views.py2
-rw-r--r--hyperkitty/tests/utils.py50
-rw-r--r--hyperkitty/tests_conf/__init__.py0
-rw-r--r--hyperkitty/tests_conf/settings_tests.py21
8 files changed, 55 insertions, 27 deletions
diff --git a/hyperkitty.spec b/hyperkitty.spec
index 39060f8..71e595b 100644
--- a/hyperkitty.spec
+++ b/hyperkitty.spec
@@ -127,9 +127,8 @@ touch --reference hyperkitty_standalone/settings.py \
%check
touch hyperkitty_standalone/__init__.py
-cp hyperkitty/tests_conf/settings_tests.py hyperkitty_standalone/settings_local.py
%{__python} hyperkitty_standalone/manage.py test --pythonpath=`pwd` hyperkitty
-rm -f hyperkitty_standalone/__init__.py hyperkitty_standalone/settings_local.py
+rm -f hyperkitty_standalone/__init__.py
%post
diff --git a/hyperkitty/tests/test_lib.py b/hyperkitty/tests/test_lib.py
index 4b9b778..19f31d1 100644
--- a/hyperkitty/tests/test_lib.py
+++ b/hyperkitty/tests/test_lib.py
@@ -21,7 +21,7 @@
import datetime
-from django.test import TestCase
+from hyperkitty.tests.utils import TestCase
from hyperkitty.lib.view_helpers import get_display_dates, paginate
diff --git a/hyperkitty/tests/test_models.py b/hyperkitty/tests/test_models.py
index 120e571..bcbcf58 100644
--- a/hyperkitty/tests/test_models.py
+++ b/hyperkitty/tests/test_models.py
@@ -19,7 +19,7 @@
# Author: Aamir Khan <syst3m.w0rm@gmail.com>
#
-from django.test import TestCase
+from hyperkitty.tests.utils import TestCase
from hyperkitty.models import Rating, Tag
class RatingTestCase(TestCase):
diff --git a/hyperkitty/tests/test_templatetags.py b/hyperkitty/tests/test_templatetags.py
index f4d9d4d..6763992 100644
--- a/hyperkitty/tests/test_templatetags.py
+++ b/hyperkitty/tests/test_templatetags.py
@@ -19,7 +19,7 @@
# Author: Aurelien Bompard <abompard@fedoraproject.org>
#
-from django.test import TestCase
+from hyperkitty.tests.utils import TestCase
from hyperkitty.templatetags.hk_generic import snip_quoted
diff --git a/hyperkitty/tests/test_views.py b/hyperkitty/tests/test_views.py
index b39544c..bd672b2 100644
--- a/hyperkitty/tests/test_views.py
+++ b/hyperkitty/tests/test_views.py
@@ -25,7 +25,7 @@ import datetime
from mock import Mock
import django.utils.simplejson as json
-from django.test import TestCase
+from hyperkitty.tests.utils import TestCase
from django.test.client import Client, RequestFactory
from django.contrib.auth.models import User, AnonymousUser
from django.core.urlresolvers import reverse
diff --git a/hyperkitty/tests/utils.py b/hyperkitty/tests/utils.py
new file mode 100644
index 0000000..5124f39
--- /dev/null
+++ b/hyperkitty/tests/utils.py
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+# Copyright (C) 1998-2012 by the Free Software Foundation, Inc.
+#
+# This file is part of HyperKitty.
+#
+# HyperKitty is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# HyperKitty is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# HyperKitty. If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: Aurelien Bompard <abompard@fedoraproject.org>
+#
+
+
+from django.test import TestCase as DjangoTestCase
+from django.conf import settings
+
+
+OVERRIDE_SETTINGS = {
+ "TEMPLATE_DEBUG": True,
+ "ASSETS_DEBUG": True,
+ "USE_SSL": False,
+ "KITTYSTORE_URL": 'sqlite:',
+ "KITTYSTORE_SEARCH_INDEX": None,
+ "KITTYSTORE_DEBUG": False,
+ "USE_MOCKUPS": False,
+}
+
+
+class TestCase(DjangoTestCase):
+
+ def _pre_setup(self):
+ super(TestCase, self)._pre_setup()
+ self._old_settings = {}
+ for key, value in OVERRIDE_SETTINGS.iteritems():
+ self._old_settings[key] = getattr(settings, key)
+ setattr(settings, key, value)
+
+ def _post_teardown(self):
+ super(TestCase, self)._post_teardown()
+ for key, value in self._old_settings.iteritems():
+ setattr(settings, key, value)
diff --git a/hyperkitty/tests_conf/__init__.py b/hyperkitty/tests_conf/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/hyperkitty/tests_conf/__init__.py
+++ /dev/null
diff --git a/hyperkitty/tests_conf/settings_tests.py b/hyperkitty/tests_conf/settings_tests.py
deleted file mode 100644
index 59e53c1..0000000
--- a/hyperkitty/tests_conf/settings_tests.py
+++ /dev/null
@@ -1,21 +0,0 @@
-#
-# This module is only used to run the unit tests.
-#
-
-DEBUG = True
-TEMPLATE_DEBUG = DEBUG
-ASSETS_DEBUG = DEBUG
-USE_SSL = False
-DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.sqlite3',
- 'NAME': ':memory:',
- 'USER': '', # Not used with sqlite3.
- 'PASSWORD': '', # Not used with sqlite3.
- 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
- 'PORT': '', # Set to empty string for default. Not used with sqlite3.
- }
-}
-KITTYSTORE_URL = 'sqlite:'
-KITTYSTORE_DEBUG=False
-USE_MOCKUPS = False