Skip to main content

Goblet GCP Client

PyPI PyPI - Python Version

Goblet GCP Client is a util library with support for creating GCP resource clients, GCP integration tests, and other related utils.

Getting started

To install run:

pip install goblet-gcp-client

Using a Client

from goblet_gcp_client import Client

cloudfunction_client = Client(
    "cloudfunctions",
    "v1",
    calls="projects.locations.functions",
    parent_schema="projects/{project_id}/locations/{location_id}",
)

scheduler_client = Client(
    "cloudscheduler",
    "v1",
    calls="projects.locations.jobs",
    parent_schema="projects/{project_id}/locations/{location_id}",
)

# override default parent_key with "name"
cloudfunction_client.execute(
                "get", parent_key="name", parent_schema="projects/{project_id}/locations/{location_id}/functions/{name}"
            )

# pass in body params
sample_body = {}
resp = cloudfunction_client.execute(
                "patch",
                parent_key="name",
                parent_schema="projects/{project_id}/locations/{location_id}/functions/{name}",
                params={"body": sample_body},
            )

# Wait for previous operation to complete
cloudfunction_client.wait_for_operation(resp["name"], calls="operations")

Writing Integration Tests:

Write your test and set env variable G_HTTP_TEST to RECORD

By default responses will be written to the /tests/data folder. You can customize this by setting G_TEST_DATA_DIR env variable.

Setting the G_MOCK_CREDENTIALS environment variable will use AnonymousCredentials.

def TestDeploy(self):
    monkeypatch.setenv("G_HTTP_TEST", "RECORD")
    monkeypatch.setenv("G_TEST_NAME", "TEST_NAME")

    cloudfunction_client = Client(
        "cloudfunctions",
        "v1",
        calls="projects.locations.functions",
        parent_schema="projects/{project_id}/locations/{location_id}",
    )

    cloudfunction_client.execute(
        "get", parent_key="name", parent_schema="projects/{project_id}/locations/{location_id}/functions/{name}"
    )

Running your test will record all responses that your Client makes

Now you can run your tests with G_HTTP_TEST with REPLAY. You can access the responses with get_responses or get_response

from goblet_gcp_client import get_responses, get_response, get_replay_count, reset_replay_count

def TestDeploy(self):

    monkeypatch.setenv("G_HTTP_TEST", "REPLAY")
    monkeypatch.setenv("G_TEST_NAME", "TEST_NAME")

    reset_replay_count()

    cloudfunction_client = Client(
        "cloudfunctions",
        "v1",
        calls="projects.locations.functions",
        parent_schema="projects/{project_id}/locations/{location_id}",
    )
    cloudfunction_client.execute(
        "get", parent_key="name", parent_schema="projects/{project_id}/locations/{location_id}/functions/{name}"
    )

    responses = get_responses("TEST_NAME")
    assert len(responses) == 2
    assert "test_value" in responses[0]["body"]
    assert get_replay_count() == 1

You can assert that your tests are making all required api called by using get_replay_count. If you are running multiple tests you can run reset_replay_count before each test to ensure the counts are accurate.

Point to Emulator

You can point to an emulator by setting the G_EMULATOR_HOST environment variable, or specifying in the Client constructor.

spanner_instances_client = Client(
    resource="spanner",
    version="v1",
    calls="projects.instances"
    emulator_host="localhost:9020",
)

Features

  • GCP resource clients
  • GCP HTTP Test Recording and Replaying

Examples

Client and Testing Examples

Issues

Please file any issues, bugs or feature requests as an issue on our GitHub page.

Want to Contribute

If you would like to contribute to the library (e.g. by improving the documentation, solving a bug or adding a cool new feature) submit a pull request.

Metadata

Release files for goblet-gcp-client 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for goblet-gcp-client 0.1.9
File Size Uploaded Provenance Actions
goblet_gcp_client-0.1.9.tar.gz 11.7 kB Without provenance Details for goblet_gcp_client-0.1.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for goblet-gcp-client 0.1.9
File Interpreter ABI Platform Actions
goblet_gcp_client-0.1.9-py3-none-any.whl Python 3 none any Details for goblet_gcp_client-0.1.9-py3-none-any.whl

Total release size: 23.3 kB

Release files / goblet_gcp_client-0.1.9.tar.gz

Download URL goblet_gcp_client-0.1.9.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4ecff0989392054350ff608f253a0c45f06bc9563f187f1670f13f03ef905ce5
BLAKE2b-256 checksum
How to use checksums
fc23f58a20734ce346a9b8feea9a3e50892ab4e58900d51d5438c1878c137f7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release files / goblet_gcp_client-0.1.9-py3-none-any.whl

Download URL goblet_gcp_client-0.1.9-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f79970089482e2896644bd1492d5aa267721e8c2986806137de86f3b6d04f707
BLAKE2b-256 checksum
How to use checksums
4cf415cb410f6d7a0be8b66c0b226b3fdcc031d76d3f6a0c381a614398b5b190
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Security for goblet-gcp-client 0.1.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page