django-rdtwt


Namedjango-rdtwt JSON
Version 2.0.0 PyPI version JSON
download
home_pagehttps://github.com/wonkybream/django-rdtwt
SummaryRun Django tests with testcontainers.
upload_time2024-01-11 07:53:26
maintainer
docs_urlNone
authorSampo Lavinen
requires_python>=3.8
licenseMIT
keywords django testing testcontainers docker test automation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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 focuses on users who wish to forget setting up a database for tests.
There's no need for 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)

By default, this test runner changes _default_ database host and port dynamically,
because it's quite hard to know database host beforehand 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 the 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 a 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_DATABASES = ["default"]  # Add more if you have multiple databases
RDTWT_POSTGRESQL_USER = 'postgres'
RDTWT_POSTGRESQL_PASSWORD = 'postgres'
RDTWT_POSTGRESQL_NAME = 'postgres'
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/wonkybream/django-rdtwt",
    "name": "django-rdtwt",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "django,testing,testcontainers,docker,test automation",
    "author": "Sampo Lavinen",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/58/b5/86a8bc3a7daeb002bc98d41ab93433c5cae89ab5ede74ec44608dc11f971/django-rdtwt-2.0.0.tar.gz",
    "platform": null,
    "description": "# django-rdtwt\n\n[![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)\n[![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)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![PyPI](https://img.shields.io/pypi/v/django-rdtwt)](https://pypi.org/project/django-rdtwt/)\n\n*(Run Django Tests With Testcontainers)*\n\nThis focuses on users who wish to forget setting up a database for tests.\nThere's no need for manually starting up *Docker compose* or local database with this.\n\n**Note:**\n\nSee: [Altering settings at runtime: Django documentation](https://docs.djangoproject.com/en/3.2/topics/settings/#altering-settings-at-runtime)\n\nBy default, this test runner changes _default_ database host and port dynamically,\nbecause it's quite hard to know database host beforehand in dynamic environments, for example, some CI/CD runners.\n\nStill, this just works and is quite simple, that's why I haven't spent that much time investigating alternative solutions. \n\n## Installation\n\n1. Add rdtwt to your INSTALLED_APPS setting like this\n    ```python\n    INSTALLED_APPS = [\n        ...\n        'rdtwt',\n    ]\n    ```\n\n2. Run tests with rdtwt runner,\n    ```shell\n    python manage.py test --testrunner=rdtwt.runner.PostgresDiscoverRunner\n    ```\n\nThough what I really suggest is to put the following in your test settings.\n\n```python\n# RDTWT SETTINGS\nRDTWT_POSTGRESQL_IMAGE = 'postgres:14.1'\nTEST_RUNNER = 'rdtwt.runner.PostgresDiscoverRunner'\n```\n\nThis makes sure that tests run against the PostgreSQL version defined by you.\nIt also adds up to the test confidence; at least they aren't flaky because of a database version changing without your knowledge.\n\n**Example:**\n\nDefining all available options.\n\n```python\n# Database\nDATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.postgresql',\n        'NAME': 'postgres',\n        'USER': 'postgres',\n        'PASSWORD': 'postgres',\n        'HOST': '127.0.0.1',\n        'PORT': '5432'\n    }\n}\n\n# RDTWT SETTINGS\nRDTWT_POSTGRESQL_IMAGE = 'postgres:14.1'\nTEST_RUNNER = 'rdtwt.runner.PostgresDiscoverRunner'\nRDTWT_DATABASES = [\"default\"]  # Add more if you have multiple databases\nRDTWT_POSTGRESQL_USER = 'postgres'\nRDTWT_POSTGRESQL_PASSWORD = 'postgres'\nRDTWT_POSTGRESQL_NAME = 'postgres'\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Run Django tests with testcontainers.",
    "version": "2.0.0",
    "project_urls": {
        "Homepage": "https://github.com/wonkybream/django-rdtwt"
    },
    "split_keywords": [
        "django",
        "testing",
        "testcontainers",
        "docker",
        "test automation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f7cadda8c57fc91f971f016e24385108d4dd4f4db58245375c1048b350ace5c7",
                "md5": "bd30be4a0c4d5c9015d50d4d99d047a2",
                "sha256": "249f7a60bdf6926aac8a8468776231b91867dee3f94e7dd478e0e26d37b7e9f2"
            },
            "downloads": -1,
            "filename": "django_rdtwt-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bd30be4a0c4d5c9015d50d4d99d047a2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 4281,
            "upload_time": "2024-01-11T07:53:25",
            "upload_time_iso_8601": "2024-01-11T07:53:25.322624Z",
            "url": "https://files.pythonhosted.org/packages/f7/ca/dda8c57fc91f971f016e24385108d4dd4f4db58245375c1048b350ace5c7/django_rdtwt-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "58b586a8bc3a7daeb002bc98d41ab93433c5cae89ab5ede74ec44608dc11f971",
                "md5": "c3007b3337bcc6abebc49e241f699c27",
                "sha256": "aa6a49fbe876fecc657b840705a13d7b475cda13fffe5127ece5031ba09a7854"
            },
            "downloads": -1,
            "filename": "django-rdtwt-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c3007b3337bcc6abebc49e241f699c27",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 4536,
            "upload_time": "2024-01-11T07:53:26",
            "upload_time_iso_8601": "2024-01-11T07:53:26.536080Z",
            "url": "https://files.pythonhosted.org/packages/58/b5/86a8bc3a7daeb002bc98d41ab93433c5cae89ab5ede74ec44608dc11f971/django-rdtwt-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-11 07:53:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "wonkybream",
    "github_project": "django-rdtwt",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "django-rdtwt"
}
        
Elapsed time: 0.18347s