Run a testcase with custom INSTALLED_APPS

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from django.core.management import call_command
from django.db.models import loading
from django.test import TestCase
from django.test.utils import override_settings


class CustomSettingsTestCase(TestCase):
    """
    A TestCase which makes extra models available in the Django project, just for testing.
    Based on http://djangosnippets.org/snippets/1011/ in Django 1.4 style.
    """
    new_settings = {}
    _override = None


    @classmethod
    def setUpClass(cls):
        cls._override = override_settings(**cls.new_settings)
        cls._override.enable()
        if 'INSTALLED_APPS' in cls.new_settings:
            cls.syncdb()


    @classmethod
    def tearDownClass(cls):
        cls._override.disable()
        if 'INSTALLED_APPS' in cls.new_settings:
            cls.syncdb()


    @classmethod
    def syncdb(cls):
        loading.cache.loaded = False
        call_command('syncdb', verbosity=0)

More like this

  1. Test runner that installs 'tests' packages as apps by adrian_lc 7 months ago
  2. Use django-social-auth & Google Accounts for admin login by pmdarrow 1 year, 4 months ago
  3. Template tag to create mailto links with options by celopes 4 years, 10 months ago
  4. yandex maps templatetag by coolchevy 1 year, 11 months ago
  5. Simple Plone Migration by msm-art 6 years, 3 months ago

Comments

(Forgotten your password?)