Metadata-Version: 2.1
Name: django-rdtwt
Version: 1.4.0
Summary: Run Django tests with testcontainers.
Home-page: https://github.com/wonkybream/django-rdtwt
Author: Sampo Lavinen
License: MIT
Keywords: django,testing,testcontainers,docker,test automation
Classifier: Intended Audience :: Developers
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Framework :: Django
Classifier: Framework :: Django :: 3.2
Classifier: Framework :: Django :: 4.0
Classifier: Framework :: Django :: 4.1
Classifier: Framework :: Django :: 4.2
Classifier: Programming Language :: Python
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
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: testcontainers[postgresql]
Requires-Dist: Django
Requires-Dist: psycopg2-binary

# django-rdtwt

[![Static analysis](https://github.com/wonkybream/django-rdtwt/actions/workflows/static-analysis.yml/badge.svg?branch=main)](https://github.com/wonkybream/django-rdtwt/actions/workflows/static-analysis.yml)
[![Tests](https://github.com/wonkybream/django-rdtwt/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/wonkybream/django-rdtwt/actions/workflows/tests.yml)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![PyPI](https://img.shields.io/pypi/v/django-rdtwt)](https://pypi.org/project/django-rdtwt/)

*(Run Django Tests With Testcontainers)*

This targets users who wish to forget setting up a database for tests. There's no manually starting up *Docker compose* or local database with this.

**Note:**

See: [Altering settings at runtime: Django documentation](https://docs.djangoproject.com/en/3.2/topics/settings/#altering-settings-at-runtime)

This test runner changes default database host and port dynamically, because it's quite hard to know database host before-hand in dynamic environments, for example some CI/CD runners.

Still this just works and is quite simple, that's why I haven't spent that much time investigating alternative solutions. 

## Installation

1. Add rdtwt to your INSTALLED_APPS setting like this
    ```python
    INSTALLED_APPS = [
        ...
        'rdtwt',
    ]
    ```

2. Run tests with rdtwt runner,
    ```shell
    python manage.py test --testrunner=rdtwt.runner.PostgresDiscoverRunner
    ```

Though what I really suggest is to put following in your test settings.

```python
# RDTWT SETTINGS
RDTWT_POSTGRESQL_IMAGE = 'postgres:14.1'
TEST_RUNNER = 'rdtwt.runner.PostgresDiscoverRunner'
```

This makes sure that tests run against the PostgreSQL version defined by you. It also adds up to the test confidence, at least they aren't flaky because of database version changing without your knowledge.

**Example:**

Defining all available options.

```python
# Database
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'postgres',
        'USER': 'postgres',
        'PASSWORD': 'postgres',
        'HOST': '127.0.0.1',
        'PORT': '5432'
    }
}

# RDTWT SETTINGS
RDTWT_POSTGRESQL_IMAGE = 'postgres:14.1'
TEST_RUNNER = 'rdtwt.runner.PostgresDiscoverRunner'
RDTWT_POSTGRESQL_USER = 'postgres'
RDTWT_POSTGRESQL_PASSWORD = 'postgres'
RDTWT_POSTGRESQL_NAME = 'postgres'
```
