Skip to main content

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

Project description

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 Name Decorator Development status
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()
    # 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...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mock_gcp-0.2.0.tar.gz (39.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mock_gcp-0.2.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file mock_gcp-0.2.0.tar.gz.

File metadata

  • Download URL: mock_gcp-0.2.0.tar.gz
  • Upload date:
  • Size: 39.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for mock_gcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 52618cd80546bfdbaa2f0c5df033df81cbd3807b02ed45c3d2b4b799c5c21810
MD5 65ec059aa3ed4c32767faed86014565e
BLAKE2b-256 6983ecda43192bebb5d7541af7ae3401e4a44accdff00280d7cbe120f45444fe

See more details on using hashes here.

File details

Details for the file mock_gcp-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mock_gcp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for mock_gcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9c3126b5ba12283302a8dc82d49a7dbbd07faf9d3436dca6b5fdbc443dd32bb8
MD5 bbf33e290cf6b96bff2b9f830fd445d4
BLAKE2b-256 6e5f88229f11a9a92b2ffc22bac19e22df2bce7b16f93a5c01bd3ea235194ad5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page