Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions mockfirestore/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_collection_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down