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

Proposed by Colin Watson on 2015-07-01
Status: Merged
Merged at revision: 17591
Proposed branch: lp:~cjwatson/launchpad/project-default-git-location
Merge into: lp:launchpad
Diff against target: 74 lines (+29/-3)
2 files modified
lib/lp/registry/browser/product.py (+4/-2)
lib/lp/registry/browser/tests/test_product_views.py (+25/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/project-default-git-location
Reviewer Review Type Date Requested Status
William Grant code 2015-07-01 Approve on 2015-07-01
Review via email: mp+263486@code.launchpad.net

Commit Message

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

Description of the Change

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.

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/browser/product.py'
2--- lib/lp/registry/browser/product.py 2015-06-25 03:33:33 +0000
3+++ lib/lp/registry/browser/product.py 2015-07-01 09:36:45 +0000
4@@ -71,7 +71,6 @@
5 from zope.schema import (
6 Bool,
7 Choice,
8- TextLine,
9 )
10 from zope.schema.vocabulary import (
11 SimpleTerm,
12@@ -1725,11 +1724,14 @@
13
14 @property
15 def initial_values(self):
16+ repository_set = getUtility(IGitRepositorySet)
17 return dict(
18 rcs_type=RevisionControlSystems.BZR,
19 default_vcs=(self.context.pillar.inferred_vcs or VCSType.BZR),
20 branch_type=LINK_LP_BZR,
21- branch_location=self.series.branch)
22+ branch_location=self.series.branch,
23+ git_repository_location=repository_set.getDefaultRepository(
24+ self.context.pillar))
25
26 @property
27 def next_url(self):
28
29=== modified file 'lib/lp/registry/browser/tests/test_product_views.py'
30--- lib/lp/registry/browser/tests/test_product_views.py 2015-06-24 21:14:20 +0000
31+++ lib/lp/registry/browser/tests/test_product_views.py 2015-07-01 09:36:45 +0000
32@@ -6,10 +6,15 @@
33 __metaclass__ = type
34
35 import soupmatchers
36+from zope.component import getUtility
37 from zope.security.proxy import removeSecurityProxy
38
39+from lp.code.interfaces.gitrepository import IGitRepositorySet
40 from lp.services.webapp import canonical_url
41-from lp.testing import BrowserTestCase
42+from lp.testing import (
43+ BrowserTestCase,
44+ person_logged_in,
45+ )
46 from lp.testing.layers import DatabaseFunctionalLayer
47
48
49@@ -22,6 +27,25 @@
50 url = canonical_url(project, view_name=view_name)
51 return self.getUserBrowser(url, project.owner)
52
53+ def test_no_initial_git_repository(self):
54+ # If a project has no default Git repository, its "Git repository"
55+ # control defaults to empty.
56+ project = self.factory.makeProduct()
57+ browser = self.getBrowser(project, '+configure-code')
58+ self.assertEqual('', browser.getControl('Git repository').value)
59+
60+ def test_initial_git_repository(self):
61+ # If a project has a default Git repository, its "Git repository"
62+ # control defaults to the unique name of that repository.
63+ project = self.factory.makeProduct()
64+ repo = self.factory.makeGitRepository(target=project)
65+ with person_logged_in(project.owner):
66+ getUtility(IGitRepositorySet).setDefaultRepository(project, repo)
67+ unique_name = repo.unique_name
68+ browser = self.getBrowser(project, '+configure-code')
69+ self.assertEqual(
70+ unique_name, browser.getControl('Git repository').value)
71+
72 def test_link_existing_git_repository(self):
73 repo = removeSecurityProxy(self.factory.makeGitRepository(
74 target=self.factory.makeProduct()))