← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/stray-editsshkeys-link into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/stray-editsshkeys-link into lp:launchpad.

Commit message:
Fix stray link to +editsshkeys on Product:+configure-code when SSH keys were already registered.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1534159 in Launchpad itself: "Product:+configure-code always shows +editsshkeys link"
  https://bugs.launchpad.net/launchpad/+bug/1534159

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/stray-editsshkeys-link/+merge/282612

Fix stray link to +editsshkeys on Product:+configure-code when SSH keys were already registered.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/stray-editsshkeys-link into lp:launchpad.
=== modified file 'lib/lp/code/templates/configure-code-macros.pt'
--- lib/lp/code/templates/configure-code-macros.pt	2015-06-24 21:22:17 +0000
+++ lib/lp/code/templates/configure-code-macros.pt	2016-01-14 15:48:18 +0000
@@ -30,7 +30,7 @@
     </p>
   </div>
 
-  <div metal:define-macro="no-keys" condition="not:view/user/sshkeys">
+  <div metal:define-macro="no-keys" tal:condition="not:view/user/sshkeys">
     <p class="infobox">To authenticate with the Launchpad branch upload service, you need to
     <a tal:attributes="href string:${view/user/fmt:url}/+editsshkeys">
     register an SSH key</a>.</p>

=== modified file 'lib/lp/registry/browser/tests/test_product_views.py'
--- lib/lp/registry/browser/tests/test_product_views.py	2015-07-01 09:31:48 +0000
+++ lib/lp/registry/browser/tests/test_product_views.py	2016-01-14 15:48:18 +0000
@@ -1,10 +1,13 @@
-# Copyright 2011-2015 Canonical Ltd.  This software is licensed under the
+# Copyright 2011-2016 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """View tests for Product pages."""
 
 __metaclass__ = type
 
+import re
+
+from testtools.matchers import Not
 import soupmatchers
 from zope.component import getUtility
 from zope.security.proxy import removeSecurityProxy
@@ -22,6 +25,10 @@
 
     layer = DatabaseFunctionalLayer
 
+    editsshkeys_tag = soupmatchers.Tag(
+        'edit SSH keys', 'a', text=re.compile('register an SSH key'),
+        attrs={'href': re.compile(r'/\+editsshkeys$')})
+
     def getBrowser(self, project, view_name=None):
         project = removeSecurityProxy(project)
         url = canonical_url(project, view_name=view_name)
@@ -58,3 +65,18 @@
             'success-div', 'div', attrs={'class': 'informational message'},
              text='Project settings updated.')
         self.assertThat(browser.contents, soupmatchers.HTMLContains(tag))
+
+    def test_editsshkeys_link_if_no_keys_registered(self):
+        project = self.factory.makeProduct()
+        browser = self.getBrowser(project, '+configure-code')
+        self.assertThat(
+            browser.contents, soupmatchers.HTMLContains(self.editsshkeys_tag))
+
+    def test_no_editsshkeys_link_if_keys_registered(self):
+        project = self.factory.makeProduct()
+        with person_logged_in(project.owner):
+            self.factory.makeSSHKey(person=project.owner)
+        browser = self.getBrowser(project, '+configure-code')
+        self.assertThat(
+            browser.contents,
+            Not(soupmatchers.HTMLContains(self.editsshkeys_tag)))


Follow ups