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.

Documentation: https://yellowbox.readthedocs.io/


Examples

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

from yellowbox.clients import docker_client
from yellowbox.extras import RedisService


def test_black_box():
  with docker_client() as docker_client, 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
  with docker_client() as docker_client,
          RedisService.run(docker_client) as redis,
          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 yellowbox.clients import docker_client
from yellowbox import temp_network, connect
from yellowbox.extras import RabbitMQService


def test_network():
  with docker_client() as docker_client,
          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 yellowbox.clients import docker_client
from pytest import fixture

from yellowbox.extras import RedisService


@fixture
def docker_client():
  with docker_client() as ret:
    yield ret


@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.7.1.tar.gz (43.8 kB view details)

Uploaded Source

Built Distribution

yellowbox-0.7.1-py3-none-any.whl (54.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: yellowbox-0.7.1.tar.gz
  • Upload date:
  • Size: 43.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.12 Linux/5.13.0-1017-azure

File hashes

Hashes for yellowbox-0.7.1.tar.gz
Algorithm Hash digest
SHA256 7542534e1184fd62920992cb0155988a85c4631154acaaac8cc3cb07d05c9efd
MD5 4c43e2b326493496a4513af0b31f570a
BLAKE2b-256 68de4750a532fadf02d958eb56bda2bb3f92e80060babcbb1d067bb70f97ccd3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: yellowbox-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 54.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.12 Linux/5.13.0-1017-azure

File hashes

Hashes for yellowbox-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7d176bc7f7a7cc2d3e3014ef4feb31109290df74532e773c50cae5bd782acade
MD5 58f302cc032ff36e68bb60c6da006e96
BLAKE2b-256 05cc92a5b03badaf9a67d641026174c75fd06124f44b079750c311b50e74d337

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