Google Cloud Firestore

From XennisWiki
(Redirected from Google-cloud-firestore)
Jump to: navigation, search

Cloud Firestore is a NoSQL document database of the Google Cloud Platform.

Python SDK

Installation

pip install google-cloud-firestore

Example usage

from google.cloud import firestore

db = firestore.Client()
doc_ref = db.collection('photos').document('mycar')
doc_ref.set({
    'id': image_id,
    'uri': image_uri,
})

Unit test

from unittest import mock

mock_document = mock.MagicMock()
mock_document.set = mock.MagicMock()
mock_collection = mock.MagicMock()
mock_collection.document.return_value = mock_document
mock_firestore_client = mock.MagicMock()
mock_firestore_client.collection.return_value = mock_collection

main.store(mock_firestore_client, 'document', {'some key': 'some value'})
# Check the correct collection was chosen
mock_firestore_client.collection.assert_called_once_with('photos')
# Check the correct document was chosen
mock_collection.document.assert_called_once_with('document')
# Check set method is called with the correct data
mock_document.set.assert_called_once_with({'some key': 'some value'})

See also

External links