postgresql-integration-test is a python module that creates a temporary PostgreSQL instance to use for testing your application.
Project description
postgresql-integration-test
Overview
postgresql-integration-test is a python module that creates a temporary PostgreSQL instance to use for testing your application. You will need a working PostgreSQL install. It does not have to be running, the binaries are needed.
Download and Install
To install use pip:
$ pip install postgresql-integration-test
Or clone the repo:
$ git clone https://github.com/jasondcamp/postgresql-integration-test.git
Configuration
Class arguments
The following class arguments can be overridden by passing them in, these arguments will override the config file arguments.
Argument | Description | Default |
---|---|---|
username | Username for database | root |
password | Password for database | root |
host | Host to bind | 127.0.0.1 |
port | Port to bind | random |
postgres_binary | Location of postgres binary | Searches paths |
timeout_start | Timeout to start PostgreSQL | 30 seconds |
timeout_stop | Timeout to stop PostgreSQL | 30 seconds |
log_level | Log level | INFO |
config_file | Configuration file | postgresql-integration-test.cfg |
postgresql-integration-test config file
Default settings can be overridden in a config file. The default name is posgresql-integration-test.cfg
in the local directory and can be overridden by passing in the config
option to the instance creation.
Example config
database:
host: '127.0.0.1'
port: '9999'
username: 'root'
password: 'test'
postgresql_binary: '/usr/sbin/mysqld'
general:
log_level: 'DEBUG'
timeout_start: 30
timeout_stop: 30
Usage
import
from postgresql_integration_test import PostgreSQL
run
Starts up the postgresql server
postgresql = PostgreSQL()
instance = postgresql.run()
stop
Stops the postgres server
postgresql.stop()
Example Code
#!/usr/bin/env python3
from postgresql_integration_test import PostgreSQL
import psycopg2
postgresql = PostgreSQL(config='/some/dir/postgresql-integration-test.cfg')
instance = postgres.run()
# Make query to database
cnx = mysql.connector.connect(user=instance.username, password=instance.password,
host=instance.host, port=instance.port)
cursor = cnx.cursor()
cursor.execute(f"SHOW databases;")
for db in cursor:
print(db[0])
cursor.close()
cnx.close()
mysqld.stop()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for postgresql-integration-test-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 969e24b5398cafc186d716c568f10fc6ffd07ab684a27b829101124ab1c7d109 |
|
MD5 | 987a7614c8760a822bc8277cf55f1003 |
|
BLAKE2b-256 | 749439b00266b65e85bbac7177bace5fa89d9dc166ba9472619c718bf7a0bf93 |
Hashes for postgresql_integration_test-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc1cabe81bdaf29c491bf8b9e73b45c0fa661f6bc0ed4e9426dac5551f34f697 |
|
MD5 | 9a3dd923e2b75e69868a00419174bf59 |
|
BLAKE2b-256 | 4ac30c84d545f6d4682194a15c8bc51d033c4eaff94ea0558364efadd3df5d9a |