Skip to content

Commit

Permalink
Omit printing total value when creating multiple overrides
Browse files Browse the repository at this point in the history
Fixed #2031

Signed-off-by: Sebastian Wojciechowski <s.wojciechowski89@gmail.com>
(cherry picked from commit a9b52c2)
  • Loading branch information
sebwoj authored and mergify-bot committed Jan 10, 2019
1 parent 3c57f7d commit e2f81cd
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
5 changes: 3 additions & 2 deletions bodhi/client/__init__.py
Expand Up @@ -1031,8 +1031,9 @@ def print_resp(resp, client, verbose=False, override_hint=True):
else:
for override in resp.overrides:
click.echo(client.override_str(override).strip())
click.echo(
'%s overrides found (%d shown)' % (resp.total, len(resp.overrides)))
if 'total' in resp:
click.echo(
'%s overrides found (%d shown)' % (resp.total, len(resp.overrides)))
elif 'build' in resp:
click.echo(client.override_str(resp, minimal=False))
if override_hint:
Expand Down
59 changes: 59 additions & 0 deletions bodhi/tests/client/test___init__.py
Expand Up @@ -1341,6 +1341,65 @@ def _send_request(*args, **kwargs):
('koji', 'wait-repo', 'f25-build', '--build=js-tag-it-2.0-1.fc25'),
stderr=-1, stdout=-1)

@mock.patch('bodhi.client.bindings.BodhiClient.csrf',
mock.MagicMock(return_value='a_csrf_token'))
@mock.patch('bodhi.client.bindings.BodhiClient.send_request', autospec=True)
def test_create_multiple_overrides(self, send_request):
"""
Assert correct behavior when user creates multiple overrides.
"""
runner = testing.CliRunner()

def _send_request(*args, **kwargs):
"""Mock the response from send_request()."""
response = client_test_data.EXAMPLE_QUERY_OVERRIDES_MUNCH
del response['total']
return response

send_request.side_effect = _send_request
expected_output = client_test_data.EXPECTED_QUERY_OVERRIDES_OUTPUT
expected_output = expected_output.replace("11 overrides found (11 shown)\n", "")

overrides_nvrs = [
'nodejs-grunt-wrap-0.3.0-2.fc25',
'python-pyramid-1.5.6-3.el7',
'erlang-esip-1.0.8-1.fc25',
'erlang-stun-1.0.7-1.fc25',
'erlang-iconv-1.0.2-1.fc25',
'erlang-stringprep-1.0.6-1.fc25',
'erlang-fast_tls-1.0.7-1.fc25',
'erlang-fast_yaml-1.0.6-1.fc25',
'erlang-fast_xml-1.1.15-1.fc25',
'python-fedmsg-atomic-composer-2016.3-1.el7',
'python-fedmsg-atomic-composer-2016.3-1.fc24',
]

overrides_nvrs_str = " ".join(overrides_nvrs)

result = runner.invoke(
client.save_buildroot_overrides,
['--user', 'bowlofeggs', '--password', 's3kr3t', overrides_nvrs_str, '--url',
'http://localhost:6543/'])

self.assertEqual(result.exit_code, 0)
self.assertEqual(result.output, expected_output)
bindings_client = send_request.mock_calls[0][1][0]
# datetime is a C extension that can't be mocked, so let's just assert that the time is
# about a week away.
expire_time = send_request.mock_calls[0][2]['data']['expiration_date']
self.assertTrue((datetime.datetime.utcnow() - expire_time) < datetime.timedelta(seconds=5))
# There should be one calls to send_request().
self.assertEqual(send_request.call_count, 1)
self.assertEqual(
send_request.mock_calls[0],
mock.call(
bindings_client, 'overrides/', verb='POST', auth=True,
data={
'expiration_date': expire_time,
'notes': u'No explanation given...', 'nvr': overrides_nvrs_str,
'csrf_token': 'a_csrf_token'}))
self.assertEqual(bindings_client.base_url, 'http://localhost:6543/')


class TestWarnIfUrlAndStagingSet(unittest.TestCase):
"""
Expand Down

0 comments on commit e2f81cd

Please sign in to comment.