Repository: fedora-infra/bodhi

Issue:
Add info how to test update
https://bodhi.fedoraproject.org/updates/FEDORA-2018-2a55cd1b82 - from this page it is absolutely unclear how to test the update. How do you know?


Discussion:
We could probably add a template to the page that can fill in Fedora specific items for how to test an update.

In the meantime, you can install an update on Fedora like this:

```
$ sudo dnf upgrade --enablerepo updates-testing --advisory FEDORA-2018-2a55cd1b82
```

Resolving patch:
diff --git a/bodhi/server/util.py b/bodhi/server/util.py
--- a/bodhi/server/util.py
+++ b/bodhi/server/util.py
@@ -1523,3 +1523,28 @@ def get_absolute_path(location):
     module, final = location.split(':')
     base = os.path.dirname(__import__(module).__file__)
     return base + "/" + final
+
+
+def update_install_command(context, update):
+    """
+    Return the dnf command for installing the Update.
+
+    Args:
+        context (mako.runtime.Context): Unused.
+        update (bodhi.server.models.Update): The Update you want to install.
+    Returns:
+        basestring: The dnf command to install the Update.
+    """
+    status = six.text_type(update.status)
+    alias = update.alias
+    update_type = six.text_type(update.type)
+
+    if status != 'stable' and status != 'testing':
+        raise ValueError('Only updates in stable or testing can be installed!')
+
+    command = 'sudo dnf {}{} --advisory={}{}'.format(
+        'install' if update_type == 'newpackage' else 'upgrade',
+        ' --enablerepo=updates-testing' if status == 'testing' else '',
+        alias,
+        r' \*' if update_type == 'newpackage' else '')
+    return command


Test patch:
diff --git a/bodhi/tests/server/test_util.py b/bodhi/tests/server/test_util.py
--- a/bodhi/tests/server/test_util.py
+++ b/bodhi/tests/server/test_util.py
@@ -30,7 +30,7 @@
 from bodhi.server import util, models
 from bodhi.server.config import config
 from bodhi.server.models import (ComposeState, TestGatingStatus, Update, UpdateRequest,
-                                 UpdateSeverity)
+                                 UpdateSeverity, UpdateStatus, UpdateType)
 from bodhi.tests.server import base
 
 if six.PY2:
@@ -1571,3 +1571,68 @@ def test___call___success(self, Session, log_exception):
         Session.return_value.commit.assert_called_once_with()
         Session.return_value.close.assert_called_once_with()
         Session.remove.assert_called_once_with()
+
+
+class TestUpdateInstallCommand(base.BaseTestCase):
+    """Test the update_install_command() function."""
+
+    def test_upgrade_in_testing(self):
+        """Update is an enhancement, a security or a bugfix and is in testing."""
+        context = {'request': mock.MagicMock()}
+        update = models.Update.query.first()
+        update.status = UpdateStatus.testing
+        update.type = UpdateType.bugfix
+
+        command = util.update_install_command(context, update)
+
+        self.assertEqual(
+            command,
+            'sudo dnf upgrade --enablerepo=updates-testing --advisory={}'.format(update.alias))
+
+    def test_upgrade_in_stable(self):
+        """Update is an enhancement, a security or a bugfix and is in stable."""
+        context = {'request': mock.MagicMock()}
+        update = models.Update.query.first()
+        update.status = UpdateStatus.stable
+        update.type = UpdateType.bugfix
+
+        command = util.update_install_command(context, update)
+
+        self.assertEqual(
+            command,
+            'sudo dnf upgrade --advisory={}'.format(update.alias))
+
+    def test_newpackage_in_testing(self):
+        """Update is a newpackage and is in testing."""
+        context = {'request': mock.MagicMock()}
+        update = models.Update.query.first()
+        update.status = UpdateStatus.testing
+        update.type = UpdateType.newpackage
+
+        command = util.update_install_command(context, update)
+
+        self.assertEqual(
+            command,
+            r'sudo dnf install --enablerepo=updates-testing --advisory={} \*'.format(update.alias))
+
+    def test_newpackage_in_stable(self):
+        """Update is a newpackage and is in stable."""
+        context = {'request': mock.MagicMock()}
+        update = models.Update.query.first()
+        update.status = UpdateStatus.stable
+        update.type = UpdateType.newpackage
+
+        command = util.update_install_command(context, update)
+
+        self.assertEqual(
+            command,
+            r'sudo dnf install --advisory={} \*'.format(update.alias))
+
+    def test_cannot_install(self):
+        """Update is out of stable or testing repositories."""
+        context = {'request': mock.MagicMock()}
+        update = models.Update.query.first()
+        update.status = UpdateStatus.obsolete
+
+        with self.assertRaises(ValueError):
+            util.update_install_command(context, update)