Repository: fedora-infra/bodhi

Issue:
The Koji URL is hardcoded in the update.html template
I noticed today that the staging Bodhi instance was linking to the production Koji instance, and it turned out that the Koji URL is hardcoded in the [template](https://github.com/fedora-infra/bodhi/blob/3.4.0/bodhi/server/templates/update.html#L1013). We should use the value from settings instead.


Discussion:

Resolving patch:
diff --git a/bodhi/server/config.py b/bodhi/server/config.py
--- a/bodhi/server/config.py
+++ b/bodhi/server/config.py
@@ -443,6 +443,9 @@ class BodhiConfig(dict):
         'waiverdb.access_token': {
             'value': None,
             'validator': _validate_none_or(six.text_type)},
+        'koji_web_url': {
+            'value': 'https://koji.fedoraproject.org/koji/',
+            'validator': _validate_tls_url},
         'koji_hub': {
             'value': 'https://koji.stg.fedoraproject.org/kojihub',
             'validator': str},


Test patch:
diff --git a/bodhi/tests/server/services/test_updates.py b/bodhi/tests/server/services/test_updates.py
--- a/bodhi/tests/server/services/test_updates.py
+++ b/bodhi/tests/server/services/test_updates.py
@@ -291,6 +291,52 @@ def test_new_rpm_update_koji_error(self, publish, *args):
         self.assertEquals(up['errors'][0]['description'],
                           "Koji error getting build: bodhi-2.0.0-2.fc17")
 
+    @mock.patch(**mock_valid_requirements)
+    @mock.patch('bodhi.server.notifications.publish')
+    def test_koji_config_url(self, publish, *args):
+        """
+        Test html rendering of default build link
+        """
+        self.app.app.registry.settings['koji_web_url'] = u'https://koji.fedoraproject.org/koji/'
+        nvr = u'bodhi-2.0.0-2.fc17'
+        resp = self.app.post_json('/updates/', self.get_update(nvr))
+
+        resp = self.app.get('/updates/%s' % nvr, headers={'Accept': 'text/html'})
+
+        self.assertRegexpMatches(str(resp), ('https://koji.fedoraproject.org/koji'
+                                             '/search\?terms=.*\&amp;type=build\&amp;match=glob'))
+
+    @mock.patch(**mock_valid_requirements)
+    @mock.patch('bodhi.server.notifications.publish')
+    def test_koji_config_url_without_trailing_slash(self, publish, *args):
+        """
+        Test html rendering of default build link without trailing slash
+        """
+        self.app.app.registry.settings['koji_web_url'] = u'https://koji.fedoraproject.org/koji'
+        nvr = u'bodhi-2.0.0-2.fc17'
+        resp = self.app.post_json('/updates/', self.get_update(nvr))
+
+        resp = self.app.get('/updates/%s' % nvr, headers={'Accept': 'text/html'})
+
+        self.assertRegexpMatches(str(resp), ('https://koji.fedoraproject.org/koji'
+                                             '/search\?terms=.*\&amp;type=build\&amp;match=glob'))
+
+    @mock.patch(**mock_valid_requirements)
+    @mock.patch('bodhi.server.notifications.publish')
+    def test_koji_config_mock_url_without_trailing_slash(self, publish, *args):
+        """
+        Test html rendering of build link using a mock config variable 'koji_web_url'
+        without a trailing slash in it
+        """
+        self.app.app.registry.settings['koji_web_url'] = u'https://host.org'
+        nvr = u'bodhi-2.0.0-2.fc17'
+        resp = self.app.post_json('/updates/', self.get_update(nvr))
+
+        resp = self.app.get('/updates/%s' % nvr, headers={'Accept': 'text/html'})
+
+        self.assertRegexpMatches(str(resp), ('https://host.org'
+                                             '/search\?terms=.*\&amp;type=build\&amp;match=glob'))
+
     @mock.patch.dict('bodhi.server.validators.config', {'acl_system': u'dummy'})
     @mock.patch(**mock_uuid4_version1)
     @mock.patch(**mock_valid_requirements)