From d9eaede89b7dd238f97402d51580b2b19361d249 Mon Sep 17 00:00:00 2001 From: Kelly Johnson Date: Wed, 3 Sep 2025 14:29:58 -0700 Subject: [PATCH] Actual firestore behavior to return none not {} --- mockfirestore/document.py | 2 ++ tests/test_document_reference.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mockfirestore/document.py b/mockfirestore/document.py index 24aa433..808959f 100644 --- a/mockfirestore/document.py +++ b/mockfirestore/document.py @@ -23,6 +23,8 @@ def exists(self) -> bool: return self._doc != {} def to_dict(self) -> Document: + if not self.exists: + return None return self._doc @property diff --git a/tests/test_document_reference.py b/tests/test_document_reference.py index c582b36..d3ff43c 100644 --- a/tests/test_document_reference.py +++ b/tests/test_document_reference.py @@ -52,7 +52,7 @@ def test_document_get_documentDoesNotExist(self): fs = MockFirestore() fs._data = {'foo': {}} doc = fs.collection('foo').document('bar').get().to_dict() - self.assertEqual({}, doc) + self.assertIsNone(doc) def test_get_nestedDocument(self): fs = MockFirestore()