testcompose


Nametestcompose JSON
Version 0.2.1 PyPI version JSON
download
home_page
SummaryProvide an easy way to perform integration testing with docker and python
upload_time2023-09-10 12:27:47
maintainerOlakunle Olaniyi
docs_urlNone
authorOlakunle Olaniyi
requires_python>=3.7,<4.0
licenseMIT
keywords docker testcontainers
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align="center" style="font-size: 3rem; margin: -15px 0">
Testcompose
</h1>



<p align="center" style="margin: 30px 0 10px">
  <img width="350" height="208" src="docs/images/testcompose.png" alt='Testcompose'>
</p>

<p align="center"><strong>Testcompose</strong> <em>- A clean and better way to test your Python containerized applications.</em></p>



![PyPI - Python Version](https://img.shields.io/pypi/pyversions/testcompose)
![PyPI - Implementation](https://img.shields.io/pypi/implementation/testcompose)
![PyPI](https://img.shields.io/pypi/v/testcompose)
![PyPI - Downloads](https://img.shields.io/pypi/dm/testcompose)
[![Tests](https://github.com/rugging24/python-testcompose/workflows/RunningTests/badge.svg)](https://github.com/rugging24/python-testcompose/blob/main/.github/workflows/tests.yaml)


---
**Testcompose** provides an easy way of using docker containers for functional and integration testing. It allows for combination of more than one containers and allows for interactions with these containers from your test code without having to write extra scripts for such interactions. I.e providing a docker compose kind of functionality with the extra benefit of being able to fully control the containers from test codes.

This is inspired by the [testcontainers-python](https://testcontainers-python.readthedocs.io/en/latest/index.html#) project and goes further to add a few additional functionalities to improve software integration testing while allowing the engineer to control every aspect of the test.

---

Install testcompose using pip:

```shell
$ pip install testcompose
```

testcompose requires Python 3.7+.

Using a config file. See the [Quickstart](https://github.com/rugging24/python-testcompose/blob/main/docs/quickstart.md) for other options

```shell
# Testcompose include a cli utility to help create a quickstart config file that should be update to suit the needs of the user.
# Create a config file by running the command

testcompose generate-template --help   # shows the help and exit.

# To generate template config for an app and a db combination, run the command

testcompose generate-template --component db --component app

# The above command ouputs to stdout. To output to a file, include a filepath as below

testcompose generate-template --component db --component app --template-file some-valid-file-location.yaml

```

A sample of the config file is represented below:


```yaml
services:
  - name: database
    image: "postgres:13"
    command: ""
    environment:
      POSTGRES_USER: postgres
      POSTGRES_DB: postgres
      POSTGRES_PASSWORD: password
    exposed_ports:
      - 5432
    log_wait_parameters:
      log_line_regex: "database system is ready to accept connections"
      wait_timeout_ms: 30000
      poll_interval_ms: 2000
  - name: application
    image: "python:3.9"
    command: "/bin/bash -x /run_app.sh"
    environment:
      DB_URL: "${database.postgres_user}:${database.postgres_password}@${database.container_hostname}:5432/${database.postgres_db}"
    volumes:
      - host: "docker-test-files/run_app.sh"
        container: "/run_app.sh"
        mode: "ro"
        source: "filesystem"
      - host: "docker-test-files/app.py"
        container: "/app.py"
        mode: "ro"
        source: "filesystem"
    exposed_ports:
      - "8000"
    log_wait_parameters:
      log_line_regex: ".*Application startup complete.*"
      wait_timeout_ms: 45000
      poll_interval_ms: 2000
    http_wait_parameters:
      http_port: 8000
      response_status_code: 200
      end_point: "/ping"
      startup_delay_time_ms: 30000
      use_https": false
    depends_on:
      - database
```

Verify it as follows:

```python
import json
from typing import Any, Dict
from requests import Response, get
from testcompose.configs.service_config import Config
from testcompose.models.bootstrap.container_service import ContainerServices
from testcompose.models.container.running_container import RunningContainer
from testcompose.run_containers import RunContainers

config_services: ContainerServices = TestConfigParser.parse_config(file_name='some-config.yaml')
running_config: Config = Config(test_services=config_services)

with RunContainers(
        config_services=config_services,
        ranked_services=running_config.ranked_config_services,
) as runner:
    assert runner
    app_container_srv_name = "application"
    app_service: RunningContainer = runner.running_containers[app_container_srv_name]
    app_env_vars: Dict[str, Any] = app_service.config_environment_variables
    mapped_port = app_service.generic_container.get_exposed_port("8000")
    print(app_env_vars)
    app_host = app_service.generic_container.get_container_host_ip()
    assert app_env_vars
    assert mapped_port
    assert app_host
    response: Response = get(url=f"http://{app_host}:{int(mapped_port)}/version")
    assert response
    assert response.status_code == 200
    assert response.text
    assert isinstance(json.loads(response.text), dict)
```


## Documentation

[Quickstart](https://github.com/rugging24/python-testcompose/blob/main/docs/quickstart.md)

[Special-Variables](https://github.com/rugging24/python-testcompose/blob/main/docs/environment_variables.md)

[Full-Doc](https://rugging24.github.io/python-testcompose/)


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "testcompose",
    "maintainer": "Olakunle Olaniyi",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "rugging24@gmail.com",
    "keywords": "docker,testcontainers",
    "author": "Olakunle Olaniyi",
    "author_email": "rugging24@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b8/93/ac24322bd7a1f9018e84c321c733ff127d3b5458818329fb397e73c2dce0/testcompose-0.2.1.tar.gz",
    "platform": null,
    "description": "<h1 align=\"center\" style=\"font-size: 3rem; margin: -15px 0\">\nTestcompose\n</h1>\n\n\n\n<p align=\"center\" style=\"margin: 30px 0 10px\">\n  <img width=\"350\" height=\"208\" src=\"docs/images/testcompose.png\" alt='Testcompose'>\n</p>\n\n<p align=\"center\"><strong>Testcompose</strong> <em>- A clean and better way to test your Python containerized applications.</em></p>\n\n\n\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/testcompose)\n![PyPI - Implementation](https://img.shields.io/pypi/implementation/testcompose)\n![PyPI](https://img.shields.io/pypi/v/testcompose)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/testcompose)\n[![Tests](https://github.com/rugging24/python-testcompose/workflows/RunningTests/badge.svg)](https://github.com/rugging24/python-testcompose/blob/main/.github/workflows/tests.yaml)\n\n\n---\n**Testcompose** provides an easy way of using docker containers for functional and integration testing. It allows for combination of more than one containers and allows for interactions with these containers from your test code without having to write extra scripts for such interactions. I.e providing a docker compose kind of functionality with the extra benefit of being able to fully control the containers from test codes.\n\nThis is inspired by the [testcontainers-python](https://testcontainers-python.readthedocs.io/en/latest/index.html#) project and goes further to add a few additional functionalities to improve software integration testing while allowing the engineer to control every aspect of the test.\n\n---\n\nInstall testcompose using pip:\n\n```shell\n$ pip install testcompose\n```\n\ntestcompose requires Python 3.7+.\n\nUsing a config file. See the [Quickstart](https://github.com/rugging24/python-testcompose/blob/main/docs/quickstart.md) for other options\n\n```shell\n# Testcompose include a cli utility to help create a quickstart config file that should be update to suit the needs of the user.\n# Create a config file by running the command\n\ntestcompose generate-template --help   # shows the help and exit.\n\n# To generate template config for an app and a db combination, run the command\n\ntestcompose generate-template --component db --component app\n\n# The above command ouputs to stdout. To output to a file, include a filepath as below\n\ntestcompose generate-template --component db --component app --template-file some-valid-file-location.yaml\n\n```\n\nA sample of the config file is represented below:\n\n\n```yaml\nservices:\n  - name: database\n    image: \"postgres:13\"\n    command: \"\"\n    environment:\n      POSTGRES_USER: postgres\n      POSTGRES_DB: postgres\n      POSTGRES_PASSWORD: password\n    exposed_ports:\n      - 5432\n    log_wait_parameters:\n      log_line_regex: \"database system is ready to accept connections\"\n      wait_timeout_ms: 30000\n      poll_interval_ms: 2000\n  - name: application\n    image: \"python:3.9\"\n    command: \"/bin/bash -x /run_app.sh\"\n    environment:\n      DB_URL: \"${database.postgres_user}:${database.postgres_password}@${database.container_hostname}:5432/${database.postgres_db}\"\n    volumes:\n      - host: \"docker-test-files/run_app.sh\"\n        container: \"/run_app.sh\"\n        mode: \"ro\"\n        source: \"filesystem\"\n      - host: \"docker-test-files/app.py\"\n        container: \"/app.py\"\n        mode: \"ro\"\n        source: \"filesystem\"\n    exposed_ports:\n      - \"8000\"\n    log_wait_parameters:\n      log_line_regex: \".*Application startup complete.*\"\n      wait_timeout_ms: 45000\n      poll_interval_ms: 2000\n    http_wait_parameters:\n      http_port: 8000\n      response_status_code: 200\n      end_point: \"/ping\"\n      startup_delay_time_ms: 30000\n      use_https\": false\n    depends_on:\n      - database\n```\n\nVerify it as follows:\n\n```python\nimport json\nfrom typing import Any, Dict\nfrom requests import Response, get\nfrom testcompose.configs.service_config import Config\nfrom testcompose.models.bootstrap.container_service import ContainerServices\nfrom testcompose.models.container.running_container import RunningContainer\nfrom testcompose.run_containers import RunContainers\n\nconfig_services: ContainerServices = TestConfigParser.parse_config(file_name='some-config.yaml')\nrunning_config: Config = Config(test_services=config_services)\n\nwith RunContainers(\n        config_services=config_services,\n        ranked_services=running_config.ranked_config_services,\n) as runner:\n    assert runner\n    app_container_srv_name = \"application\"\n    app_service: RunningContainer = runner.running_containers[app_container_srv_name]\n    app_env_vars: Dict[str, Any] = app_service.config_environment_variables\n    mapped_port = app_service.generic_container.get_exposed_port(\"8000\")\n    print(app_env_vars)\n    app_host = app_service.generic_container.get_container_host_ip()\n    assert app_env_vars\n    assert mapped_port\n    assert app_host\n    response: Response = get(url=f\"http://{app_host}:{int(mapped_port)}/version\")\n    assert response\n    assert response.status_code == 200\n    assert response.text\n    assert isinstance(json.loads(response.text), dict)\n```\n\n\n## Documentation\n\n[Quickstart](https://github.com/rugging24/python-testcompose/blob/main/docs/quickstart.md)\n\n[Special-Variables](https://github.com/rugging24/python-testcompose/blob/main/docs/environment_variables.md)\n\n[Full-Doc](https://rugging24.github.io/python-testcompose/)\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Provide an easy way to perform integration testing with docker and python",
    "version": "0.2.1",
    "project_urls": null,
    "split_keywords": [
        "docker",
        "testcontainers"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "76adf21ca6d31246e48c33a9f421577d61ec193ee27fddb8306df3300457163c",
                "md5": "f53fe36e6199b682321cb05ee89e676f",
                "sha256": "9f1973c574bb3d2c308b212c3a47a1a311f45a4a4aa70cb5e38227967beffd36"
            },
            "downloads": -1,
            "filename": "testcompose-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f53fe36e6199b682321cb05ee89e676f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 31265,
            "upload_time": "2023-09-10T12:27:45",
            "upload_time_iso_8601": "2023-09-10T12:27:45.376420Z",
            "url": "https://files.pythonhosted.org/packages/76/ad/f21ca6d31246e48c33a9f421577d61ec193ee27fddb8306df3300457163c/testcompose-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b893ac24322bd7a1f9018e84c321c733ff127d3b5458818329fb397e73c2dce0",
                "md5": "ea7206767681c6317da378f63b22c881",
                "sha256": "d1ab686bce8b3f2e76f24c7e8d0fcd25fc77ae870fc16a470feeb03659f004d2"
            },
            "downloads": -1,
            "filename": "testcompose-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ea7206767681c6317da378f63b22c881",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 22211,
            "upload_time": "2023-09-10T12:27:47",
            "upload_time_iso_8601": "2023-09-10T12:27:47.043463Z",
            "url": "https://files.pythonhosted.org/packages/b8/93/ac24322bd7a1f9018e84c321c733ff127d3b5458818329fb397e73c2dce0/testcompose-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-10 12:27:47",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "testcompose"
}
        
Elapsed time: 7.48696s