Skip to content

Commit

Permalink
Allow querying on multiple gating statuses simultaneously
Browse files Browse the repository at this point in the history
I have a script that wants to find updates that are in waiting or
failed gating status. It's annoying to have to run two searches.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
  • Loading branch information
AdamWill committed May 14, 2024
1 parent 6919373 commit 97a8408
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
13 changes: 10 additions & 3 deletions bodhi-server/bodhi/server/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ class Status(colander.SequenceSchema):
validator=colander.OneOf(list(UpdateStatus.values())))


class GatingStatus(colander.SequenceSchema):
"""A SequenceSchema to validate a list of TestGatingStatus objects."""

status = colander.SchemaNode(colander.String(),
validator=colander.OneOf(list(TestGatingStatus.values())))


class Tests(colander.SequenceSchema):
"""A SequenceSchema to validate a list of Test objects."""

Expand Down Expand Up @@ -653,11 +660,11 @@ class ListUpdateSchema(PaginatedSchema, SearchableSchema, Cosmetics):
preparer=[util.splitter],
)

gating = colander.SchemaNode(
colander.String(),
gating = GatingStatus(
colander.Sequence(accept_scalar=True),
location="querystring",
missing=None,
validator=colander.OneOf(list(TestGatingStatus.values())),
preparer=[util.splitter],
)


Expand Down
2 changes: 1 addition & 1 deletion bodhi-server/bodhi/server/services/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def query_updates(request):

gating_status = data.get('gating')
if gating_status is not None:
query = query.filter(Update.test_gating_status == gating_status)
query = query.filter(or_(*[Update.test_gating_status == s for s in gating_status]))

user = data.get('user')
if user is not None:
Expand Down
20 changes: 20 additions & 0 deletions bodhi-server/tests/services/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2956,6 +2956,26 @@ def test_list_updates_by_gating_status(self):
assert up['alias'] == f'FEDORA-{YEAR}-a3bbe1a8f2'
assert up['karma'] == 1

def test_list_updates_by_gating_status_multiple(self):
# set the bodhi update's gating status to passed, add two
# updates with different gating statuses, query for those
# two statuses and expect to find those updates but not the
# bodhi update
bodhi = self.db.query(Build).filter_by(nvr='bodhi-2.0-1.fc17').one().update
bodhi.test_gating_status = TestGatingStatus.passed
firefox = self.create_update(['firefox-61.0.2-3.fc17'])
firefox.test_gating_status = TestGatingStatus.failed
python_nose = self.create_update(['python-nose-1.3.7-11.fc17'])
python_nose.test_gating_status = TestGatingStatus.waiting
self.db.commit()

res = self.app.get('/updates/', {"gating": ["failed", "waiting"]})
body = res.json_body
assert len(body['updates']) == 2
expected = ['firefox-61.0.2-3.fc17', 'python-nose-1.3.7-11.fc17']
actual = sorted(update['title'] for update in body['updates'])
assert expected == actual

def test_list_updates_by_from_side_tag(self):
up = self.db.query(Build).filter_by(nvr='bodhi-2.0-1.fc17').one().update
up.from_tag = 'f33-side-tag'
Expand Down
1 change: 1 addition & 0 deletions news/PR5658.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When searching updates, you can now specify multiple gating statuses by passing the 'gating' query arg more than once

0 comments on commit 97a8408

Please sign in to comment.