Skip to content

Commit

Permalink
Display the push to batched button for pushed updates.
Browse files Browse the repository at this point in the history
The HTML template code is crazy[0,1] and its craziness was
underestimated when the batching feature was first written. It
turns out that it would only display the push to batched button for
unpushed updates.

This commit refactors the template code to be slightly less crazy
(further refactoring is certainly needed), and displays that button
on pushed updates. It also adds several test cases to assert that
the correct buttons appear at the right times.

These new tests revealed that the CI tests were leaking state, as
they would pass on their own but fail if the CI tests were run
first. Thus, this commit also refactors the CI tests to stop
leaking state by using mock.

fixes fedora-infra#1875
re fedora-infra#1887
re fedora-infra#1888

[0] fedora-infra#1887
[1] fedora-infra#1888

Signed-off-by: Randy Barlow <randy@electronsweatshop.com>
  • Loading branch information
bowlofeggs committed Oct 11, 2017
1 parent 47ed7e4 commit 7ab232c
Show file tree
Hide file tree
Showing 5 changed files with 324 additions and 55 deletions.
21 changes: 9 additions & 12 deletions bodhi/server/templates/update.html
Original file line number Diff line number Diff line change
Expand Up @@ -499,30 +499,27 @@ <h1>
% if can_edit:
% if not update.locked:
<div id='updatebuttons' class="btn-group pull-right" role="group" aria-label="...">
<a id='edit' class="btn btn-sm btn-primary"><span class="fa fa-fw fa-pencil"></span> Edit</a>
% if not update.pushed:
<a id='edit' class="btn btn-sm btn-primary"><span class="fa fa-fw fa-pencil"></span> Edit</a>
% if update.request is None:
% if update.status.description != 'testing':
<a id='testing' class="btn btn-sm btn-success"><span class="fa fa-fw fa-arrow-circle-right"></span> Push to Testing</a>
% endif
% if update.status.description not in ['stable', 'obsolete']:
<a id='batched' class="btn btn-sm btn-success"><span class="fa fa-fw fa-arrow-circle-right"></span> Push to Batched</a>
% endif
% elif update.request.description == 'batched':
<a id='stable' class="btn btn-sm btn-success"><span class="fa fa-fw fa-arrow-circle-right"></span> Push to Stable</a>
% elif update.request.description in ['batched', 'stable']:
${self.util.push_to_batched_or_stable_button(update) | n}
% else:
<a id='revoke' class="btn btn-sm btn-danger"><span class="fa fa-fw fa-arrow-circle-left"></span> Revoke</a>
% endif
% elif update.pushed and (update.status.description != 'stable' or (update.status.description == 'stable' and 'releng' in [group.name for group in request.user.groups])):
<a id='edit' class="btn btn-sm btn-default"><span class="fa fa-fw fa-pencil"></span> Edit</a>
% if update.critpath and getattr(update.request, 'description', None) != 'stable':
% if update.critpath_approved:
<a id='stable' class="btn btn-sm btn-success"><span class="fa fa-fw fa-arrow-circle-right"></span> Push to Stable</a>
% endif
% elif update.meets_testing_requirements and getattr(update.request, 'description', None) != 'stable':
<a id='stable' class="btn btn-sm btn-success"><span class="fa fa-fw fa-arrow-circle-right"></span> Push to Stable</a>
% elif update.stable_karma not in (0, None) and update.karma >= update.stable_karma and not update.autokarma and getattr(update.request, 'description', None) != 'stable':
<a id='stable' class="btn btn-sm btn-success"><span class="fa fa-fw fa-arrow-circle-right"></span> Push to Stable</a>
% if update.critpath and update.critpath_approved:
${self.util.push_to_batched_or_stable_button(update) | n}
% elif update.meets_testing_requirements:
${self.util.push_to_batched_or_stable_button(update) | n}
% elif update.stable_karma not in (0, None) and update.karma >= update.stable_karma and not update.autokarma:
${self.util.push_to_batched_or_stable_button(update) | n}
% endif
<a id='unpush' class="btn btn-sm btn-danger"><span class="fa fa-fw fa-arrow-circle-left"></span> Unpush</a>
% endif
Expand Down
23 changes: 23 additions & 0 deletions bodhi/server/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,29 @@ def bug_link(context, bug, short=False):
return link


def push_to_batched_or_stable_button(context, update):
"""
Form the push to batched or push to stable button, as appropriate.
Args:
context (mako.runtime.Context): The current template rendering context. Unused.
update (bodhi.server.models.Update): The Update we are rendering a button about.
Returns:
basestring: HTML for a button that will draw the push to stable or push to batched button,
as appropriate.
"""
if getattr(update.request, 'description', None) == 'batched' or \
getattr(update.severity, 'description', None) == 'urgent':
button = ('stable', 'Stable')
elif getattr(update.request, 'description', None) in ('stable', None):
button = ('batched', 'Batched')
else:
return ''

return ('<a id="{}" class="btn btn-sm btn-success">'
'<span class="fa fa-fw fa-arrow-circle-right"></span> Push to {}</a>').format(*button)


def testcase_link(context, test, short=False):
"""
Form a URL to a given test description.
Expand Down
Loading

0 comments on commit 7ab232c

Please sign in to comment.