No project description provided
Project description
Yellowbox
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file yellowbox-0.0.2a2.tar.gz
.
File metadata
- Download URL: yellowbox-0.0.2a2.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.8.3 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78cd16b4a4e8d1b096b3f4cbc843bad350d7e3a318f31df4cb38735544151dca |
|
MD5 | 2a573175853ce85bfb07e0662cdc79af |
|
BLAKE2b-256 | f6cff6da2f6f3238d488fd5fe02430b847caec926dfa60b5f5d6f652ebc9d638 |
File details
Details for the file yellowbox-0.0.2a2-py3-none-any.whl
.
File metadata
- Download URL: yellowbox-0.0.2a2-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.8.3 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 765389ca6ff4675a1bbdccaf714b69fa34b2fc9b4d03f8132e607e3e54df7155 |
|
MD5 | ebd2c7a46b905a1584b832adb7c9f1a5 |
|
BLAKE2b-256 | da4c83fd4d800ea6fa9f277ad6945c88ed59b347339b3b483bb28417e01631e7 |