Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kwargs to doc ref #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion mockfirestore/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ def __init__(self, data: Store, path: List[str],
def id(self):
return self._path[-1]

def get(self) -> DocumentSnapshot:
@property
def path(self):
return '/'.join(self._path)

def get(self, **kwargs) -> DocumentSnapshot:
return DocumentSnapshot(self, get_by_path(self._data, self._path))

def delete(self):
Expand Down
19 changes: 18 additions & 1 deletion tests/test_document_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,31 @@ def test_get_document_by_path(self):
self.assertEqual({'id': 1}, doc.to_dict())
self.assertEqual('first', doc.id)

def test_get_document_by_path_with_transaction_kwarg(self):
fs = MockFirestore()
fs._data = {'foo': {
'first': {'id': 1}
}}
doc = fs.document('foo/first').get(transaction='tx')
self.assertEqual({'id': 1}, doc.to_dict())
self.assertEqual('first', doc.id)

def test_document_path_property(self):
fs = MockFirestore()
fs._data = {'foo': {
'first': {'id': 1}
}}
doc = fs.document('foo/first')
self.assertEqual('foo/first', doc.path)

def test_set_document_by_path(self):
fs = MockFirestore()
fs._data = {}
doc_content = {'id': 'bar'}
fs.document('foo/doc1/bar/doc2').set(doc_content)
doc = fs.document('foo/doc1/bar/doc2').get().to_dict()
self.assertEqual(doc_content, doc)

def test_document_get_returnsDocument(self):
fs = MockFirestore()
fs._data = {'foo': {
Expand Down
Loading