Exemplo n.º 1
0
    def setUpClass(cls):
        if cls.install_apps:
            # When running this app via `./manage.py test fluent_pages`, auto install the test app + models.
            run_migrate = False
            for appname in cls.install_apps:
                if appname not in settings.INSTALLED_APPS:
                    print('Adding {0} to INSTALLED_APPS'.format(appname))
                    settings.INSTALLED_APPS = (appname,) + tuple(settings.INSTALLED_APPS)
                    run_migrate = True

                    testapp = import_module(appname)

                    # Flush caches
                    if django.VERSION < (1, 9):
                        from django.template.loaders import app_directories
                        from django.db.models import loading
                        loading.cache.loaded = False

                        app_directories.app_template_dirs += (
                            os.path.join(os.path.dirname(testapp.__file__), 'templates'),
                        )
                    else:
                        from django.template.utils import get_app_template_dirs
                        get_app_template_dirs.cache_clear()

            if run_migrate:
                call_command('migrate', verbosity=0)

        # This also runs setUpTestData
        super(AppTestCase, cls).setUpClass()

        if django.VERSION < (1, 8):
            # Newer Django versions wrap this in a reversable translation,
            # for older Django versions emulate the method call only.
            cls.setUpTestData()
Exemplo n.º 2
0
    def setUpClass(cls):
        super(AppTestCase, cls).setUpClass()

        # Avoid early import, triggers AppCache
        User = get_user_model()

        if cls.install_apps:
            # When running this app via `./manage.py test fluent_pages`, auto install the test app + models.
            run_syncdb = False
            for appname in cls.install_apps:
                if appname not in settings.INSTALLED_APPS:
                    print('Adding {0} to INSTALLED_APPS'.format(appname))
                    settings.INSTALLED_APPS = (appname, ) + tuple(
                        settings.INSTALLED_APPS)
                    run_syncdb = True

                    testapp = import_module(appname)

                    # Flush caches
                    from django.template.utils import get_app_template_dirs
                    get_app_template_dirs.cache_clear()

            if run_syncdb:
                call_command('migrate', verbosity=0)

        # Create basic objects
        # 1.4 does not create site automatically with the defined SITE_ID, 1.3 does.
        Site.objects.get_or_create(id=settings.SITE_ID,
                                   defaults=dict(domain='django.localhost',
                                                 name='django at localhost'))
        cls.user, _ = User.objects.get_or_create(
            is_superuser=True, is_staff=True, username="******")
Exemplo n.º 3
0
    def setUpClass(cls):
        super(AppTestCase, cls).setUpClass()

        # Avoid early import, triggers AppCache
        User = get_user_model()

        if cls.install_apps:
            # When running this app via `./manage.py test fluent_pages`, auto install the test app + models.
            run_syncdb = False
            for appname in cls.install_apps:
                if appname not in settings.INSTALLED_APPS:
                    print('Adding {0} to INSTALLED_APPS'.format(appname))
                    settings.INSTALLED_APPS = (appname, ) + tuple(
                        settings.INSTALLED_APPS)
                    run_syncdb = True

                    testapp = import_module(appname)

                    # Flush caches
                    if django.VERSION < (1, 9):
                        from django.template.loaders import app_directories
                        from django.db.models import loading
                        loading.cache.loaded = False

                        app_directories.app_template_dirs += (os.path.join(
                            os.path.dirname(testapp.__file__), 'templates'), )
                    else:
                        from django.template.utils import get_app_template_dirs
                        get_app_template_dirs.cache_clear()

            if run_syncdb:
                if django.VERSION < (1, 7):
                    call_command(
                        'syncdb',
                        verbosity=0)  # may run south's overlaid version
                else:
                    call_command('migrate', verbosity=0)

        # Create basic objects
        # 1.4 does not create site automatically with the defined SITE_ID, 1.3 does.
        Site.objects.get_or_create(id=settings.SITE_ID,
                                   defaults=dict(domain='django.localhost',
                                                 name='django at localhost'))
        cls.user, _ = User.objects.get_or_create(is_superuser=True,
                                                 is_staff=True,
                                                 username="******")

        # Create tree.
        # Reset data first because the testcase class setup runs outside the transaction
        UrlNode.objects.all().delete()
        cls.setUpTree()
