Skip to content

Commit 90e134d

Browse files
author
Ben Poppy
committed
test: add additional tests for select
1 parent e422000 commit 90e134d

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

tests/test_collection_reference.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,39 @@ def test_collection_orderby_offset(self):
245245

246246
def test_collection_select(self):
247247
fs = MockFirestore()
248-
fs._data = {'foo': {'first': {'id': 1, 'value': 'one'}, 'second': {'id': 2, 'value': 'two'}, 'third': {'id': 3, 'value': 'three'}}}
248+
fs._data = {'foo': {
249+
'first': {'id': 1, 'value': 'one'},
250+
'second': {'id': 2, 'value': 'two'},
251+
'third': {'id': 3, 'value': 'three'}
252+
}}
249253
docs = list(fs.collection('foo').select(['id']).stream())
250-
self.assertEquals({'id': 1}, docs[0].to_dict())
251-
self.assertEquals({'id': 2}, docs[1].to_dict())
252-
self.assertEquals({'id': 3}, docs[2].to_dict())
254+
self.assertEqual({'id': 1}, docs[0].to_dict())
255+
self.assertEqual({'id': 2}, docs[1].to_dict())
256+
self.assertEqual({'id': 3}, docs[2].to_dict())
257+
258+
def test_collection_select_missing_fields(self):
259+
fs = MockFirestore()
260+
fs._data = {'foo': {
261+
'first': {'id': 1, 'value': 'one'},
262+
'second': {'id': 2, 'value': 'two'},
263+
'third': {'id': 3, 'value': 'three'}
264+
}}
265+
docs = list(fs.collection("foo").select(["name"]).stream())
266+
self.assertEqual({}, docs[0].to_dict())
267+
self.assertEqual({}, docs[1].to_dict())
268+
self.assertEqual({}, docs[2].to_dict())
269+
270+
def test_collection_select_one_missing_field(self):
271+
fs = MockFirestore()
272+
fs._data = {'foo': {
273+
'first': {'id': 1, 'value': 'one'},
274+
'second': {'id': 2, 'value': 'two'},
275+
'third': {'id': 3, 'value': 'three'}
276+
}}
277+
docs = list(fs.collection("foo").select(["id", "name"]).stream())
278+
self.assertEqual({"id": 1}, docs[0].to_dict())
279+
self.assertEqual({"id": 2}, docs[1].to_dict())
280+
self.assertEqual({"id": 3}, docs[2].to_dict())
253281

254282
def test_collection_start_at(self):
255283
fs = MockFirestore()

0 commit comments

Comments
 (0)