Beispiel #1
0
 def test_foreign_keys(self):
     foreign_keys_values = {"ON": 1, "OFF": 0}
     for value in foreign_keys_values:
         database = SQLite(
             URI("sqlite:%s?foreign_keys=%s" % (self.get_path(), value)))
         connection = database.connect()
         result = connection.execute("PRAGMA foreign_keys").get_one()[0]
         self.assertEqual(result, foreign_keys_values[value])
Beispiel #2
0
 def test_synchronous(self):
     synchronous_values = {"OFF": 0, "NORMAL": 1, "FULL": 2}
     for value in synchronous_values:
         database = SQLite(
             URI("sqlite:%s?synchronous=%s" % (self.get_path(), value)))
         connection = database.connect()
         result = connection.execute("PRAGMA synchronous")
         self.assertEqual(result.get_one()[0], synchronous_values[value])
Beispiel #3
0
 def test_foreign_keys(self):
     foreign_keys_values = {"ON": 1, "OFF": 0}
     for value in foreign_keys_values:
         database = SQLite(URI("sqlite:%s?foreign_keys=%s" %
                               (self.get_path(), value)))
         connection = database.connect()
         result = connection.execute("PRAGMA foreign_keys").get_one()[0]
         self.assertEquals(result,
                           foreign_keys_values[value])
Beispiel #4
0
 def test_synchronous(self):
     synchronous_values = {"OFF": 0, "NORMAL": 1, "FULL": 2}
     for value in synchronous_values:
         database = SQLite(URI("sqlite:%s?synchronous=%s" %
                               (self.get_path(), value)))
         connection = database.connect()
         result = connection.execute("PRAGMA synchronous")
         self.assertEquals(result.get_one()[0],
                           synchronous_values[value])
Beispiel #5
0
 def test_foreign_keys_persistency_to_rollback(self):
     foreign_keys_values = {"ON": 1, "OFF": 0}
     for value in foreign_keys_values:
         database = SQLite(
             URI("sqlite:%s?foreign_keys=%s" % (self.get_path(), value)))
         connection = database.connect()
         connection.execute("CREATE TABLE test (id INTEGER PRIMARY KEY)")
         connection.rollback()
         result = connection.execute("PRAGMA foreign_keys").get_one()[0]
         self.assertEqual(result, foreign_keys_values[value])
Beispiel #6
0
 def test_journal(self):
     journal_values = {"DELETE": u'delete', "TRUNCATE": u'truncate',
                       "PERSIST": u'persist', "MEMORY": u'memory',
                       "WAL": u'wal', "OFF": u'off'}
     for value in journal_values:
         database = SQLite(URI("sqlite:%s?journal_mode=%s" %
                               (self.get_path(), value)))
         connection = database.connect()
         result = connection.execute("PRAGMA journal_mode").get_one()[0]
         self.assertEquals(result,
                           journal_values[value])
Beispiel #7
0
 def test_foreign_keys_persistency_to_rollback(self):
     foreign_keys_values = {"ON": 1, "OFF": 0}
     for value in foreign_keys_values:
         database = SQLite(URI("sqlite:%s?foreign_keys=%s" %
                               (self.get_path(), value)))
         connection = database.connect()
         connection.execute("CREATE TABLE test (id INTEGER PRIMARY KEY)")
         connection.rollback()
         result = connection.execute("PRAGMA foreign_keys").get_one()[0]
         self.assertEquals(result,
                           foreign_keys_values[value])
Beispiel #8
0
 def test_journal(self):
     journal_values = {
         "DELETE": u'delete',
         "TRUNCATE": u'truncate',
         "PERSIST": u'persist',
         "MEMORY": u'memory',
         "WAL": u'wal',
         "OFF": u'off'
     }
     for value in journal_values:
         database = SQLite(
             URI("sqlite:%s?journal_mode=%s" % (self.get_path(), value)))
         connection = database.connect()
         result = connection.execute("PRAGMA journal_mode").get_one()[0]
         self.assertEqual(result, journal_values[value])
Beispiel #9
0
 def test_journal_persistency_to_rollback(self):
     journal_values = {
         "DELETE": u'delete',
         "TRUNCATE": u'truncate',
         "PERSIST": u'persist',
         "MEMORY": u'memory',
         "WAL": u'wal',
         "OFF": u'off'
     }
     for value in journal_values:
         database = SQLite(
             URI("sqlite:%s?journal_mode=%s" % (self.get_path(), value)))
         connection = database.connect()
         connection.execute("CREATE TABLE test (id INTEGER PRIMARY KEY)")
         connection.rollback()
         result = connection.execute("PRAGMA journal_mode").get_one()[0]
         assert result == journal_values[value]
Beispiel #10
0
 def test_block_access_with_multiple_stores(self):
     """
     If multiple L{Store}s are passed to L{block_access} they will all be
     blocked until the managed context is left.
     """
     database = SQLite(URI("sqlite:%s" % self.make_path()))
     store = Store(database)
     with block_access(self.store, store):
         self.assertRaises(ConnectionBlockedError, self.store.execute,
                           "SELECT 1")
         self.assertRaises(ConnectionBlockedError, store.execute,
                           "SELECT 1")
Beispiel #11
0
 def __init__(self, uri):
     SQLite.__init__(self, uri)
Beispiel #12
0
 def __init__(self, uri):
     SQLite.__init__(self, uri)
            del self[key]
        except KeyError, k:
            raise AttributeError, k

    def __repr__(self):
        return '<Storage ' + dict.__repr__(self) + '>'

    def __getstate__(self):
        return dict(self)

    def __setstate__(self, value):
        for (k, v) in value.items():
            self[k] = v

def randomStr(length, num=True):
    """
    Returns a random a mixed lowercase, uppercase, alfanumerical (if num True)
    string long length
    """
    chars = string.ascii_lowercase + string.ascii_uppercase
    if num:
        chars += string.digits
    return ''.join(random.choice(chars) for x in range(length))

from oonib import config

database = SQLite(URI(config.main.database_uri))
db_threadpool = ThreadPool(0, config.main.db_threadpool_size)
db_threadpool.start()
transactor = Transactor(db_threadpool)
Beispiel #14
0
 def raw_connect(self):
     connection = SQLite.raw_connect(self)
     connection.execute("PRAGMA foreign_keys = ON;")
     return connection
Beispiel #15
0
 def create_database(self):
     self.database = SQLite(
         URI("sqlite:%s?synchronous=OFF" % self.make_path()))
Beispiel #16
0
 def create_database(self):
     self.database = SQLite(
         URI("sqlite:%s?synchronous=OFF&timeout=0" % self.get_path()))
Beispiel #17
0
 def setUp(self):
     super(BlockAccessTest, self).setUp()
     database = SQLite(URI("sqlite:"))
     self.store = Store(database)