Skip to content

Commit

Permalink
Add ability to filter by none/null
Browse files Browse the repository at this point in the history
Fixes #37
  • Loading branch information
al4 committed Jun 17, 2016
1 parent 7c0ae2f commit f49bdd0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 6 additions & 2 deletions orlo/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,17 @@ def releases(**kwargs):
if any(field.startswith('package_') for field in kwargs.keys()) \
or "status" in kwargs.keys():
# Package attributes need the join, as does status as it's really a
# package
# attribute
# package attribute
query = db.session.query(Release).join(Package)
else:
# No need to join on package if none of our params need it
query = db.session.query(Release)

for key in kwargs.keys():
if isinstance(kwargs[key], bool):
continue
if kwargs[key].lower() in ['null', 'none']:
kwargs[key] = None
try:
query = apply_filters(query, kwargs)
except AttributeError as e:
Expand Down
17 changes: 15 additions & 2 deletions tests/test_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,12 @@ def _get_releases_time_filter(self, field, finished=False):
yesterday = (now - timedelta(days=1)).strftime(t_format)
tomorrow = (now + timedelta(days=1)).strftime(t_format)

r_yesterday = self._get_releases(filters=['{}={}'.format(field, yesterday)])
r_tomorrow = self._get_releases(filters=['{}={}'.format(field, tomorrow)])
r_yesterday = self._get_releases(
filters=['{}={}'.format(field, yesterday)]
)
r_tomorrow = self._get_releases(
filters=['{}={}'.format(field, tomorrow)]
)

return r_yesterday, r_tomorrow

Expand All @@ -501,6 +505,15 @@ def test_get_release_filter_stime_before(self):
self.assertEqual(3, len(r_tomorrow['releases']))
self.assertEqual(0, len(r_yesterday['releases']))

def test_get_release_filter_ftime_null(self):
"""
Filter on releases that don't have a finish time
"""
releases = self._get_releases(
filters=['{}={}'.format('ftime', 'null')]
)
self.assertEqual(len(releases['releases']), 0)

def test_get_release_filter_stime_after(self):
"""
Filter on releases that started after a particular time
Expand Down

0 comments on commit f49bdd0

Please sign in to comment.