firestore-mock


Namefirestore-mock JSON
Version 0.1.5 PyPI version JSON
download
home_pagehttps://github.com/pckmsolutions/firestore-mock
SummaryIn-memory implementation of Google Cloud Firestore for use in tests with support for asyncio
upload_time2024-02-26 21:17:48
maintainer
docs_urlNone
authorPeter Metcalf
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Python Mock Firestore

An in-memory implementation of the [Python client library](https://github.com/googleapis/python-firestore) 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.6+ is required for it to work.

## Usage

```python
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:
```python
mock_db = MockFirestore()
mock_db.reset()
```

## Supported operations

```python
mock_db = MockFirestore()

# Collections
mock_db.collections()
mock_db.collection('users')
mock_db.collection('users').get()
mock_db.collection('users').list_documents()
mock_db.collection('users').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').update_time
mock_db.collection('users').document('alovelace').read_time
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').update({'favourite.color': 'red'})
mock_db.collection('users').document('alovelace').update({'associates': ['Charles Babbage', 'Michael Faraday']})
mock_db.collection('users').document('alovelace').collection('friends')
mock_db.collection('users').document('alovelace').delete()
mock_db.collection('users').document(document_id: 'alovelace').delete()
mock_db.collection('users').add({'first': 'Ada', 'last': 'Lovelace'}, 'alovelace')
mock_db.get_all([mock_db.collection('users').document('alovelace')])
mock_db.document('users/alovelace')
mock_db.document('users/alovelace').update({'born': 1815})
mock_db.collection('users/alovelace/friends')

# Querying
mock_db.collection('users').order_by('born').get()
mock_db.collection('users').order_by('born', direction='DESCENDING').get()
mock_db.collection('users').limit(5).get()
mock_db.collection('users').where('born', '==', 1815).get()
mock_db.collection('users').where('born', '!=', 1815).get()
mock_db.collection('users').where('born', '<', 1815).get()
mock_db.collection('users').where('born', '>', 1815).get()
mock_db.collection('users').where('born', '<=', 1815).get()
mock_db.collection('users').where('born', '>=', 1815).get()
mock_db.collection('users').where('born', 'in', [1815, 1900]).stream()
mock_db.collection('users').where('born', 'in', [1815, 1900]).stream()
mock_db.collection('users').where('associates', 'array_contains', 'Charles Babbage').stream()
mock_db.collection('users').where('associates', 'array_contains_any', ['Charles Babbage', 'Michael Faraday']).stream()

# Transforms
mock_db.collection('users').document('alovelace').update({'likes': firestore.Increment(1)})
mock_db.collection('users').document('alovelace').update({'associates': firestore.ArrayUnion(['Andrew Cross', 'Charles Wheatstone'])})
mock_db.collection('users').document('alovelace').update({firestore.DELETE_FIELD: "born"})
mock_db.collection('users').document('alovelace').update({'associates': firestore.ArrayRemove(['Andrew Cross'])})

# Cursors
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()
mock_db.collection('users').start_after(mock_db.collection('users').document('alovelace')).stream()

# Transactions
transaction = mock_db.transaction()
transaction.id
transaction.in_progress
transaction.get(mock_db.collection('users').where('born', '==', 1815))
transaction.get(mock_db.collection('users').document('alovelace'))
transaction.get_all([mock_db.collection('users').document('alovelace')])
transaction.set(mock_db.collection('users').document('alovelace'), {'born': 1815})
transaction.update(mock_db.collection('users').document('alovelace'), {'born': 1815})
transaction.delete(mock_db.collection('users').document('alovelace'))
transaction.commit()
```

## Running the tests
* Create and activate a virtualenv with a Python version of at least 3.6
* Install dependencies with `pip install -r requirements-dev-minimal.txt`
* Run tests with `python -m unittest discover tests -t /`

## Contributors

* [Matt Dowds](https://github.com/mdowds)
* [Chris Tippett](https://github.com/christippett)
* [Anton Melnikov](https://github.com/notnami)
* [Ben Riggleman](https://github.com/briggleman)
* [Steve Atwell](https://github.com/satwell)
* [ahti123](https://github.com/ahti123)
* [Billcountry Mwaniki](https://github.com/Billcountry)
* [Lucas Moura](https://github.com/lsantosdemoura)
* [Kamil Romaszko](https://github.com/kromash)
* [Anna Melnikov](https://github.com/notnami)
* [Carl Chipperfield](https://github.com/carl-chipperfield)
* [Aaron Loo](https://github.com/domanchi)
* [Kristof Krenn](https://github.com/KrennKristof)
* [Ben Phillips](https://github.com/tavva)
* [Rene Delgado](https://github.com/RDelg)
* [klanderson](https://github.com/klanderson)
* [William Li](https://github.com/wli)
* [Ugo Marchand](https://github.com/UgoM)
* [Bryce Thornton](https://github.com/brycethornton)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pckmsolutions/firestore-mock",
    "name": "firestore-mock",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Peter Metcalf",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/13/08/100520fd981db6cf0088e532e5282b970f765d3ee0bf96ff6d602d9c5f24/firestore-mock-0.1.5.tar.gz",
    "platform": null,
    "description": "# Python Mock Firestore\n\nAn in-memory implementation of the [Python client library](https://github.com/googleapis/python-firestore) 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.\n\nTo install:\n\n`pip install mock-firestore`\n\nPython 3.6+ is required for it to work.\n\n## Usage\n\n```python\ndb = firestore.Client()\nmock_db = MockFirestore()\n\n# Can be used in the same way as a firestore.Client() object would be, e.g.:\ndb.collection('users').get()\nmock_db.collection('users').get()\n```\n\nTo reset the store to an empty state, use the `reset()` method:\n```python\nmock_db = MockFirestore()\nmock_db.reset()\n```\n\n## Supported operations\n\n```python\nmock_db = MockFirestore()\n\n# Collections\nmock_db.collections()\nmock_db.collection('users')\nmock_db.collection('users').get()\nmock_db.collection('users').list_documents()\nmock_db.collection('users').stream()\n\n# Documents\nmock_db.collection('users').document()\nmock_db.collection('users').document('alovelace')\nmock_db.collection('users').document('alovelace').id\nmock_db.collection('users').document('alovelace').parent\nmock_db.collection('users').document('alovelace').update_time\nmock_db.collection('users').document('alovelace').read_time\nmock_db.collection('users').document('alovelace').get()\nmock_db.collection('users').document('alovelace').get().exists\nmock_db.collection('users').document('alovelace').get().to_dict()\nmock_db.collection('users').document('alovelace').set({\n    'first': 'Ada',\n    'last': 'Lovelace'\n})\nmock_db.collection('users').document('alovelace').set({'first': 'Augusta Ada'}, merge=True)\nmock_db.collection('users').document('alovelace').update({'born': 1815})\nmock_db.collection('users').document('alovelace').update({'favourite.color': 'red'})\nmock_db.collection('users').document('alovelace').update({'associates': ['Charles Babbage', 'Michael Faraday']})\nmock_db.collection('users').document('alovelace').collection('friends')\nmock_db.collection('users').document('alovelace').delete()\nmock_db.collection('users').document(document_id: 'alovelace').delete()\nmock_db.collection('users').add({'first': 'Ada', 'last': 'Lovelace'}, 'alovelace')\nmock_db.get_all([mock_db.collection('users').document('alovelace')])\nmock_db.document('users/alovelace')\nmock_db.document('users/alovelace').update({'born': 1815})\nmock_db.collection('users/alovelace/friends')\n\n# Querying\nmock_db.collection('users').order_by('born').get()\nmock_db.collection('users').order_by('born', direction='DESCENDING').get()\nmock_db.collection('users').limit(5).get()\nmock_db.collection('users').where('born', '==', 1815).get()\nmock_db.collection('users').where('born', '!=', 1815).get()\nmock_db.collection('users').where('born', '<', 1815).get()\nmock_db.collection('users').where('born', '>', 1815).get()\nmock_db.collection('users').where('born', '<=', 1815).get()\nmock_db.collection('users').where('born', '>=', 1815).get()\nmock_db.collection('users').where('born', 'in', [1815, 1900]).stream()\nmock_db.collection('users').where('born', 'in', [1815, 1900]).stream()\nmock_db.collection('users').where('associates', 'array_contains', 'Charles Babbage').stream()\nmock_db.collection('users').where('associates', 'array_contains_any', ['Charles Babbage', 'Michael Faraday']).stream()\n\n# Transforms\nmock_db.collection('users').document('alovelace').update({'likes': firestore.Increment(1)})\nmock_db.collection('users').document('alovelace').update({'associates': firestore.ArrayUnion(['Andrew Cross', 'Charles Wheatstone'])})\nmock_db.collection('users').document('alovelace').update({firestore.DELETE_FIELD: \"born\"})\nmock_db.collection('users').document('alovelace').update({'associates': firestore.ArrayRemove(['Andrew Cross'])})\n\n# Cursors\nmock_db.collection('users').start_after({'id': 'alovelace'}).stream()\nmock_db.collection('users').end_before({'id': 'alovelace'}).stream()\nmock_db.collection('users').end_at({'id': 'alovelace'}).stream()\nmock_db.collection('users').start_after(mock_db.collection('users').document('alovelace')).stream()\n\n# Transactions\ntransaction = mock_db.transaction()\ntransaction.id\ntransaction.in_progress\ntransaction.get(mock_db.collection('users').where('born', '==', 1815))\ntransaction.get(mock_db.collection('users').document('alovelace'))\ntransaction.get_all([mock_db.collection('users').document('alovelace')])\ntransaction.set(mock_db.collection('users').document('alovelace'), {'born': 1815})\ntransaction.update(mock_db.collection('users').document('alovelace'), {'born': 1815})\ntransaction.delete(mock_db.collection('users').document('alovelace'))\ntransaction.commit()\n```\n\n## Running the tests\n* Create and activate a virtualenv with a Python version of at least 3.6\n* Install dependencies with `pip install -r requirements-dev-minimal.txt`\n* Run tests with `python -m unittest discover tests -t /`\n\n## Contributors\n\n* [Matt Dowds](https://github.com/mdowds)\n* [Chris Tippett](https://github.com/christippett)\n* [Anton Melnikov](https://github.com/notnami)\n* [Ben Riggleman](https://github.com/briggleman)\n* [Steve Atwell](https://github.com/satwell)\n* [ahti123](https://github.com/ahti123)\n* [Billcountry Mwaniki](https://github.com/Billcountry)\n* [Lucas Moura](https://github.com/lsantosdemoura)\n* [Kamil Romaszko](https://github.com/kromash)\n* [Anna Melnikov](https://github.com/notnami)\n* [Carl Chipperfield](https://github.com/carl-chipperfield)\n* [Aaron Loo](https://github.com/domanchi)\n* [Kristof Krenn](https://github.com/KrennKristof)\n* [Ben Phillips](https://github.com/tavva)\n* [Rene Delgado](https://github.com/RDelg)\n* [klanderson](https://github.com/klanderson)\n* [William Li](https://github.com/wli)\n* [Ugo Marchand](https://github.com/UgoM)\n* [Bryce Thornton](https://github.com/brycethornton)\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "In-memory implementation of Google Cloud Firestore for use in tests with support for asyncio",
    "version": "0.1.5",
    "project_urls": {
        "Homepage": "https://github.com/pckmsolutions/firestore-mock"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bab01bc7a557c891d6551966e79484892a94e5325a75730d798ef480a3647d17",
                "md5": "453f1b38cbb447c38a49d7d71f0fdea4",
                "sha256": "c617c74d8eb0e3a344f3a052e61669d5fab9705ac6f022b9d0238070a974287c"
            },
            "downloads": -1,
            "filename": "firestore_mock-0.1.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "453f1b38cbb447c38a49d7d71f0fdea4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 19394,
            "upload_time": "2024-02-26T21:17:47",
            "upload_time_iso_8601": "2024-02-26T21:17:47.046832Z",
            "url": "https://files.pythonhosted.org/packages/ba/b0/1bc7a557c891d6551966e79484892a94e5325a75730d798ef480a3647d17/firestore_mock-0.1.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1308100520fd981db6cf0088e532e5282b970f765d3ee0bf96ff6d602d9c5f24",
                "md5": "9d15081aa708eaa12af4666af54c2bd1",
                "sha256": "cc9cb1b4bda1e9c8ed0cd71ddf762c99e1f454017b25e2650c9cac66177bb17f"
            },
            "downloads": -1,
            "filename": "firestore-mock-0.1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "9d15081aa708eaa12af4666af54c2bd1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 14220,
            "upload_time": "2024-02-26T21:17:48",
            "upload_time_iso_8601": "2024-02-26T21:17:48.506192Z",
            "url": "https://files.pythonhosted.org/packages/13/08/100520fd981db6cf0088e532e5282b970f765d3ee0bf96ff6d602d9c5f24/firestore-mock-0.1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-26 21:17:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pckmsolutions",
    "github_project": "firestore-mock",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "firestore-mock"
}
        
Elapsed time: 0.65406s