Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

All clobbers endpoints #32

Merged
5 commits merged into from Feb 22, 2015
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion relengapi/blueprints/clobberer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,31 @@ def branches():
return [branch[0] for branch in branches]


@bp.route('/lastclobber/all', methods=['GET'])
@apimethod([rest.ClobberTime])
def lastclobber_all():
"Return a sorted list of all clobbers"
session = g.db.session(DB_DECLARATIVE_BASE)
return session.query(ClobberTime).order_by(ClobberTime.lastclobber)


@bp.route('/lastclobber/greater-than/<int:mintime>', methods=['GET'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be better as /lastclobber/since/<int:mintime> or even /lastclobber/all?since=<int:mintime>.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djmitche oooh, yes, I like that idea. Thanks!

@apimethod([rest.ClobberTime], int)
def lastclobber_greater_than(mintime):
"Return a sorted list of all clobbers greater than the time passed in"
session = g.db.session(DB_DECLARATIVE_BASE)
return session.query(ClobberTime).filter(
ClobberTime.lastclobber > mintime
).order_by(ClobberTime.lastclobber)


@bp.route('/lastclobber/branch/by-builder/<string:branch>', methods=['GET'])
@apimethod({unicode: [rest.ClobberTime]}, unicode)
def lastclobber_by_builder(branch):
"Return a dictionary of most recent ClobberTimes grouped by buildername."

# TODO: simplify this query, new clobberer _only_ tracks max clobber times
# - old clobberer did not - so this query may be simplified under that
# assuption
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get a bug or issue on file and point to it in this comment -- sounds like a good fix for a first-time contributor or a sprint.

session = g.db.session(DB_DECLARATIVE_BASE)

# Isolates the maximum lastclobber for each builddir on a branch
Expand Down
29 changes: 29 additions & 0 deletions relengapi/blueprints/clobberer/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,35 @@ def test_clobber_request(client):
'No new clobbers were detected, clobber request failed.')


@ test_context
def test_lastclobber_all(client):
rv = client.get('/clobberer/lastclobber/all')
eq_(rv.status_code, 200)
clobbertimes = json.loads(rv.data)["result"]
eq_(len(clobbertimes), len(_clobber_args))


@ test_context
def test_lastclobber_greater_than(client):
session = test_context._app.db.session(DB_DECLARATIVE_BASE)
min_ct = session.query(ClobberTime.lastclobber).order_by(
ClobberTime.lastclobber
).first()[0]

# since this is less than the min, we should see all the results
lt_min_ct = min_ct - 1
rv = client.get('/clobberer/lastclobber/greater-than/%i' % lt_min_ct)
eq_(rv.status_code, 200)
lt_min_ct_result = json.loads(rv.data)["result"]
eq_(len(lt_min_ct_result), len(_clobber_args))

# now we should see less than last time
rv = client.get('/clobberer/lastclobber/greater-than/%i' % min_ct)
eq_(rv.status_code, 200)
min_ct_result = json.loads(rv.data)["result"]
assert len(lt_min_ct_result) > len(min_ct_result)


@test_context
def test_clobber_request_of_release(client):
"Ensures that attempting to clobber a release build will fail."
Expand Down