Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

In-memory implementation of Google Cloud Firestore for use in tests

Project description

Python Mock Firestore

An in-memory implementation of the Python client library for Google Cloud Firestore, intended for use in tests to replace the real thing. This project is in early stages and is only a partial implementation of the real client library.

To install:

pip install mock-firestore

Python 3.5+ is required for it to work.

Usage

db = firestore.Client()
mock_db = MockFirestore()

# Can be used in the same way as a firestore.Client() object would be, e.g.:
db.collection('users').get()
mock_db.collection('users').get()

To reset the store to an empty state, use the reset() method:

mock_db = MockFirestore()
mock_db.reset()

Supported operations

mock_db = MockFirestore()

# Collections
mock_db.collection('users')
mock_db.collection('users').get()
mock_db.collection('users').list_documents()
mock_db.collection('users').stream()
mock_db.collection('users').start_after({'id': 'alovelace'}).stream()
mock_db.collection('users').end_before({'id': 'alovelace'}).stream()
mock_db.collection('users').end_at({'id': 'alovelace'}).stream()

# Documents
mock_db.collection('users').document()
mock_db.collection('users').document('alovelace')
mock_db.collection('users').document('alovelace').id
mock_db.collection('users').document('alovelace').parent
mock_db.collection('users').document('alovelace').get()
mock_db.collection('users').document('alovelace').get().exists
mock_db.collection('users').document('alovelace').get().to_dict()
mock_db.collection('users').document('alovelace').set({
    'first': 'Ada',
    'last': 'Lovelace'
})
mock_db.collection('users').document('alovelace').set({
    'first': 'Augusta Ada'
}, merge=True)
mock_db.collection('users').document('alovelace').update({
    'born': 1815
})
mock_db.collection('users').document('alovelace').collection('friends')
mock_db.collection('users').document('alovelace').delete()

mock_db.collection('users').add({'first': 'Ada', 'last': 'Lovelace'},
                                'alovelace')

# Querying
mock_db.collection('users').document('alovelace').order_by('born').get()
mock_db.collection('users').document('alovelace').order_by('born', direction='DESCENDING').get()
mock_db.collection('users').document('alovelace').limit(5).get()
mock_db.collection('users').document('alovelace').where('born', '==', 1815).get()
mock_db.collection('users').document('alovelace').where('born', '<', 1815).get()
mock_db.collection('users').document('alovelace').where('born', '>', 1815).get()
mock_db.collection('users').document('alovelace').where('born', '<=', 1815).get()
mock_db.collection('users').document('alovelace').where('born', '>=', 1815).get()

Contributors

Project details


Download files

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

Files for mock-firestore, version 0.5.0
Filename, size File type Python version Upload date Hashes
Filename, size mock-firestore-0.5.0.tar.gz (6.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page