Пример #1
0
    def _pre_setup(self):
        """Performs any pre-test setup. This includes:

        * If the class has an 'available_apps' attribute, restricting the app
          registry to these applications, then firing post_migrate -- it must
          run with the correct set of applications for the test case.
        * If the class has a 'fixtures' attribute, installing these fixtures.
        """
        super(TransactionTestCase, self)._pre_setup()
        if self.available_apps is not None:
            apps.set_available_apps(self.available_apps)
            setting_changed.send(sender=settings._wrapped.__class__,
                                 setting='INSTALLED_APPS',
                                 value=self.available_apps,
                                 enter=True)
            for db_name in self._databases_names(include_mirrors=False):
                flush.Command.emit_post_migrate(verbosity=0, interactive=False, database=db_name)
        try:
            self._fixture_setup()
        except Exception:
            if self.available_apps is not None:
                apps.unset_available_apps()
                setting_changed.send(sender=settings._wrapped.__class__,
                                     setting='INSTALLED_APPS',
                                     value=settings.INSTALLED_APPS,
                                     enter=False)

            raise
Пример #2
0
 def test_no_sekizai(self):
     if DJANGO_1_6:
         with self.settings(INSTALLED_APPS=['cms', 'menus']):
             old_libraries = base.libraries
             base.libraries = {}
             old_templatetags_modules = base.templatetags_modules
             base.templatetags_modules = []
             self.assertRaises(TemplateSyntaxError, check, TestOutput())
             base.libraries = old_libraries
             base.templatetags_modules = old_templatetags_modules
     elif DJANGO_1_7:
         from django.apps import apps
         apps.set_available_apps(['cms', 'menus'])
         old_libraries = base.libraries
         base.libraries = {}
         old_templatetags_modules = base.templatetags_modules
         base.templatetags_modules = []
         self.assertRaises(TemplateSyntaxError, check, TestOutput())
         base.libraries = old_libraries
         base.templatetags_modules = old_templatetags_modules
         apps.unset_available_apps()
     else:
         from django.apps import apps
         base.get_templatetags_modules.cache_clear()
         apps.set_available_apps(['cms', 'menus'])
         self.assertCheck(False, errors=2)
         apps.unset_available_apps()
Пример #3
0
 def test_no_sekizai(self):
     if DJANGO_1_6:
         with self.settings(INSTALLED_APPS=['cms', 'menus']):
             old_libraries = base.libraries
             base.libraries = {}
             old_templatetags_modules = base.templatetags_modules
             base.templatetags_modules = []
             self.assertRaises(TemplateSyntaxError, check, TestOutput())
             base.libraries = old_libraries
             base.templatetags_modules = old_templatetags_modules
     elif DJANGO_1_7:
         from django.apps import apps
         apps.set_available_apps(['cms', 'menus'])
         old_libraries = base.libraries
         base.libraries = {}
         old_templatetags_modules = base.templatetags_modules
         base.templatetags_modules = []
         self.assertRaises(TemplateSyntaxError, check, TestOutput())
         base.libraries = old_libraries
         base.templatetags_modules = old_templatetags_modules
         apps.unset_available_apps()
     else:
         from django.apps import apps
         base.get_templatetags_modules.cache_clear()
         apps.set_available_apps(['cms', 'menus'])
         self.assertCheck(False, errors=2)
         apps.unset_available_apps()
Пример #4
0
    def _pre_setup(self):
        """Performs any pre-test setup. This includes:

        * If the class has an 'available_apps' attribute, restricting the app
          registry to these applications, then firing post_migrate -- it must
          run with the correct set of applications for the test case.
        * If the class has a 'fixtures' attribute, installing these fixtures.
        """
        super(TransactionTestCase, self)._pre_setup()
        if self.available_apps is not None:
            apps.set_available_apps(self.available_apps)
            setting_changed.send(sender=settings._wrapped.__class__,
                                 setting='INSTALLED_APPS',
                                 value=self.available_apps,
                                 enter=True)
            for db_name in self._databases_names(include_mirrors=False):
                flush.Command.emit_post_migrate(verbosity=0, interactive=False, database=db_name)
        try:
            self._fixture_setup()
        except Exception:
            if self.available_apps is not None:
                apps.unset_available_apps()
                setting_changed.send(sender=settings._wrapped.__class__,
                                     setting='INSTALLED_APPS',
                                     value=settings.INSTALLED_APPS,
                                     enter=False)

            raise
