Merge ~twom/launchpad:git-branch-picker-short-form-urls into launchpad:master

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: aa0f05df1fc186a803d360d2c619ea24c18818ff
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:git-branch-picker-short-form-urls
Merge into: launchpad:master
Diff against target: 63 lines (+21/-1)
2 files modified
lib/lp/code/browser/widgets/tests/test_gitrefwidget.py (+19/-0)
lib/lp/code/model/gitcollection.py (+2/-1)
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+396734@code.launchpad.net

Commit message

Allow short form owner default repository urls

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/code/browser/widgets/tests/test_gitrefwidget.py b/lib/lp/code/browser/widgets/tests/test_gitrefwidget.py
2index 92c0569..98e223a 100644
3--- a/lib/lp/code/browser/widgets/tests/test_gitrefwidget.py
4+++ b/lib/lp/code/browser/widgets/tests/test_gitrefwidget.py
5@@ -8,6 +8,7 @@ from testscenarios import (
6 load_tests_apply_scenarios,
7 WithScenarios,
8 )
9+from zope.component import getUtility
10 from zope.formlib.interfaces import (
11 IBrowserWidget,
12 IInputWidget,
13@@ -21,11 +22,13 @@ from zope.schema import ValidationError
14
15 from lp.app.validators import LaunchpadValidationError
16 from lp.code.browser.widgets.gitref import GitRefWidget
17+from lp.code.interfaces.gitrepository import IGitRepositorySet
18 from lp.code.vocabularies.gitrepository import GitRepositoryVocabulary
19 from lp.services.beautifulsoup import BeautifulSoup
20 from lp.services.webapp.escaping import html_escape
21 from lp.services.webapp.servers import LaunchpadTestRequest
22 from lp.testing import (
23+ person_logged_in,
24 TestCaseWithFactory,
25 verifyObject,
26 )
27@@ -255,6 +258,22 @@ class TestGitRefWidget(WithScenarios, TestCaseWithFactory):
28 "There is no Git repository named '%s' registered in "
29 "Launchpad." % ref.repository_url)
30
31+ def test_getInputValue_owner_default_short_form(self):
32+ owner = self.factory.makePerson()
33+ target = self.factory.makeProduct()
34+ repo = self.factory.makeGitRepository(owner=owner, target=target)
35+ [ref] = self.factory.makeGitRefs(repository=repo)
36+ with person_logged_in(repo.owner):
37+ getUtility(IGitRepositorySet).setDefaultRepositoryForOwner(
38+ owner, target, repo, owner)
39+ short_url = "~{}/{}".format(owner.name, target.name)
40+ form = {
41+ "field.git_ref.repository": short_url,
42+ "field.git_ref.path": ref.path,
43+ }
44+ self.widget.request = LaunchpadTestRequest(form=form)
45+ self.assertEqual(ref, self.widget.getInputValue())
46+
47 def test_call(self):
48 # The __call__ method sets up the widgets.
49 markup = self.widget()
50diff --git a/lib/lp/code/model/gitcollection.py b/lib/lp/code/model/gitcollection.py
51index eef06f6..f9466a9 100644
52--- a/lib/lp/code/model/gitcollection.py
53+++ b/lib/lp/code/model/gitcollection.py
54@@ -544,7 +544,8 @@ class GenericGitCollection:
55 path = URI(term).path.strip("/")
56 except InvalidURIError:
57 path = term
58- return getUtility(IGitLookup).getByUniqueName(path)
59+ result = getUtility(IGitLookup).getByPath(path)
60+ return result[0]
61
62 def search(self, term):
63 """See `IGitCollection`."""

Subscribers

People subscribed via source and target branches

to status/vote changes: