Beispiel #1
0
 def test_table_exists(self):
     try:
         app_cache.set_available_apps(settings.INSTALLED_APPS)
         call_command('migrate', verbosity=0)
     finally:
         app_cache.unset_available_apps()
     from .app1.models import ProxyModel
     from .app2.models import NiceModel
     self.assertEqual(NiceModel.objects.all().count(), 0)
     self.assertEqual(ProxyModel.objects.all().count(), 0)
Beispiel #2
0
    def _pre_setup(self):
        """Performs any pre-test setup. This includes:

        * If the class has an 'available_apps' attribute, restricting the app
          cache 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:
            app_cache.set_available_apps(self.available_apps)
            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:
                app_cache.unset_available_apps()
            raise
Beispiel #3
0
    def _post_teardown(self):
        """Performs any post-test things. This includes:

        * Flushing the contents of the database, to leave a clean slate. If
          the class has an 'available_apps' attribute, post_migrate isn't fired.
        * Force-closing the connection, so the next test gets a clean cursor.
        """
        try:
            self._fixture_teardown()
            super(TransactionTestCase, self)._post_teardown()
            # Some DB cursors include SQL statements as part of cursor
            # creation. If you have a test that does rollback, the effect of
            # these statements is lost, which can effect the operation of
            # tests (e.g., losing a timezone setting causing objects to be
            # created with the wrong time). To make sure this doesn't happen,
            # get a clean connection at the start of every test.
            for conn in connections.all():
                conn.close()
        finally:
            app_cache.unset_available_apps()