Mocker library of Google Cloud Storage with local filesystem mounting.
Project description
cloud-storage-mocker
Mocker library of Google Cloud Storage with local filesystem mounting.
Getting started
This library provides patch context manager, which replaces following classes on the
google-cloud-storage package:
ClientBucketBlob
patch takes a list of Mount objects, which represents a mapping between a bucket
name and a local storage.
Each mount has Boolean configs readable and writable to control read/write access
to the mounted bucket.
A canonical way to use this library is writing unit tests that are working with Google Cloud Storage:
import tempfile
import google.cloud.storage
from cloud_storage_mocker import patch as gcs_patch, Mount
# A pytest test case.
def test_something() -> None:
# Creates a temporary directory
# And mounts it to the Cloud Storage bucket "my_bucket"
with (
tempfile.TemporaryDirectory() as readable_dir,
tempfile.TemporaryDirectory() as writable_dir,
gcs_patch([
Mount("readable_bucket", readable_dir, readable=True),
Mount("writable_bucket", writable_dir, writable=True),
]),
):
# Reads a blob.
with open(readable_dir + "/test.txt", "w") as fp:
fp.write("Hello.")
blob = google.cloud.storage.Client().bucket("readable_bucket").blob("test.txt")
assert readable_blob.download_as_text() == "Hello."
# Writes a blob.
blob = google.cloud.storage.Client().bucket("writable_bucket").blob("test.txt")
blob.upload_from_string("World.")
with open(writable_dir + "/test.txt") as fp:
assert fp.read() == "World."
Patched methods
Methods below has a specialized behavior to mount the local filesystem.
Other methods are mapped to MagicMock.
Client()Client.bucket()Bucket.blob()Blob.download_as_text()Blob.upload_from_string()
Caution
This library is provided for writing unit tests that work with the Google Cloud Storage client library. DO NOT use this library on any code on the production.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cloud_storage_mocker-0.0.1a4.tar.gz.
File metadata
- Download URL: cloud_storage_mocker-0.0.1a4.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
552b3f62ff01fa6592376edb71a107ad34c41ba24adfe6cccc36ed4b96047964
|
|
| MD5 |
388a2585ea0d318075049b15c866c328
|
|
| BLAKE2b-256 |
103f96d49d8d46c4f98afcabe35d59b8bac283f6b8ffc8e6f74c40de9c943300
|
File details
Details for the file cloud_storage_mocker-0.0.1a4-py3-none-any.whl.
File metadata
- Download URL: cloud_storage_mocker-0.0.1a4-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df40f6491a0e309d645e9176db5ec1bf25a1ed9e06a100ba44afed3b51bb3f47
|
|
| MD5 |
c0b3144639a9ade223147104143e7ae7
|
|
| BLAKE2b-256 |
12e3c5f976b7fc17286110212fabb01f5dfd6c142531dbb0130f19aed798b4aa
|