diff --git a/mockfirestore/document.py b/mockfirestore/document.py index 24aa433..298cb47 100644 --- a/mockfirestore/document.py +++ b/mockfirestore/document.py @@ -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)) diff --git a/tests/test_document_reference.py b/tests/test_document_reference.py index c582b36..239e785 100644 --- a/tests/test_document_reference.py +++ b/tests/test_document_reference.py @@ -16,6 +16,14 @@ 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 = {} @@ -23,7 +31,7 @@ def test_set_document_by_path(self): 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': {