Skip to content

Commit 11f70f0

Browse files
authored
Fixing start_at, end_at, equal_to queries to accept False values (#96)
* Fixing start_at, end_at, equal_to queries to accept False values * Updating docs
1 parent d8a9345 commit 11f70f0

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

firebase_admin/db.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,10 @@ def start_at(self, start):
442442
Query: The updated Query instance.
443443
444444
Raises:
445-
ValueError: If the value is empty or None.
445+
ValueError: If the value is None.
446446
"""
447-
if not start:
448-
raise ValueError('Start value must not be empty or None.')
447+
if start is None:
448+
raise ValueError('Start value must not be None.')
449449
self._params['startAt'] = json.dumps(start)
450450
return self
451451

@@ -462,10 +462,10 @@ def end_at(self, end):
462462
Query: The updated Query instance.
463463
464464
Raises:
465-
ValueError: If the value is empty or None.
465+
ValueError: If the value is None.
466466
"""
467-
if not end:
468-
raise ValueError('End value must not be empty or None.')
467+
if end is None:
468+
raise ValueError('End value must not be None.')
469469
self._params['endAt'] = json.dumps(end)
470470
return self
471471

@@ -481,10 +481,10 @@ def equal_to(self, value):
481481
Query: The updated Query instance.
482482
483483
Raises:
484-
ValueError: If the value is empty or None.
484+
ValueError: If the value is None.
485485
"""
486-
if not value:
487-
raise ValueError('Equal to value must not be empty or None.')
486+
if value is None:
487+
raise ValueError('Equal to value must not be None.')
488488
self._params['equalTo'] = json.dumps(value)
489489
return self
490490

tests/test_db.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,16 +694,31 @@ def test_start_at_none(self):
694694
with pytest.raises(ValueError):
695695
query.start_at(None)
696696

697+
@pytest.mark.parametrize('arg', ['', 'foo', True, False, 0, 1, dict()])
698+
def test_valid_start_at(self, arg):
699+
query = self.ref.order_by_child('foo').start_at(arg)
700+
assert query._querystr == 'orderBy="foo"&startAt={0}'.format(json.dumps(arg))
701+
697702
def test_end_at_none(self):
698703
query = self.ref.order_by_child('foo')
699704
with pytest.raises(ValueError):
700705
query.end_at(None)
701706

707+
@pytest.mark.parametrize('arg', ['', 'foo', True, False, 0, 1, dict()])
708+
def test_valid_end_at(self, arg):
709+
query = self.ref.order_by_child('foo').end_at(arg)
710+
assert query._querystr == 'endAt={0}&orderBy="foo"'.format(json.dumps(arg))
711+
702712
def test_equal_to_none(self):
703713
query = self.ref.order_by_child('foo')
704714
with pytest.raises(ValueError):
705715
query.equal_to(None)
706716

717+
@pytest.mark.parametrize('arg', ['', 'foo', True, False, 0, 1, dict()])
718+
def test_valid_equal_to(self, arg):
719+
query = self.ref.order_by_child('foo').equal_to(arg)
720+
assert query._querystr == 'equalTo={0}&orderBy="foo"'.format(json.dumps(arg))
721+
707722
def test_range_query(self, initquery):
708723
query, order_by = initquery
709724
query.start_at(1)

0 commit comments

Comments
 (0)