tests/delayedquery.py
author Radek Brich <radek.brich@devl.cz>
Fri, 25 Jul 2014 15:15:16 +0200
changeset 106 db4c582a2abd
parent 104 d8ff52a0390f
permissions -rwxr-xr-x
Fix autocommit mode in oursql.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/env python3
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
import logging
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
import time
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
78
64c62ac8f65d Rename config module to configparser.
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
     6
from tests.config import Config
104
d8ff52a0390f Rename to pydbkit.
Radek Brich <radek.brich@devl.cz>
parents: 78
diff changeset
     7
from pydbkit import pgmanager
d8ff52a0390f Rename to pydbkit.
Radek Brich <radek.brich@devl.cz>
parents: 78
diff changeset
     8
from pydbkit.delayedquery import DelayedQuery
21
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
if __name__ == '__main__':
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
    cfg = Config('tests.conf')
78
64c62ac8f65d Rename config module to configparser.
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
    13
21
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
    pgm = pgmanager.get_instance()
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
    pgm.create_conn(isolation_level = 'autocommit', **cfg)
78
64c62ac8f65d Rename config module to configparser.
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
    16
21
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
    handler = logging.StreamHandler()
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
    logger = logging.getLogger('pgmanager')
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
    logger.addHandler(handler)
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
    logger.setLevel(logging.DEBUG)
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
    dq = DelayedQuery(pgm)
78
64c62ac8f65d Rename config module to configparser.
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
    23
21
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
    print('add 1')
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
    dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam1'], queryid=1)
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
    dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam1'], queryid=1)
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
    print('after 1')
78
64c62ac8f65d Rename config module to configparser.
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
    28
21
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
    time.sleep(5)
78
64c62ac8f65d Rename config module to configparser.
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
    30
21
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
    print('add 2')
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
    dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam2'])
78
64c62ac8f65d Rename config module to configparser.
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
    33
21
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
    time.sleep(5)
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
    print('after 10')
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
    time.sleep(10)