def update_installed_apps(**kwargs):
    if kwargs['setting'] == 'INSTALLED_APPS':
        # Rebuild any AppDirectoriesFinder instance.
        from django.contrib.staticfiles.finders import get_finder
        get_finder.cache_clear()
        # Rebuild management commands cache
        from django.core.management import get_commands
        get_commands.cache_clear()
        # Rebuild get_app_template_dirs cache.
        from django.template.utils import get_app_template_dirs
        get_app_template_dirs.cache_clear()
        # Rebuild translations cache.
        from django.utils.translation import trans_real
        trans_real._translations = {}
Exemplo n.º 5
0
def update_installed_apps(**kwargs):
    if kwargs['setting'] == 'INSTALLED_APPS':
        # Rebuild any AppDirectoriesFinder instance.
        from django.contrib.staticfiles.finders import get_finder
        get_finder.cache_clear()
        # Rebuild management commands cache
        from django.core.management import get_commands
        get_commands.cache_clear()
        # Rebuild get_app_template_dirs cache.
        from django.template.utils import get_app_template_dirs
        get_app_template_dirs.cache_clear()
        # Rebuild translations cache.
        from django.utils.translation import trans_real
        trans_real._translations = {}
Exemplo n.º 6
0
    def setUpClass(cls):
        super(AppTestCase, cls).setUpClass()

        # Avoid early import, triggers AppCache
        User = get_user_model()

        if cls.install_apps:
            # When running this app via `./manage.py test fluent_pages`, auto install the test app + models.
            run_syncdb = False
            for appname in cls.install_apps:
                if appname not in settings.INSTALLED_APPS:
                    print('Adding {0} to INSTALLED_APPS'.format(appname))
                    settings.INSTALLED_APPS = (appname,) + tuple(settings.INSTALLED_APPS)
                    run_syncdb = True

                    testapp = import_module(appname)

                    # Flush caches
                    if django.VERSION < (1, 9):
                        from django.template.loaders import app_directories
                        from django.db.models import loading
                        loading.cache.loaded = False

                        app_directories.app_template_dirs += (
                            os.path.join(os.path.dirname(testapp.__file__), 'templates'),
                        )
                    else:
                        from django.template.utils import get_app_template_dirs
                        get_app_template_dirs.cache_clear()

            if run_syncdb:
                if django.VERSION < (1, 7):
                    call_command('syncdb', verbosity=0)  # may run south's overlaid version
                else:
                    call_command('migrate', verbosity=0)

        # Create basic objects
        # 1.4 does not create site automatically with the defined SITE_ID, 1.3 does.
        Site.objects.get_or_create(id=settings.SITE_ID, defaults=dict(domain='django.localhost', name='django at localhost'))
        cls.user, _ = User.objects.get_or_create(is_superuser=True, is_staff=True, username="******")

        # Create tree.
        # Reset data first because the testcase class setup runs outside the transaction
        UrlNode.objects.all().delete()
        cls.setUpTree()
Exemplo n.º 7
0
    def setUpClass(cls):
        if cls.install_apps:
            # When running this app via `./manage.py test fluent_pages`, auto install the test app + models.
            run_migrate = False
            for appname in cls.install_apps:
                if appname not in settings.INSTALLED_APPS:
                    print('Adding {0} to INSTALLED_APPS'.format(appname))
                    settings.INSTALLED_APPS = (appname,) + tuple(settings.INSTALLED_APPS)
                    run_migrate = True

                    testapp = import_module(appname)

                    # Flush caches
                    from django.template.utils import get_app_template_dirs
                    get_app_template_dirs.cache_clear()

            if run_migrate:
                call_command('migrate', verbosity=0)

        # This also runs setUpTestData
        super(AppTestCase, cls).setUpClass()
Exemplo n.º 8
0
import os