Metadata-Version: 2.1
Name: postgresql-integration-test
Version: 0.0.2
Summary: postgresql-integration-test is a python module that creates a temporary PostgreSQL instance to use for testing your application.
Author-email: Jason Camp <me@jason.camp>, Ian Meyer <k@imeyer.io>
License: Apache
Project-URL: Homepage, https://github.com/jasondcamp/postgresql-integration-test
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: psycopg2-binary >=2.9.9
Requires-Dist: pyyaml >=6.0.1
Provides-Extra: tests
Requires-Dist: pytest >=8.1.1 ; extra == 'tests'
Requires-Dist: pytest-env ==0.8.1 ; extra == 'tests'
Requires-Dist: pytest-cov ==4.0.0 ; extra == 'tests'
Requires-Dist: coverage >=7.2.1 ; extra == 'tests'
Requires-Dist: mock ==5.0.1 ; extra == 'tests'
Requires-Dist: pytest-mock ==3.10.0 ; extra == 'tests'
Requires-Dist: pytest-skip-slow ==0.0.5 ; extra == 'tests'

# postgresql-integration-test
![](https://img.shields.io/pypi/v/postgresql-integration-test.svg) ![](https://img.shields.io/badge/status-alpha-red) ![](https://github.com/jasondcamp/postgresql-integration-test/actions/workflows/postgresql-integration-test.yml/badge.svg)  ![](https://img.shields.io/pypi/pyversions/postgresql-integration-test.svg) ![](https://img.shields.io/badge/license-Apache-lightgrey)

![](https://api.codeclimate.com/v1/badges/c4e922d83662be40871c/maintainability) ![](https://api.codeclimate.com/v1/badges/c4e922d83662be40871c/test_coverage)

## 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()
```



