🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

mock-gcp

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock-gcp

A library that allows to mock out GCP services in unit tests.

0.2.0
Maintainers
1

mock-gcp | Mock GCP Services

Python Version Supported GCS Version Code style: black

A library that allows to mock out GCP services in unit tests.

Intro

List of supported services

Service NameDecoratorDevelopment status
Cloud Storage@mock_storagebasic 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()
    # Firts, need to create a bucket in our virtual Google Cloud project
    client.create_bucket("test-bucket")

    assert create_bucket_if_doesnt_exists("test-bucket") is None

Install

pip install mock-gcp

Not yet working...

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts