mock-gcp | Mock GCP Services

A library that allows to mock out GCP services in unit tests.
Intro
List of supported services
Cloud Storage | @mock_storage | basic endpoints implemented |
Usage
Let's say you have the following function to test.
from google.cloud import storage
def create_bucket_if_doesnt_exist(bucket_name):
client = storage.Client()
if client.lookup_bucket(bucket_name) is None:
return client.create_bucket(bucket_name)
else:
return None
To test this function with mock-gcp
use the @mock_storage
decorator which will mock out all API calls in the background.
from google.cloud import storage
from mockgcp import mock_storage
@mock_storage
def test_create_bucket_if_doesnt_exist_when_bucket_exists():
client = storage.Client()
client.create_bucket("test-bucket")
assert create_bucket_if_doesnt_exists("test-bucket") is None
Install
pip install mock-gcp
Not yet working...