Esempio n. 1
0
 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)
Esempio n. 2
0
    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)
Esempio n. 3
0
    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)
Esempio n. 4
0
 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
Esempio n. 5
0
 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
Esempio n. 6
0
    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)
Esempio n. 7
0
 def f():
     other_stores.append(stores.get_store("name"))
Esempio n. 8
0
 def drop_tables(self):
     store = stores.get_store("django")
     store.execute("DROP TABLE django_test")
     transaction.commit()
Esempio n. 9
0
 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()
Esempio n. 10
0
 def create_tables(self):
     store = stores.get_store("django")
     store.execute("CREATE TABLE django_test ("
                   "  id SERIAL PRIMARY KEY,"
                   "  title TEXT)")
     transaction.commit()
Esempio n. 11
0
 def test_using_wrapper_joins_transaction(self):
     wrapper = make_wrapper()
     cursor = wrapper.cursor()
     cursor.execute("SELECT 1")
     self.assertInTransaction(stores.get_store("django"))
Esempio n. 12
0
 def _get_connection(self):
     if self._store is None:
         self._store = get_store(settings.DATABASE_NAME)
     return self._store._connection._raw_connection
Esempio n. 13
0
 def drop_tables(self):
     store = stores.get_store("django")
     store.execute("DROP TABLE django_test")
     transaction.commit()
Esempio n. 14
0
 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()
Esempio n. 15
0
 def create_tables(self):
     store = stores.get_store("django")
     store.execute("CREATE TABLE django_test ("
                   "  id SERIAL PRIMARY KEY,"
                   "  title TEXT)")
     transaction.commit()
Esempio n. 16
0
 def test_using_wrapper_joins_transaction(self):
     wrapper = make_wrapper()
     cursor = wrapper.cursor()
     cursor.execute("SELECT 1")
     self.assertInTransaction(stores.get_store("django"))