Пример #5
0
        def _fixture_setup(self):
            for db_name in self._databases_names(include_mirrors=False):
                # Reset sequences
                if self.reset_sequences:
                    self._reset_sequences(db_name)

                # If we need to provide replica initial data from migrated apps,
                # then do so.
                if self.serialized_rollback and hasattr(
                        connections[db_name], "_test_serialized_contents"):
                    if self.available_apps is not None:
                        apps.unset_available_apps()

                    # Use our monkey-patched version of deserialize_db_from_string.
                    BaseTestCases.SlurmExecutionTestCase.deserialize_db_from_string(
                        connections[db_name].creation,
                        connections[db_name]._test_serialized_contents)

                    if self.available_apps is not None:
                        apps.set_available_apps(self.available_apps)

                if self.fixtures:
                    # We have to use this slightly awkward syntax due to the fact
                    # that we're using *args and **kwargs together.
                    call_command('loaddata', *self.fixtures, **{
                        'verbosity': 0,
                        'database': db_name
                    })
Пример #6
0
        def _fixture_setup(self):
            for db_name in self._databases_names(include_mirrors=False):
                # Reset sequences
                if self.reset_sequences:
                    self._reset_sequences(db_name)

                # If we need to provide replica initial data from migrated apps,
                # then do so.
                if self.serialized_rollback and hasattr(connections[db_name], "_test_serialized_contents"):
                    if self.available_apps is not None:
                        apps.unset_available_apps()

                    # Use our monkey-patched version of deserialize_db_from_string.
                    BaseTestCases.SlurmExecutionTestCase.deserialize_db_from_string(
                        connections[db_name].creation,
                        connections[db_name]._test_serialized_contents
                    )

                    if self.available_apps is not None:
                        apps.set_available_apps(self.available_apps)

                if self.fixtures:
                    # We have to use this slightly awkward syntax due to the fact
                    # that we're using *args and **kwargs together.
                    call_command('loaddata', *self.fixtures,
                                 **{'verbosity': 0, 'database': db_name})
Пример #7
0
 def test_no_sekizai(self):
     if DJANGO_1_8:
         from django.apps import apps
         apps.set_available_apps(['cms', 'menus'])
         self.assertCheck(False, errors=2)
         apps.unset_available_apps()
     else:
         from django.apps import apps
         apps.set_available_apps(['cms', 'menus'])
         self.assertCheck(False, errors=2)
         apps.unset_available_apps()
Пример #8
0
def transactional_db(django_db_blocker, request):
    # Django's/Pytest Django's handling of this is garbage
    # The database is wipe of initial data and never repopulated so we have to do
    # all of it ourselves
    django_db_blocker.unblock()
    request.addfinalizer(django_db_blocker.restore)

    from django.test import TransactionTestCase
    test_case = TransactionTestCase(methodName='__init__')
    test_case._pre_setup()

    # Dump all initial data into a string :+1:
    for connection in connections.all():
        if connection.settings_dict['TEST']['MIRROR']:
            continue
        connection._test_serialized_contents = connection.creation.serialize_db_to_string(
        )

    yield None

    test_case.serialized_rollback = True
    test_case._post_teardown()

    # Disconnect post save listeners because they screw up deserialization
    receivers, post_save.receivers = post_save.receivers, []

    if test_case.available_apps is not None:
        apps.unset_available_apps()

    for connection in connections.all():
        if connection.settings_dict['TEST']['MIRROR']:
            connection.close()
            continue
        # Everything has to be in a single transaction to avoid violating key constraints
        # It also makes it run significantly faster
        with transaction.atomic():
            connection.creation.deserialize_db_from_string(
                connection._test_serialized_contents)

    if test_case.available_apps is not None:
        apps.set_available_apps(test_case.available_apps)

    post_save.receivers = receivers
    def _fixture_setup(self):
        for db_name in self._databases_names(include_mirrors=False):
            # Reset sequences
            if self.reset_sequences:
                self._reset_sequences(db_name)

            # If we need to provide replica initial data from migrated apps,
            # then do so.
            if self.serialized_rollback and hasattr(connections[db_name], "_test_serialized_contents"):
                if self.available_apps is not None:
                    apps.unset_available_apps()
                connections[db_name].creation.deserialize_db_from_string(connections[db_name]._test_serialized_contents)
                if self.available_apps is not None:
                    apps.set_available_apps(self.available_apps)

            if self.fixtures:
                # We have to use this slightly awkward syntax due to the fact
                # that we're using *args and **kwargs together.
                call_command("loaddata", *self.fixtures, **{"verbosity": 0, "database": db_name, "skip_checks": True})
