def _pre_setup(self): """Munge DB infrastructure before the superclass gets a chance to set up the DBs.""" # clear all module state pindb._init_state() # patch up the db system to use the effective router settings (see override_settings) # we can't just reconstruct objects here because # lots of places do from foo import baz, so they have # a local reference to an object we can't replace. # so reach in and (gulp) mash the object's state. if dj_VERSION < (1, 4): for conn in dj_db.connections._connections.values(): conn.close() dj_db.connections._connections = {} else: for conn in dj_db.connections.all(): conn.close() dj_db.connections._connections = local() dj_db.connections.databases = settings.DATABASES def make_router(import_path): module_path, class_name = import_path.rsplit('.', 1) mod = importlib.import_module(module_path) return getattr(mod, class_name)() dj_db.router.routers = [ make_router(import_path) for import_path in settings.DATABASE_ROUTERS] dj_db.connection = dj_db.connections[dj_db.DEFAULT_DB_ALIAS] dj_db.backend = dj_db.load_backend(dj_db.connection.settings_dict['ENGINE']) self.shim_runner = DjangoTestSuiteRunner() self.setup_databases() super(PinDbTestCase, self)._pre_setup()
def test_init_happens_only_once(self): self.assertEqual(set(['wark']), pindb._locals.pinned_set) pindb._init_state() self.assertEqual(set(), pindb._locals.pinned_set) pindb._locals.pinned_set.add('wargle') pindb._init_state() self.assertEqual(set(['wargle']), pindb._locals.pinned_set) # except now we'll force inited back: pindb._locals.inited = False pindb._init_state() self.assertEqual(set(), pindb._locals.pinned_set)
def test_init_worked(self): self.assertEqual(set(['wark']), pindb._locals.pinned_set) pindb._init_state() self.assertEqual(set(), pindb._locals.pinned_set)