From 1c96b8fe8e281fffb3104df22ff67193a6e1f010 Mon Sep 17 00:00:00 2001 From: Timothy Long <30597851+tlong123@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:12:38 +0000 Subject: [PATCH 1/5] try to add reference hashes and equality again --- mockfirestore/document.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mockfirestore/document.py b/mockfirestore/document.py index 24aa433..2fc4c92 100644 --- a/mockfirestore/document.py +++ b/mockfirestore/document.py @@ -77,6 +77,17 @@ def set(self, data: Dict, merge=False): self.set(data) else: set_by_path(self._data, self._path, deepcopy(data)) + + def __hash__(self): + return hash(tuple(self._path)) + + def __eq__(self, other): + if not isinstance(other, self.__class__): + return False + + return self._path == other._path + + def update(self, data: Dict[str, Any]): document = get_by_path(self._data, self._path) From a523e5b664a1f225a8a90eb7ed9ad5421cc62ad8 Mon Sep 17 00:00:00 2001 From: Timothy Long <30597851+tlong123@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:21:47 +0000 Subject: [PATCH 2/5] use alternative action to build python the workflow currently fails due to a lack of python 3.6 on ubuntu-latest. This should allow the action to fall back to building the python version if it's missing --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 41a7cd6..078554b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: MatteoH2O1999/setup-python@v1 with: python-version: ${{ matrix.python-version }} - name: Install dependencies From 8dc50a654360d158af8834676abdb048b08bd819 Mon Sep 17 00:00:00 2001 From: Timothy Long <30597851+tlong123@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:22:52 +0000 Subject: [PATCH 3/5] use valid action version --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 078554b..38eecac 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} - uses: MatteoH2O1999/setup-python@v1 + uses: MatteoH2O1999/setup-python@v0.1.1 with: python-version: ${{ matrix.python-version }} - name: Install dependencies From 59f9f28a23782bb7a1b485623666269ed8c5e5d2 Mon Sep 17 00:00:00 2001 From: Tim Long Date: Mon, 6 Mar 2023 14:34:09 +0000 Subject: [PATCH 4/5] add test to query by reference --- tests/test_collection_reference.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_collection_reference.py b/tests/test_collection_reference.py index 7f1924a..e9c6f0b 100644 --- a/tests/test_collection_reference.py +++ b/tests/test_collection_reference.py @@ -193,6 +193,17 @@ def test_collection_whereArrayContainsAny(self): self.assertEqual({'field': ['val4']}, contains_any_docs[0].to_dict()) self.assertEqual({'field': ['val3', 'val2', 'val1']}, contains_any_docs[1].to_dict()) + def test_collection_whereByReference(self): + fs = MockFirestore() + fs._data = {'foo': { + 'first': {'ref': fs.document('bar/first')}, + 'second': {'ref': fs.document('bar/second')} + }} + + docs = list(fs.collection('foo').where('ref', '==', fs.document('bar/first')).stream()) + self.assertEqual(len(docs), 1) + self.assertEqual({'ref': fs.document('bar/first')}, docs[0].to_dict()) + def test_collection_orderBy(self): fs = MockFirestore() fs._data = {'foo': { From d569ae7a9f2136877feaa9f320e2dde77059ce5a Mon Sep 17 00:00:00 2001 From: Tim Long Date: Mon, 6 Mar 2023 14:52:08 +0000 Subject: [PATCH 5/5] add test for doc ref querying --- tests/test_collection_reference.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/test_collection_reference.py b/tests/test_collection_reference.py index e9c6f0b..e4dcc30 100644 --- a/tests/test_collection_reference.py +++ b/tests/test_collection_reference.py @@ -195,12 +195,14 @@ def test_collection_whereArrayContainsAny(self): def test_collection_whereByReference(self): fs = MockFirestore() - fs._data = {'foo': { - 'first': {'ref': fs.document('bar/first')}, - 'second': {'ref': fs.document('bar/second')} + fs._data = { + 'foo': { + 'otherDocRef': {'ref': fs.document('bar/first')}, }} - docs = list(fs.collection('foo').where('ref', '==', fs.document('bar/first')).stream()) + doc_ref = fs.collection('bar').document('first') + + docs = list(fs.collection('foo').where('ref', '==', doc_ref).stream()) self.assertEqual(len(docs), 1) self.assertEqual({'ref': fs.document('bar/first')}, docs[0].to_dict())