Create test database. :param hostname: string :param username: string :param password: string :param dbname: string :param port: int :return:
(hostname='localhost', username=None, password=None, dbname=None, port=None)
| 7 | |
| 8 | |
| 9 | def create_db(hostname='localhost', username=None, password=None, dbname=None, port=None): |
| 10 | """Create test database. |
| 11 | |
| 12 | :param hostname: string |
| 13 | :param username: string |
| 14 | :param password: string |
| 15 | :param dbname: string |
| 16 | :param port: int |
| 17 | :return: |
| 18 | |
| 19 | """ |
| 20 | cn = create_cn(hostname, password, username, 'postgres', port) |
| 21 | |
| 22 | # ISOLATION_LEVEL_AUTOCOMMIT = 0 |
| 23 | # Needed for DB creation. |
| 24 | cn.set_isolation_level(0) |
| 25 | |
| 26 | with cn.cursor() as cr: |
| 27 | cr.execute('drop database if exists %s', (AsIs(dbname),)) |
| 28 | cr.execute('create database %s', (AsIs(dbname),)) |
| 29 | |
| 30 | cn.close() |
| 31 | |
| 32 | cn = create_cn(hostname, password, username, dbname, port) |
| 33 | return cn |
| 34 | |
| 35 | |
| 36 | def create_cn(hostname, password, username, dbname, port): |