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)
| 2 | |
| 3 | |
| 4 | def create_db(hostname="localhost", username=None, password=None, dbname=None, port=None): |
| 5 | """Create test database. |
| 6 | |
| 7 | :param hostname: string |
| 8 | :param username: string |
| 9 | :param password: string |
| 10 | :param dbname: string |
| 11 | :param port: int |
| 12 | :return: |
| 13 | |
| 14 | """ |
| 15 | cn = create_cn(hostname, password, username, "postgres", port) |
| 16 | |
| 17 | cn.autocommit = True |
| 18 | with cn.cursor() as cr: |
| 19 | cr.execute(f"drop database if exists {dbname}") |
| 20 | cr.execute(f"create database {dbname}") |
| 21 | |
| 22 | cn.close() |
| 23 | |
| 24 | cn = create_cn(hostname, password, username, dbname, port) |
| 25 | return cn |
| 26 | |
| 27 | |
| 28 | def create_cn(hostname, password, username, dbname, port): |