Skip to content
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
4 changes: 4 additions & 0 deletions mockfirestore/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def __init__(self, data: Store, path: List[str],
def id(self):
return self._path[-1]

@property
def path(self):
return '/'.join(self._path)

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

Expand Down
10 changes: 9 additions & 1 deletion tests/test_document_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,22 @@ def test_get_document_by_path(self):
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