def test_get_store(self): conf.settings.MIDDLEWARE_CLASSES += ( "storm.django.middleware.ZopeTransactionMiddleware",) conf.settings.STORM_STORES = {"name": "sqlite:"} store = stores.get_store("name") self.assertTrue(isinstance(store, Store)) # Calling get_store() twice returns the same store. store2 = stores.get_store("name") self.assertTrue(store is store2)
def test_create_wrapper(self): wrapper = make_wrapper() self.assertTrue(isinstance(wrapper, self.get_wrapper_class())) # The wrapper uses the same database connection as the store. store = stores.get_store("django") self.assertEqual(store._connection._raw_connection, wrapper.connection)
def _get_connection(self): if self._store is None: self._store = get_store(settings.DATABASE_NAME) # Make sure that the store is registered with the transaction # manager: we don't know what the connection will be used for. self._store._event.emit("register-transaction") self._store._connection._ensure_connected() return self._store._connection._raw_connection
def test_get_store_returns_per_thread_stores(self): conf.settings.MIDDLEWARE_CLASSES += ( "storm.django.middleware.ZopeTransactionMiddleware",) conf.settings.STORM_STORES = {"name": "sqlite:"} store = stores.get_store("name") other_stores = [] def f(): other_stores.append(stores.get_store("name")) thread = threading.Thread(target=f) thread.start() thread.join() self.assertEqual(len(other_stores), 1) self.assertNotEqual(other_stores[0], store)
def f(): other_stores.append(stores.get_store("name"))
def drop_tables(self): store = stores.get_store("django") store.execute("DROP TABLE django_test") transaction.commit()
def create_tables(self): store = stores.get_store("django") store.execute("CREATE TABLE django_test (" " id INT AUTO_INCREMENT PRIMARY KEY," " title TEXT) ENGINE=InnoDB") transaction.commit()
def create_tables(self): store = stores.get_store("django") store.execute("CREATE TABLE django_test (" " id SERIAL PRIMARY KEY," " title TEXT)") transaction.commit()
def test_using_wrapper_joins_transaction(self): wrapper = make_wrapper() cursor = wrapper.cursor() cursor.execute("SELECT 1") self.assertInTransaction(stores.get_store("django"))
def _get_connection(self): if self._store is None: self._store = get_store(settings.DATABASE_NAME) return self._store._connection._raw_connection