Skip to content

phil-lopreiato/google-cloud-datastore-stub

Repository files navigation

An In-Memory Stub for Google Cloud Datastore

PyPI version

This project is a pure python implementation of the Google Cloud Datastore RPC Spec. This allows projects using the python-ndb lirary to write unit tests without needing to depend on/manage the full datastore emulator. It is intended as a replacement for the legacy App Engine runtime's local datastore testbed.

Installing

InMemoryCloudDatatoreStub can be installed from PyPi:

$ pip install InMemoryCloudDatastoreStub

Using

The stub can be inserted into your unit tests as a pytest fixture using monkeypatch:

from unittest.mock import MagicMock

import pytest
from google.cloud.ndb import _datastore_api
from InMemoryCloudDatastoreStub.datastore_stub import LocalDatastoreStub

@pytest.fixture()
def ndb_stub(monkeypatch):
    stub = LocalDatastoreStub()
    monkeypatch.setattr(_datastore_api, "stub", MagicMock(return_value=stub))
    return stub

Contributing

Unit tests, typechecks, and lints can all be run with tox:

# Run everything
$ tox

# Run unit tests
$ tox -e py

# Run lint check
$ tox -e lint

# Run type check
$ tox -e typecheck

About

An Google Cloud Datastore in-memory stub for use in unit tests

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages