Floci Cloud Emulators (GCP, OCI, AWS, Azure)#
Integration with Floci cloud service emulators for Amazon Web Services
(floci/floci), Microsoft Azure (floci/floci-az), Google Cloud Platform (floci/floci-gcp), and Oracle Cloud
Infrastructure (floci/floci-oci). Each image serves every emulated service of its cloud on one gateway port:
Cloud |
Fixture |
Default image |
Container port |
Health path |
|---|---|---|---|---|
AWS |
|
|
|
|
Azure |
|
|
|
|
GCP |
|
|
|
|
OCI |
|
|
|
|
The fixtures are clientless: readiness probes and the bucket helpers use the standard library, so
google-cloud-storage, oci, boto3, and azure-storage-blob are not required.
Installation#
pip install pytest-databases
Google Cloud Platform (floci_gcp_service)#
Emulates Cloud Storage, Pub/Sub, Firestore, Bigtable, Cloud KMS, Secret Manager, and more. By default,
floci_gcp_compat_proxy (FLOCI_GCP_COMPAT_PROXY, default True) places a stdlib loopback compatibility proxy
in front of Floci GCP that injects missing ETag and RFC-2822 Last-Modified headers and
<ListBucketResult><Contents> XML fields, translates XML PUT with x-goog-copy-source into JSON copyTo
responses (<CopyObjectResult>), and serves XML HEAD requests via upstream GET with accurate
Content-Length and an empty body so obstore (GCSStore), gcsfs, and google-cloud-storage work out of
the box. Set FLOCI_GCP_COMPAT_PROXY=0 to target the raw container port directly:
from pytest_databases.docker.floci import FlociGCPService
pytest_plugins = ["pytest_databases.docker.floci"]
def test_gcs_bucket(floci_gcp_service: FlociGCPService) -> None:
bucket = floci_gcp_service.ensure_bucket(f"{floci_gcp_service.resource_prefix}uploads")
assert bucket["name"].endswith("uploads")
assert floci_gcp_service.storage_emulator_host == floci_gcp_service.endpoint_url
Oracle Cloud Infrastructure (floci_oci_service)#
Emulates Object Storage, Queue, Vault, Secrets, Streaming, and more. Floci OCI accepts unsigned requests and attributes
them to its local tenancy, so floci_oci_namespace defaults to that tenancy’s namespace floci-local and
floci_oci_compartment_id to its root compartment OCID:
from pytest_databases.docker.floci import FlociOCIService
pytest_plugins = ["pytest_databases.docker.floci"]
def test_oci_bucket(floci_oci_service: FlociOCIService) -> None:
bucket = floci_oci_service.ensure_bucket(f"{floci_oci_service.resource_prefix}exports")
assert bucket["name"].endswith("exports")
Amazon Web Services (floci_aws_service)#
Tokenless AWS emulator (S3, SQS, SNS, DynamoDB, Secrets Manager, KMS, Lambda, and more). Point an SDK at
floci_aws_service.endpoint_url with region, access_key, and secret_key. Use
ensure_bucket() (returns None, raising RuntimeError on
failure) or top-level pytest_databases.create_s3_bucket() (returning bool):
from pytest_databases import create_s3_bucket
from pytest_databases.docker.floci import FlociAWSService
pytest_plugins = ["pytest_databases.docker.floci"]
def test_aws_buckets(floci_aws_service: FlociAWSService) -> None:
floci_aws_service.ensure_bucket(f"{floci_aws_service.resource_prefix}app-uploads")
created = create_s3_bucket(
floci_aws_service.endpoint_url,
f"{floci_aws_service.resource_prefix}secondary",
access_key=floci_aws_service.access_key,
secret_key=floci_aws_service.secret_key,
region=floci_aws_service.region,
)
assert created is True
Microsoft Azure (floci_az_service)#
Azure emulator (Blob Storage, Queue Storage, Service Bus, Key Vault, Cosmos DB, and more). Blob Storage is path-style
at floci_az_service.blob_endpoint (<endpoint_url>/<account_name>); any account name and key are accepted.
Isolation#
With the default xdist_floci_isolation_level (database) all pytest-xdist workers share one container per
cloud; prefix resource names with resource_prefix (pytest-databases-<worker>-) to keep them apart. With
server each worker starts its own container named floci_<cloud>_<worker>.
Available Fixtures#
floci_gcp_image,floci_gcp_project,floci_gcp_compat_proxy(defaultTrue, envFLOCI_GCP_COMPAT_PROXY),floci_gcp_servicefloci_oci_image,floci_oci_namespace,floci_oci_region,floci_oci_compartment_id,floci_oci_servicefloci_aws_image,floci_aws_region,floci_aws_access_key,floci_aws_secret_key,floci_aws_servicefloci_az_image,floci_az_account_name,floci_az_account_key,floci_az_servicefloci_resource_prefixandxdist_floci_isolation_level
Each image fixture reads an environment variable (FLOCI_AWS_IMAGE, FLOCI_AZ_IMAGE, FLOCI_GCP_IMAGE,
FLOCI_OCI_IMAGE), as do the other settings (FLOCI_GCP_PROJECT, FLOCI_OCI_NAMESPACE,
FLOCI_RESOURCE_PREFIX, …).
Service API#
Floci multi-cloud (GCP, OCI, AWS, Azure) emulator container fixtures and stdlib HTTP helpers.
Each Floci image serves one cloud on its own gateway port and health path, listed in FLOCI_CONTAINER_PORTS and
FLOCI_HEALTH_PATHS.
- class pytest_databases.docker.floci.FlociAWSService(container: docker.models.containers.Container, host: str, port: int, endpoint_url: str, resource_prefix: str, region: str, access_key: str, secret_key: str)[source]#
Bases:
FlociServiceConnection metadata and S3 bucket helper for a Floci AWS emulator (S3, SQS, SNS, DynamoDB, Secrets Manager).
- class pytest_databases.docker.floci.FlociAzureService(container: docker.models.containers.Container, host: str, port: int, endpoint_url: str, resource_prefix: str, account_name: str, account_key: str)[source]#
Bases:
FlociServiceConnection metadata for a Floci Azure emulator (Blob Storage, Queue Storage, Service Bus, Key Vault, Cosmos DB).
- class pytest_databases.docker.floci.FlociGCPService(container: docker.models.containers.Container, host: str, port: int, endpoint_url: str, resource_prefix: str, project: str)[source]#
Bases:
FlociServiceConnection metadata and helpers for a Floci GCP emulator (GCS, Pub/Sub, Firestore, Bigtable, KMS, Secret Manager).
- class pytest_databases.docker.floci.FlociOCIService(container: docker.models.containers.Container, host: str, port: int, endpoint_url: str, resource_prefix: str, namespace: str, region: str, compartment_id: str)[source]#
Bases:
FlociServiceConnection metadata and helpers for a Floci OCI emulator (Object Storage, Queue, Vault, Secrets, Streaming).
- class pytest_databases.docker.floci.FlociService(container: docker.models.containers.Container, host: str, port: int, endpoint_url: str, resource_prefix: str)[source]#
Bases:
ServiceContainerBase connection metadata for a Floci cloud emulator container.
- pytest_databases.docker.floci.check_floci_health(host: str, port: int, health_path: str = '/_floci/health', *, timeout: float = 2.0) dict[str, Any] | None[source]#
Probe a Floci health endpoint.
- Parameters:
host – Mapped container host address.
port – Mapped container gateway port.
health_path – Health endpoint path of the image, one of
FLOCI_HEALTH_PATHS.timeout – HTTP request timeout in seconds.
- Returns:
The health JSON object when the endpoint answers HTTP 200 with a JSON object, otherwise
None.
- pytest_databases.docker.floci.ensure_gcs_bucket(host: str, port: int, bucket_name: str, *, project: str = 'pytest-databases', timeout: float = 5.0) dict[str, Any][source]#
Create a Google Cloud Storage bucket on a Floci GCP emulator via stdlib HTTP.
An existing bucket (HTTP 409) is not an error.
- Parameters:
host – Mapped container host address.
port – Mapped container gateway port.
bucket_name – Name of the GCS bucket to create.
project – GCP project ID.
timeout – HTTP request timeout in seconds.
- Returns:
Bucket metadata returned by the emulator, or
{"name", "project"}when the bucket already existed.
- pytest_databases.docker.floci.ensure_oci_bucket(host: str, port: int, namespace: str, bucket_name: str, *, compartment_id: str = 'ocid1.tenancy.oc1..flocilocaltenancy0000000000000000000000000000000000000000', timeout: float = 5.0) dict[str, Any][source]#
Create an Oracle Cloud Infrastructure Object Storage bucket on a Floci OCI emulator via stdlib HTTP.
Floci OCI accepts unsigned requests and attributes them to its local tenancy, whose Object Storage namespace is
DEFAULT_FLOCI_OCI_NAMESPACEand whose root compartment isDEFAULT_FLOCI_OCI_COMPARTMENT_ID. An existing bucket (HTTP 409) is not an error.- Parameters:
host – Mapped container host address.
port – Mapped container gateway port.
namespace – OCI Object Storage namespace.
bucket_name – Name of the OCI bucket to create.
compartment_id – OCI compartment OCID that owns the bucket.
timeout – HTTP request timeout in seconds.
- Returns:
Bucket metadata returned by the emulator, or
{"name", "namespace"}when the bucket already existed.
- pytest_databases.docker.floci.floci_aws_access_key() str[source]#
Provide the test AWS access key ID for the Floci AWS emulator.
- pytest_databases.docker.floci.floci_aws_image() str[source]#
Provide the Floci AWS emulator container image.
- pytest_databases.docker.floci.floci_aws_region() str[source]#
Provide the default AWS region for the Floci AWS emulator.
- pytest_databases.docker.floci.floci_aws_secret_key() str[source]#
Provide the test AWS secret access key for the Floci AWS emulator.
- pytest_databases.docker.floci.floci_aws_service(container_service: ContainerService, floci_aws_image: str, floci_aws_region: str, floci_aws_access_key: str, floci_aws_secret_key: str, floci_resource_prefix: str, xdist_floci_isolation_level: XdistIsolationLevel) Generator[FlociAWSService, None, None][source]#
Start and yield a ready Floci AWS emulator service container.
- Yields:
A configured FlociAWSService instance.
- pytest_databases.docker.floci.floci_az_account_key() str[source]#
Provide the default Azure storage account key for the Floci Azure emulator.
- pytest_databases.docker.floci.floci_az_account_name() str[source]#
Provide the default Azure storage account name for the Floci Azure emulator.
- pytest_databases.docker.floci.floci_az_image() str[source]#
Provide the Floci Azure emulator container image.
- pytest_databases.docker.floci.floci_az_service(container_service: ContainerService, floci_az_image: str, floci_az_account_name: str, floci_az_account_key: str, floci_resource_prefix: str, xdist_floci_isolation_level: XdistIsolationLevel) Generator[FlociAzureService, None, None][source]#
Start and yield a ready Floci Azure emulator service container.
- Yields:
A configured FlociAzureService instance.
- pytest_databases.docker.floci.floci_gcp_compat_proxy() bool[source]#
Return whether
floci_gcp_servicestarts the GCS compatibility proxy.
- pytest_databases.docker.floci.floci_gcp_image() str[source]#
Provide the Floci GCP emulator container image.
- pytest_databases.docker.floci.floci_gcp_project() str[source]#
Provide a worker-scoped GCP project ID for Floci GCP tests.
- pytest_databases.docker.floci.floci_gcp_service(container_service: ContainerService, floci_gcp_image: str, floci_gcp_project: str, floci_resource_prefix: str, xdist_floci_isolation_level: XdistIsolationLevel, floci_gcp_compat_proxy: bool) Generator[FlociGCPService, None, None][source]#
Start and yield a ready Floci GCP emulator service container.
- Yields:
A configured FlociGCPService instance.
- pytest_databases.docker.floci.floci_oci_compartment_id() str[source]#
Provide the compartment OCID for Floci OCI resources (the local tenancy root compartment).
- pytest_databases.docker.floci.floci_oci_image() str[source]#
Provide the Floci OCI emulator container image.
- pytest_databases.docker.floci.floci_oci_namespace() str[source]#
Provide the OCI Object Storage namespace of the Floci OCI local tenancy.
- pytest_databases.docker.floci.floci_oci_region() str[source]#
Provide the default OCI region for the Floci OCI emulator.
- pytest_databases.docker.floci.floci_oci_service(container_service: ContainerService, floci_oci_image: str, floci_oci_namespace: str, floci_oci_region: str, floci_oci_compartment_id: str, floci_resource_prefix: str, xdist_floci_isolation_level: XdistIsolationLevel) Generator[FlociOCIService, None, None][source]#
Start and yield a ready Floci OCI emulator service container.
- Yields:
A configured FlociOCIService instance.
- pytest_databases.docker.floci.floci_resource_prefix() str[source]#
Provide a worker-scoped resource name prefix for Floci emulators.
- pytest_databases.docker.floci.provide_floci_container(container_service: ContainerService, *, image: str, name: str, container_port: int, health_path: str, isolation_level: XdistIsolationLevel = 'database') Generator[ServiceContainer, None, None][source]#
Start and yield a ready Floci emulator container.
- Parameters:
container_service – Container runtime service.
image – Floci image to run.
name – Base container name;
_<worker number>is appended under xdist withserverisolation.container_port – Gateway port inside the container, one of
FLOCI_CONTAINER_PORTS.health_path – Health endpoint path, one of
FLOCI_HEALTH_PATHS.isolation_level – pytest-xdist isolation level.
- Yields:
A ready ServiceContainer instance.
- pytest_databases.docker.floci.provide_floci_gcp_service(container_service: ContainerService, *, image: str = 'floci/floci-gcp:0.12.0', project: str = 'pytest-databases', resource_prefix: str = 'pytest-databases-', isolation_level: XdistIsolationLevel = 'database', compat_proxy: bool = True) Generator[FlociGCPService, None, None][source]#
Start Floci GCP and optionally front it with the GCS XML/JSON compatibility proxy.
- Yields:
A configured FlociGCPService instance.