Merge lp:~cjwatson/launchpad/git-get-by-unique-name-oops into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18735
Proposed branch: lp:~cjwatson/launchpad/git-get-by-unique-name-oops
Merge into: lp:launchpad
Diff against target: 76 lines (+28/-3)
2 files modified
lib/lp/code/model/gitlookup.py (+2/-2)
lib/lp/code/model/tests/test_gitlookup.py (+26/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/git-get-by-unique-name-oops
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+350447@code.launchpad.net

Commit message

Fix OOPS when trying to look up ~user/project:branch as a unique Git repository name.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/model/gitlookup.py'
--- lib/lp/code/model/gitlookup.py 2015-07-09 12:18:51 +0000
+++ lib/lp/code/model/gitlookup.py 2018-07-23 11:05:21 +0000
@@ -1,4 +1,4 @@
1# Copyright 2015 Canonical Ltd. This software is licensed under the1# Copyright 2015-2018 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Database implementation of the Git repository lookup utility."""4"""Database implementation of the Git repository lookup utility."""
@@ -347,7 +347,7 @@
347 if repository is None or trailing or list(segments):347 if repository is None or trailing or list(segments):
348 raise InvalidNamespace(unique_name)348 raise InvalidNamespace(unique_name)
349 return repository349 return repository
350 except (InvalidNamespace, NameLookupFailed):350 except (InvalidNamespace, InvalidProductName, NameLookupFailed):
351 pass351 pass
352 return None352 return None
353353
354354
=== modified file 'lib/lp/code/model/tests/test_gitlookup.py'
--- lib/lp/code/model/tests/test_gitlookup.py 2017-10-04 01:29:35 +0000
+++ lib/lp/code/model/tests/test_gitlookup.py 2018-07-23 11:05:21 +0000
@@ -1,4 +1,4 @@
1# Copyright 2015-2017 Canonical Ltd. This software is licensed under the1# Copyright 2015-2018 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Tests for the IGitLookup implementation."""4"""Tests for the IGitLookup implementation."""
@@ -65,22 +65,47 @@
65 unused_name = self.factory.getUniqueString()65 unused_name = self.factory.getUniqueString()
66 self.assertIsNone(self.lookup.getByUniqueName(unused_name))66 self.assertIsNone(self.lookup.getByUniqueName(unused_name))
6767
68 def test_invalid_name(self):
69 # repository:branch forms are not valid as repository unique names.
70 # Provoke various failure modes depending on where the invalid
71 # component occurs in the traversal.
72 repository = self.factory.makeGitRepository()
73 self.assertIsNone(self.lookup.getByUniqueName(
74 repository.unique_name + ":branch-name"))
75 with person_logged_in(repository.owner):
76 getUtility(IGitRepositorySet).setDefaultRepositoryForOwner(
77 repository.owner, repository.target, repository,
78 repository.owner)
79 self.assertIsNone(self.lookup.getByUniqueName(
80 repository.shortened_path + ":branch-name"))
81 with person_logged_in(repository.target.owner):
82 getUtility(IGitRepositorySet).setDefaultRepository(
83 repository.target, repository)
84 self.assertIsNone(self.lookup.getByUniqueName(
85 repository.shortened_path + ":branch-name"))
86
68 def test_project(self):87 def test_project(self):
69 repository = self.factory.makeGitRepository()88 repository = self.factory.makeGitRepository()
70 self.assertEqual(89 self.assertEqual(
71 repository, self.lookup.getByUniqueName(repository.unique_name))90 repository, self.lookup.getByUniqueName(repository.unique_name))
91 self.assertIsNone(self.lookup.getByUniqueName(
92 repository.unique_name + "-nonexistent"))
7293
73 def test_package(self):94 def test_package(self):
74 dsp = self.factory.makeDistributionSourcePackage()95 dsp = self.factory.makeDistributionSourcePackage()
75 repository = self.factory.makeGitRepository(target=dsp)96 repository = self.factory.makeGitRepository(target=dsp)
76 self.assertEqual(97 self.assertEqual(
77 repository, self.lookup.getByUniqueName(repository.unique_name))98 repository, self.lookup.getByUniqueName(repository.unique_name))
99 self.assertIsNone(self.lookup.getByUniqueName(
100 repository.unique_name + "-nonexistent"))
78101
79 def test_personal(self):102 def test_personal(self):
80 owner = self.factory.makePerson()103 owner = self.factory.makePerson()
81 repository = self.factory.makeGitRepository(owner=owner, target=owner)104 repository = self.factory.makeGitRepository(owner=owner, target=owner)
82 self.assertEqual(105 self.assertEqual(
83 repository, self.lookup.getByUniqueName(repository.unique_name))106 repository, self.lookup.getByUniqueName(repository.unique_name))
107 self.assertIsNone(self.lookup.getByUniqueName(
108 repository.unique_name + "-nonexistent"))
84109
85110
86class TestGetByPath(TestCaseWithFactory):111class TestGetByPath(TestCaseWithFactory):