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 #1875
re #1887
re #1888

[0] #1887
[1] #1888

Signed-off-by: Randy Barlow <[email protected]>
  • Loading branch information
bowlofeggs committed Oct 11, 2017
1 parent cebe8b7 commit aa57ba8
Show file tree
Hide file tree
Showing 5 changed files with 356 additions and 53 deletions.
18 changes: 8 additions & 10 deletions bodhi/server/templates/update.html
Original file line number Diff line number Diff line change
Expand Up @@ -508,21 +508,19 @@ <h1>
% 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 @@ -583,6 +583,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):
url = config.get('test_case_base_url') + test.name
display = test.name.replace('QA:Testcase ', '')
Expand Down
Loading

0 comments on commit aa57ba8

Please sign in to comment.