Repository: fedora-infra/bodhi

Issue:
add option to query according to update title
If I know the update title, there seems to be no way to retrieve the corresponding update object. There is no `query(title=)` or similar. Can you please implement this?

From IRC:

```
<threebean> kparal: can you file an RFE to add a 'title' to the ListUpdatesSchema ?
```

And a follow-up:

```
<lmacken> kparal: like=title should work?
<lmacken> but we should have a proper title field
<kparal> lmacken: that works!
```

python-fedora 0.5.5



Discussion:
Adding it not just to update schema but also to the docstring would be appreciated ;-)

Yes, thanks!


Resolving patch:
diff --git a/bodhi/client/__init__.py b/bodhi/client/__init__.py
--- a/bodhi/client/__init__.py
+++ b/bodhi/client/__init__.py
@@ -459,6 +459,7 @@ def edit(user, password, url, debug, **kwargs):
 
 @updates.command()
 @click.option('--updateid', help='Query by update ID (eg: FEDORA-2015-0001)')
+@click.option('--title', help='Query by title')
 @click.option('--alias', help='Query by alias')
 @click.option('--approved-since', help='Approved after a specific timestamp')
 @click.option('--approved-before', help='Approved before a specific timestamp')
diff --git a/bodhi/client/bindings.py b/bodhi/client/bindings.py
--- a/bodhi/client/bindings.py
+++ b/bodhi/client/bindings.py
@@ -302,6 +302,7 @@ def query(self, **kwargs):
         Query bodhi for a list of updates.
 
         Args:
+            title (basestring): The update title.
             alias (basestring): The update alias.
             updateid (basestring): The update ID (eg: FEDORA-2015-0001).
             content_type (basestring): A content type (rpm, module) to limit the query to.
