diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 41a7cd6..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: actions/setup-python@v2 + uses: MatteoH2O1999/setup-python@v0.1.1 with: python-version: ${{ matrix.python-version }} - name: Install dependencies 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) diff --git a/tests/test_collection_reference.py b/tests/test_collection_reference.py index 7f1924a..e4dcc30 100644 --- a/tests/test_collection_reference.py +++ b/tests/test_collection_reference.py @@ -193,6 +193,19 @@ 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': { + 'otherDocRef': {'ref': fs.document('bar/first')}, + }} + + 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()) + def test_collection_orderBy(self): fs = MockFirestore() fs._data = {'foo': {