python-mock-firestore
python-mock-firestore copied to clipboard
firestore transformations are not supported
Issue
firestore
comes with some atomic "transformations" that are used to manipulate data without retrieving the document first, checking the value, then setting it again. These transformations are listed in their documentation: https://googleapis.dev/python/firestore/latest/transforms.html
However, mockfirestore
does not support this functionality.
Reproduction Steps
mock_database.collection('user').document('some-random-id').add({'likes': 0})
mock_database.collection('user').document('some-random-id').update({'likes': firestore.Increment(1)})
assert (
mock_database.collection('user').document('some-random-id').get().to_dict() ==
{'likes': 1}
)
Instead, I get something like:
{'likes': <google.cloud.firestore_v1.transforms.Increment object at 0x106ee5208>}
Hi @domanchi. I followed your implementation and added the firestore ArrayUnion transformation, but finally I ended up adding custom transformation classes to the mock library because I think it is better to be decoupled from the firestore python library. The pull request is here #38