@@ -349,6 +350,9 @@ def query(self, **kwargs):
         Returns:
             munch.Munch: The response from Bodhi describing the query results.
         """
+        if 'title' in kwargs:
+            kwargs['like'] = kwargs['title']
+            del kwargs['title']
         # bodhi1 compat
         if 'limit' in kwargs:
             kwargs['rows_per_page'] = kwargs['limit']


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
@@ -656,7 +656,7 @@ def test_query_single_update(self, send_request):
             mock.call(
                 bindings_client, 'updates/', verb='GET',
                 params={
-                    'updateid': None, 'alias': None, 'approved_since': None,
+                    'updateid': None, 'alias': None, 'approved_since': None, 'like': None,
                     'approved_before': None, 'status': None, 'locked': None,
                     'builds': u'nodejs-grunt-wrap-0.3.0-2.fc25', 'releases': None,
                     'active_releases': None, 'content_type': None, 'severity': None,
@@ -697,7 +697,7 @@ def test_query_multiple_update(self, send_request):
         send_request.assert_called_once_with(
             bindings_client, 'updates/', verb='GET',
             params={
-                'updateid': None, 'alias': None, 'approved_since': None,
+                'updateid': None, 'alias': None, 'approved_since': None, 'like': None,
                 'approved_before': None, 'status': None, 'locked': None,
                 'builds': u'nodejs-grunt-wrap-0.3.0-2.fc25', 'releases': None,
                 'active_releases': None, 'content_type': None, 'severity': None,
@@ -730,7 +730,7 @@ def test_url_flag(self, send_request):
             mock.call(
                 bindings_client, 'updates/', verb='GET',
                 params={
-                    'updateid': None, 'alias': None, 'approved_since': None,
+                    'updateid': None, 'alias': None, 'approved_since': None, 'like': None,
                     'approved_before': None, 'status': None, 'locked': None,
                     'builds': u'nodejs-grunt-wrap-0.3.0-2.fc25', 'releases': None,
                     'active_releases': None, 'content_type': None, 'severity': None,
@@ -771,7 +771,7 @@ def test_query_mine_flag_username_unset(self, mock_input, send_request):
             mock.call(
                 bindings_client, 'updates/', verb='GET',
                 params={
-                    'updateid': None, 'alias': None, 'approved_since': None,
+                    'updateid': None, 'alias': None, 'approved_since': None, 'like': None,
                     'approved_before': None, 'status': None, 'locked': None,
                     'builds': None, 'releases': None, 'active_releases': None,
                     'content_type': None, 'severity': None, 'submitted_since': None,
@@ -813,7 +813,7 @@ def test_rows_flag(self, send_request):
                 params={
                     'updateid': None, 'alias': None, 'approved_since': None,
                     'approved_before': None, 'status': None, 'locked': None,
-                    'builds': None, 'releases': None,
+                    'builds': None, 'releases': None, 'like': None,
                     'active_releases': None, 'content_type': None, 'severity': None,
                     'submitted_since': None, 'submitted_before': None, 'suggest': None,
                     'request': None, 'bugs': None, 'staging': False, 'modified_since': None,
@@ -852,7 +852,7 @@ def test_page_flag(self, send_request):
                 params={
                     'updateid': None, 'alias': None, 'approved_since': None,
                     'approved_before': None, 'status': None, 'locked': None,
-                    'builds': None, 'releases': None,
+                    'builds': None, 'releases': None, 'like': None,
                     'active_releases': None, 'content_type': None, 'severity': None,
                     'submitted_since': None, 'submitted_before': None, 'suggest': None,
                     'request': None, 'bugs': None, 'staging': False, 'modified_since': None,
@@ -869,6 +869,45 @@ def test_page_flag(self, send_request):
         ]
         self.assertEqual(send_request.mock_calls, calls)
 
+    @mock.patch('bodhi.client.bindings.BodhiClient.csrf',
+                mock.MagicMock(return_value='a_csrf_token'))
+    @mock.patch('bodhi.client.bindings.BodhiClient.send_request',
+                return_value=client_test_data.EXAMPLE_QUERY_MUNCH, autospec=True)
+    def test_title_flag(self, send_request):
+        """
+        Assert correct behavior with the --title flag.
+        """
+        runner = testing.CliRunner()
+
+        result = runner.invoke(
+            client.query,
+            ['--title', 'nodejs-grunt-wrap-0.3.0-2.fc25'])
+
+        self.assertEqual(result.exit_code, 0)
+        bindings_client = send_request.mock_calls[0][1][0]
+        calls = [
+            mock.call(
+                bindings_client, 'updates/', verb='GET',
+                params={
+                    'updateid': None, 'alias': None, 'approved_since': None,
+                    'approved_before': None, 'status': None, 'locked': None,
+                    'builds': None, 'releases': None, 'like': u'nodejs-grunt-wrap-0.3.0-2.fc25',
+                    'active_releases': None, 'content_type': None, 'severity': None,
+                    'submitted_since': None, 'submitted_before': None, 'suggest': None,
+                    'request': None, 'bugs': None, 'staging': False, 'modified_since': None,
+                    'modified_before': None, 'pushed': None, 'pushed_since': None,
+                    'pushed_before': None, 'user': None, 'critpath': None, 'packages': None,
+                    'type': None, 'cves': None, 'rows_per_page': None, 'page': None
+                },
+            ),
+            mock.call(
+                bindings_client,
+                u'updates/FEDORA-2017-c95b33872d/get-test-results',
+                verb='GET'
+            )
+        ]
+        self.assertEqual(send_request.mock_calls, calls)
+
 
 class TestQueryBuildrootOverrides(unittest.TestCase):
     """
diff --git a/bodhi/tests/client/test_bindings.py b/bodhi/tests/client/test_bindings.py
--- a/bodhi/tests/client/test_bindings.py
+++ b/bodhi/tests/client/test_bindings.py
@@ -817,6 +817,19 @@ def test_with_page(self):
         client.send_request.assert_called_once_with(
             'updates/', verb='GET', params={'packages': 'bodhi', 'page': 5})
 
+    def test_with_title(self):
+        """
+        Test with the 'title' kwarg.
+        """
+        client = bindings.BodhiClient()
+        client.send_request = mock.MagicMock(return_value='return_value')
+
+        result = client.query(title='nest-2.16.0-1.fc28')
+
+        self.assertEqual(result, 'return_value')
+        client.send_request.assert_called_once_with(
+            'updates/', verb='GET', params={'like': 'nest-2.16.0-1.fc28'})
+
 
 class TestBodhiClient_save(unittest.TestCase):
     """