Skip to main content

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
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 postgresql-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'
  postgresql_binary: '/usr/sbin/postgres'

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

postgres = PostgreSQL(config='/some/dir/postgresql-integration-test.cfg')
instance = postgres.run()

# Make query to database
cnx = psycopg2.connect(
    user=instance.username,
    host=instance.host,
    port=instance.port,
    database="test",
)
cursor = cnx.cursor()
cursor.execute("SELECT id FROM some_table")
for _result in cursor:
    result = _result
cursor.close()
cnx.close()

postgres.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

postgresql-integration-test-0.0.4.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file postgresql-integration-test-0.0.4.tar.gz.

File metadata

File hashes

Hashes for postgresql-integration-test-0.0.4.tar.gz
Algorithm Hash digest
SHA256 ae582b53d762f9c7e80a92ed0f8a282a1495fb46820780ece3935aacb854f84d
MD5 3c505d38ed058e323c869c0e0f86b09e
BLAKE2b-256 fcecf5b2f780045cba27f79cc7875cf8df495716378a94a9ab346c57ec96b749

See more details on using hashes here.

File details

Details for the file postgresql_integration_test-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for postgresql_integration_test-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b2aeae145b546e2da9d4f413d212163404577f9a894904a80f30cc95d9d1ca56
MD5 6c95339d1401a3e30bd254e7406491e0
BLAKE2b-256 7676d7c27303ec04cf6fff20aafe0f7bd82654c4d6703018d3fb64145faf8097

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page