← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/project-default-git-location into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/project-default-git-location into lp:launchpad.

Commit message:
Set an appropriate initial default for "Git repository" on Product:+configure-code.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/project-default-git-location/+merge/263486

Set an appropriate initial default for "Git repository" on Product:+configure-code.  It shouldn't be blank if the project already has a default Git repository.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/project-default-git-location into lp:launchpad.
=== modified file 'lib/lp/registry/browser/product.py'
--- lib/lp/registry/browser/product.py	2015-06-25 03:33:33 +0000
+++ lib/lp/registry/browser/product.py	2015-07-01 09:36:45 +0000
@@ -71,7 +71,6 @@
 from zope.schema import (
     Bool,
     Choice,
-    TextLine,
     )
 from zope.schema.vocabulary import (
     SimpleTerm,
@@ -1725,11 +1724,14 @@
 
     @property
     def initial_values(self):
+        repository_set = getUtility(IGitRepositorySet)
         return dict(
             rcs_type=RevisionControlSystems.BZR,
             default_vcs=(self.context.pillar.inferred_vcs or VCSType.BZR),
             branch_type=LINK_LP_BZR,
-            branch_location=self.series.branch)
+            branch_location=self.series.branch,
+            git_repository_location=repository_set.getDefaultRepository(
+                self.context.pillar))
 
     @property
     def next_url(self):

=== modified file 'lib/lp/registry/browser/tests/test_product_views.py'
--- lib/lp/registry/browser/tests/test_product_views.py	2015-06-24 21:14:20 +0000
+++ lib/lp/registry/browser/tests/test_product_views.py	2015-07-01 09:36:45 +0000
@@ -6,10 +6,15 @@
 __metaclass__ = type
 
 import soupmatchers
+from zope.component import getUtility
 from zope.security.proxy import removeSecurityProxy
 
+from lp.code.interfaces.gitrepository import IGitRepositorySet
 from lp.services.webapp import canonical_url
-from lp.testing import BrowserTestCase
+from lp.testing import (
+    BrowserTestCase,
+    person_logged_in,
+    )
 from lp.testing.layers import DatabaseFunctionalLayer
 
 
@@ -22,6 +27,25 @@
         url = canonical_url(project, view_name=view_name)
         return self.getUserBrowser(url, project.owner)
 
+    def test_no_initial_git_repository(self):
+        # If a project has no default Git repository, its "Git repository"
+        # control defaults to empty.
+        project = self.factory.makeProduct()
+        browser = self.getBrowser(project, '+configure-code')
+        self.assertEqual('', browser.getControl('Git repository').value)
+
+    def test_initial_git_repository(self):
+        # If a project has a default Git repository, its "Git repository"
+        # control defaults to the unique name of that repository.
+        project = self.factory.makeProduct()
+        repo = self.factory.makeGitRepository(target=project)
+        with person_logged_in(project.owner):
+            getUtility(IGitRepositorySet).setDefaultRepository(project, repo)
+        unique_name = repo.unique_name
+        browser = self.getBrowser(project, '+configure-code')
+        self.assertEqual(
+            unique_name, browser.getControl('Git repository').value)
+
     def test_link_existing_git_repository(self):
         repo = removeSecurityProxy(self.factory.makeGitRepository(
             target=self.factory.makeProduct()))


Follow ups