Пример #10
0
def transactional_db(django_db_blocker, request):
    # Django's/Pytest Django's handling of this is garbage
    # The database is wipe of initial data and never repopulated so we have to do
    # all of it ourselves
    django_db_blocker.unblock()
    request.addfinalizer(django_db_blocker.restore)

    from django.test import TransactionTestCase
    test_case = TransactionTestCase(methodName='__init__')
    test_case._pre_setup()

    # Dump all initial data into a string :+1:
    for connection in connections.all():
        if connection.settings_dict['TEST']['MIRROR']:
            continue
        connection._test_serialized_contents = connection.creation.serialize_db_to_string()

    yield None

    test_case.serialized_rollback = True
    test_case._post_teardown()

    # Disconnect post save listeners because they screw up deserialization
    receivers, post_save.receivers = post_save.receivers, []

    if test_case.available_apps is not None:
        apps.unset_available_apps()

    for connection in connections.all():
        if connection.settings_dict['TEST']['MIRROR']:
            connection.close()
            continue
        # Everything has to be in a single transaction to avoid violating key constraints
        # It also makes it run significantly faster
        with transaction.atomic():
            connection.creation.deserialize_db_from_string(connection._test_serialized_contents)

    if test_case.available_apps is not None:
        apps.set_available_apps(test_case.available_apps)

    post_save.receivers = receivers
Пример #11
0
 def test_no_sekizai(self):
     if DJANGO_1_6:
         with SettingsOverride(INSTALLED_APPS=['cms', 'menus']):
             old_libraries = base.libraries
             base.libraries = {}
             old_templatetags_modules = base.templatetags_modules
             base.templatetags_modules = []
             self.assertRaises(TemplateSyntaxError, check, TestOutput())
             base.libraries = old_libraries
             base.templatetags_modules = old_templatetags_modules
     else:
         from django.apps import apps
         apps.set_available_apps(['cms', 'menus'])
         old_libraries = base.libraries
         base.libraries = {}
         old_templatetags_modules = base.templatetags_modules
         base.templatetags_modules = []
         self.assertRaises(TemplateSyntaxError, check, TestOutput())
         base.libraries = old_libraries
         base.templatetags_modules = old_templatetags_modules
         apps.unset_available_apps()
Пример #12
0
 def test_no_sekizai(self):
     if DJANGO_1_6:
         with SettingsOverride(INSTALLED_APPS=['cms', 'menus']):
             old_libraries = base.libraries
             base.libraries = {}
             old_templatetags_modules = base.templatetags_modules
             base.templatetags_modules = []
             self.assertRaises(TemplateSyntaxError, check, TestOutput())
             base.libraries = old_libraries
             base.templatetags_modules = old_templatetags_modules
     else:
         from django.apps import apps
         apps.set_available_apps(['cms', 'menus'])
         old_libraries = base.libraries
         base.libraries = {}
         old_templatetags_modules = base.templatetags_modules
         base.templatetags_modules = []
         self.assertRaises(TemplateSyntaxError, check, TestOutput())
         base.libraries = old_libraries
         base.templatetags_modules = old_templatetags_modules
         apps.unset_available_apps()