Skip to main content

No project description provided

Project description

Yellowbox

Test YellowBox Coverage

Yellowbox makes it easy to run docker containers as part of black box tests.

Examples

Say you want to run a blackbox test on a service that depends on a redis server.

from docker import DockerClient
from yellowbox.extras import RedisService

def test_black_box():
    docker_client = DockerClient.from_env()
    with RedisService.run(docker_client) as redis:
        redis_port = redis.client_port()  # this the host port the redis
        ...  # run your black box test here
    # yellowbox will automatically close the service when exiting the scope

def test_black_box_with_initial_data():
    # you can use the service's built-in utility functions to
    # easily interoperate the service
    docker_client = DockerClient.from_env()
    with RedisService.run(docker_client) as redis:
        with redis.client() as client:
            client.set("foo","bar")
        ...

Supported Extras

The currently supported built-in services are:

  • Kafka: from yellowbox.extras import KafkaService
    • currently, the kafka service supports only plaintext protocol, and always binds to the host port 9092
  • Logstash: from yellowbox.extras import LogstashService
  • RabbitMQ: from yellowbox.extras import RabbitMQService
  • Redis: from yellowbox.extras import RedisService

Note: all these extras require additional dependencies as specified in the project's extras.

Networks

Yellowbox also makes it easy to set up temporary docker networks, so that different containers and services can communicate directly.

from docker import DockerClient
from yellowbox import temp_network, connect
from yellowbox.extras import RabbitMQService

def test_network():
    docker_client = DockerClient.from_env()
    with RabbitMQService.run(docker_client) as rabbit, \
        temp_network(docker_client) as network, \
        connect(network, rabbit) as alias:
        # yellow's "connect" function connects between a network and a
        # Container/YellowService, retrieves the container's alias(es) on 
        # the network, and disconnects the two when done
        another_container = docker_client.containers.create("my-image", 
            environment={"RABBITMQ_HOSTNAME": alias[0]}
        )
        with connect(network, another_container):
            another_container.start()
            another_container.wait()

As Pytest Fixtures

Both yellow services and networks can be used fluently with pytest fixures

from docker import DockerClient
from pytest import fixture

from yellowbox.extras import RedisService

@fixture
def docker_client():
    docker_client = DockerClient.from_env()
    yield docker_client
    docker_client.close()

@fixture
def redis_service(docker_client):
    with RedisService.run(docker_client) as service:
        yield service

def black_box(redis_service):
    # run your test with the redis service provided
    ...

since docker container may take some time to set up, it's advisable to set their scope to at least "module"

Extending Yellow

Users can create their own Yellow Service classes by implementing the YellowService abstract class. If the service encapsulates only a single container, the SingleContainerService class already implements the necessary methods.

License

Yellowbox is registered under the MIT public license

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

yellowbox-0.5.0.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

yellowbox-0.5.0-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file yellowbox-0.5.0.tar.gz.

File metadata

  • Download URL: yellowbox-0.5.0.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.7 Linux/5.4.0-1036-azure

File hashes

Hashes for yellowbox-0.5.0.tar.gz
Algorithm Hash digest
SHA256 50d02ef7673a5d7f4b75aab71c64fb1e05b67ff57f47b13e69aee46c2271cd32
MD5 f1f004e40aa76bf9691bbe9e901ff633
BLAKE2b-256 195b32c7c2a1729755fccc5a866fd91c13299319c9605ac26363d91c1d9fbc00

See more details on using hashes here.

File details

Details for the file yellowbox-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: yellowbox-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.7 Linux/5.4.0-1036-azure

File hashes

Hashes for yellowbox-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db9c0cd741098770c4c76ae5099e80566b79c1a890cc22c33a6a93111ecd8e28
MD5 3fc433332d42d1bc10e857898f4db774
BLAKE2b-256 5624ffdf81d83ac5f5d34713bfc0b456c7efba067ad6c31374a6317c21425f41

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