Repository: fedora-infra/bodhi

Issue:
CLI forces user to pass --notes or --notes-file when --file is used
```fedpkg``` passes update notes via the update ini file, but the development version of Bodhi now requires ```--notes``` or ```--notes-file``` to be passed to the client. This breaks ```fedpkg update```:

```
$ fedpkg update
ERROR: must specify at least one of --notes, --notes-file
Could not execute update: Could not generate update request: Command 'bodhi updates new --file bodhi.template --user bowlofeggs js-jquery-file-upload-9.22.0-1.fc27' returned non-zero exit status 1.
```

This is a 3.9.0 release blocker.


Discussion:

Resolving patch:
diff --git a/bodhi/client/__init__.py b/bodhi/client/__init__.py
--- a/bodhi/client/__init__.py
+++ b/bodhi/client/__init__.py
@@ -307,8 +307,8 @@ def new(user, password, url, **kwargs):
 
     kwargs['notes'] = _get_notes(**kwargs)
 
-    if not kwargs['notes']:
-        click.echo("ERROR: must specify at least one of --notes, --notes-file")
+    if not kwargs['notes'] and not kwargs['file']:
+        click.echo("ERROR: must specify at least one of --file, --notes, or --notes-file")
         sys.exit(1)
 
     for update in updates:


Test patch:
diff --git a/bodhi/tests/client/test___init__.py b/bodhi/tests/client/test___init__.py
--- a/bodhi/tests/client/test___init__.py
+++ b/bodhi/tests/client/test___init__.py
@@ -20,6 +20,7 @@
 import datetime
 import os
 import platform
+import tempfile
 import unittest
 import copy
 
@@ -39,6 +40,32 @@
 EXPECTED_DEFAULT_BASE_URL = os.environ.get('BODHI_URL', bindings.BASE_URL)
 
 
+UPDATE_FILE = '''[fedora-workstation-backgrounds-1.1-1.fc26]
+# bugfix, security, enhancement, newpackage (required)
+type=bugfix
+
+# testing, stable
+request=testing
+
+# Bug numbers: 1234,9876
+bugs=123456,43212
+
+# Here is where you give an explanation of your update.
+notes=Initial Release
+
+# Enable request automation based on the stable/unstable karma thresholds
+autokarma=True
+stable_karma=3
+unstable_karma=-3
+
+# Automatically close bugs when this marked as stable
+close_bugs=True
+
+# Suggest that users restart after update
+suggest_reboot=False
+'''
+
+
 class TestComment(unittest.TestCase):
     """
     Test the comment() function.
@@ -366,21 +393,46 @@ def test_url_flag(self, send_request):
 
     @mock.patch('bodhi.client.bindings.BodhiClient.csrf',
                 mock.MagicMock(return_value='a_csrf_token'))
-    @mock.patch('bodhi.client.bindings.BodhiClient.parse_file', autospec=True)
-    def test_file_flag(self, parse_file):
+    @mock.patch('bodhi.client.bindings.BodhiClient.send_request',
+                return_value=client_test_data.EXAMPLE_UPDATE_MUNCH, autospec=True)
+    def test_file_flag(self, send_request):
         """
         Assert correct behavior with the --file flag.
         """
         runner = testing.CliRunner()
+        with tempfile.NamedTemporaryFile() as update_file:
+            update_file.write(UPDATE_FILE.encode('utf-8'))
+            update_file.flush()
 
-        runner.invoke(
-            client.new,
-            ['--user', 'bowlofeggs', '--password', 's3kr3t', '--autokarma', 'bodhi-2.2.4-1.el7',
-             '--file', '/tmp/bodhiupdate.txt'])
-
-        bindings_client = parse_file.mock_calls[0][1][0]
+            result = runner.invoke(
+                client.new,
+                ['--user', 'bowlofeggs', '--password', 's3kr3t', '--autokarma', 'bodhi-2.2.4-1.el7',
+                 '--file', update_file.name])
 
-        parse_file.assert_called_once_with(bindings_client, u'/tmp/bodhiupdate.txt')
+        self.assertEqual(result.exit_code, 0)
+        expected_output = client_test_data.EXPECTED_UPDATE_OUTPUT.replace(
+            'http://example.com/tests', 'https://bodhi.fedoraproject.org')
+        self.assertTrue(compare_output(result.output, expected_output))
+        bindings_client = send_request.mock_calls[0][1][0]
+        calls = [
+            mock.call(
+                bindings_client, 'updates/', auth=True, verb='POST',
+                data={
+                    'close_bugs': True, 'stable_karma': '3', 'csrf_token': 'a_csrf_token',
+                    'builds': u'fedora-workstation-backgrounds-1.1-1.fc26',
+                    'autokarma': 'True', 'suggest': 'unspecified', 'notes': u'Initial Release',
+                    'request': 'testing', 'bugs': u'123456,43212',
+                    'unstable_karma': '-3', 'type_': 'bugfix', 'type': 'bugfix',
+                    'type': 'bugfix', 'severity': 'unspecified'
+                }
+            ),
+            mock.call(
+                bindings_client,
+                u'updates/FEDORA-EPEL-2016-3081a94111/get-test-results',
+                verb='GET'
+            )
+        ]
+        self.assertEqual(send_request.mock_calls, calls)
 
     @mock.patch('bodhi.client.bindings.BodhiClient.csrf',
                 mock.MagicMock(return_value='a_csrf_token'))
@@ -475,7 +527,7 @@ def test_new_update_without_notes(self):
              '--url', 'http://localhost:6543'])
 
         self.assertEqual(result.exit_code, 1)
-        self.assertEqual(result.output, u'ERROR: must specify at least one of --notes, '
+        self.assertEqual(result.output, u'ERROR: must specify at least one of --file, --notes, or '
                                         '--notes-file\n')