Merge lp:~cjwatson/launchpad/codeimport-create-hosting into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18232
Proposed branch: lp:~cjwatson/launchpad/codeimport-create-hosting
Merge into: lp:launchpad
Prerequisite: lp:~cjwatson/launchpad/codeimport-worker-refactor
Diff against target: 206 lines (+35/-8)
6 files modified
lib/lp/code/mail/tests/test_codeimport.py (+2/-0)
lib/lp/code/model/codeimport.py (+3/-0)
lib/lp/code/model/tests/test_codeimport.py (+24/-5)
lib/lp/code/model/tests/test_codeimportjob.py (+2/-0)
lib/lp/code/tests/helpers.py (+1/-0)
lib/lp/snappy/browser/tests/test_hassnaps.py (+3/-3)
To merge this branch: bzr merge lp:~cjwatson/launchpad/codeimport-create-hosting
Reviewer Review Type Date Requested Status
William Grant (community) code Approve
Review via email: mp+308132@code.launchpad.net

Commit message

Create repository on hosting service when creating a Git-targeted code import.

Description of the change

This is normally done by the XML-RPC endpoint that calls IGitNamespace.createRepository, but code import creation doesn't go through that.

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
1=== modified file 'lib/lp/code/mail/tests/test_codeimport.py'
2--- lib/lp/code/mail/tests/test_codeimport.py 2016-10-03 17:00:56 +0000
3+++ lib/lp/code/mail/tests/test_codeimport.py 2016-10-12 12:51:40 +0000
4@@ -11,6 +11,7 @@
5 RevisionControlSystems,
6 TargetRevisionControlSystems,
7 )
8+from lp.code.tests.helpers import GitHostingFixture
9 from lp.services.mail import stub
10 from lp.testing import (
11 login_person,
12@@ -95,6 +96,7 @@
13
14 def test_git_to_git_import(self):
15 # Test the email for a new git-to-git import.
16+ self.useFixture(GitHostingFixture())
17 eric = self.factory.makePerson(name='eric')
18 fooix = self.factory.makeProduct(name='fooix')
19 # Eric needs to be logged in for the mail to be sent.
20
21=== modified file 'lib/lp/code/model/codeimport.py'
22--- lib/lp/code/model/codeimport.py 2016-10-03 17:00:56 +0000
23+++ lib/lp/code/model/codeimport.py 2016-10-12 12:51:40 +0000
24@@ -59,6 +59,7 @@
25 )
26 from lp.code.interfaces.codeimportevent import ICodeImportEventSet
27 from lp.code.interfaces.codeimportjob import ICodeImportJobWorkflow
28+from lp.code.interfaces.githosting import IGitHostingClient
29 from lp.code.interfaces.gitnamespace import get_git_namespace
30 from lp.code.interfaces.gitrepository import IGitRepository
31 from lp.code.mail.codeimport import code_import_updated
32@@ -308,6 +309,8 @@
33 import_target = namespace.createRepository(
34 repository_type=GitRepositoryType.IMPORTED, name=branch_name,
35 registrant=registrant)
36+ hosting_path = import_target.getInternalPath()
37+ getUtility(IGitHostingClient).create(hosting_path)
38
39 code_import = CodeImport(
40 registrant=registrant, owner=owner, target=import_target,
41
42=== modified file 'lib/lp/code/model/tests/test_codeimport.py'
43--- lib/lp/code/model/tests/test_codeimport.py 2016-10-03 17:00:56 +0000
44+++ lib/lp/code/model/tests/test_codeimport.py 2016-10-12 12:51:40 +0000
45@@ -43,6 +43,7 @@
46 )
47 from lp.code.model.codeimportresult import CodeImportResult
48 from lp.code.tests.codeimporthelpers import make_running_import
49+from lp.code.tests.helpers import GitHostingFixture
50 from lp.registry.interfaces.person import IPersonSet
51 from lp.testing import (
52 login,
53@@ -66,15 +67,22 @@
54 "supports_source_cvs": True,
55 "supports_source_svn": True,
56 "supports_source_bzr": True,
57+ "needs_git_hosting_fixture": False,
58 }),
59 ("GitRepository", {
60 "target_rcs_type": TargetRevisionControlSystems.GIT,
61 "supports_source_cvs": False,
62 "supports_source_svn": False,
63 "supports_source_bzr": False,
64+ "needs_git_hosting_fixture": True,
65 }),
66 ]
67
68+ def setUp(self, *args, **kwargs):
69+ super(TestCodeImportBase, self).setUp(*args, **kwargs)
70+ if self.needs_git_hosting_fixture:
71+ self.hosting_fixture = self.useFixture(GitHostingFixture())
72+
73
74 class TestCodeImportCreation(TestCodeImportBase):
75 """Test the creation of CodeImports."""
76@@ -159,6 +167,11 @@
77 code_import.review_status)
78 # A job is created for the import.
79 self.assertIsNot(None, code_import.import_job)
80+ if self.needs_git_hosting_fixture:
81+ # The repository is created on the hosting service.
82+ self.assertEqual(
83+ (code_import.git_repository.getInternalPath(),),
84+ self.hosting_fixture.create.extract_args()[0])
85
86 def test_git_import_reviewed(self):
87 """A new git import is always reviewed by default."""
88@@ -175,6 +188,11 @@
89 code_import.review_status)
90 # A job is created for the import.
91 self.assertIsNot(None, code_import.import_job)
92+ if self.needs_git_hosting_fixture:
93+ # The repository is created on the hosting service.
94+ self.assertEqual(
95+ (code_import.git_repository.getInternalPath(),),
96+ self.hosting_fixture.create.extract_args()[0])
97
98 def test_bzr_import_reviewed(self):
99 """A new bzr import is always reviewed by default."""
100@@ -352,7 +370,8 @@
101
102 def setUp(self):
103 # Log in a VCS Imports member.
104- TestCaseWithFactory.setUp(self, 'david.allouche@canonical.com')
105+ super(TestCodeImportStatusUpdate, self).setUp(
106+ 'david.allouche@canonical.com')
107 self.import_operator = getUtility(IPersonSet).getByEmail(
108 'david.allouche@canonical.com')
109 # Remove existing jobs.
110@@ -484,7 +503,7 @@
111 layer = LaunchpadFunctionalLayer
112
113 def setUp(self):
114- TestCaseWithFactory.setUp(self)
115+ super(TestCodeImportResultsAttribute, self).setUp()
116 self.code_import = self.factory.makeCodeImport(
117 target_rcs_type=self.target_rcs_type)
118
119@@ -550,7 +569,7 @@
120 layer = LaunchpadZopelessLayer
121
122 def setUp(self):
123- TestCaseWithFactory.setUp(self)
124+ super(TestConsecutiveFailureCount, self).setUp()
125 login('no-priv@canonical.com')
126 self.machine = self.factory.makeCodeImportMachine()
127 self.machine.setOnline()
128@@ -692,7 +711,7 @@
129
130 def setUp(self):
131 # Log in a VCS Imports member.
132- TestCaseWithFactory.setUp(self)
133+ super(TestTryFailingImportAgain, self).setUp()
134 login_person(getUtility(ILaunchpadCelebrities).vcs_imports.teamowner)
135
136 def test_mustBeFailing(self):
137@@ -751,7 +770,7 @@
138
139 def setUp(self):
140 # We have to be logged in to request imports
141- TestCaseWithFactory.setUp(self, user='no-priv@canonical.com')
142+ super(TestRequestImport, self).setUp(user='no-priv@canonical.com')
143
144 def test_requestsJob(self):
145 code_import = self.factory.makeCodeImport(
146
147=== modified file 'lib/lp/code/model/tests/test_codeimportjob.py'
148--- lib/lp/code/model/tests/test_codeimportjob.py 2016-10-12 12:09:44 +0000
149+++ lib/lp/code/model/tests/test_codeimportjob.py 2016-10-12 12:51:40 +0000
150@@ -43,6 +43,7 @@
151 make_finished_import,
152 make_running_import,
153 )
154+from lp.code.tests.helpers import GitHostingFixture
155 from lp.services.config import config
156 from lp.services.database.constants import UTC_NOW
157 from lp.services.librarian.interfaces import ILibraryFileAliasSet
158@@ -1160,6 +1161,7 @@
159 super(TestCodeImportJobMacaroonIssuer, self).setUp()
160 login_for_code_imports()
161 self.pushConfig("codeimport", macaroon_secret_key="some-secret")
162+ self.useFixture(GitHostingFixture())
163
164 def makeJob(self, target_rcs_type=TargetRevisionControlSystems.GIT):
165 code_import = self.factory.makeCodeImport(
166
167=== modified file 'lib/lp/code/tests/helpers.py'
168--- lib/lp/code/tests/helpers.py 2016-09-07 03:43:36 +0000
169+++ lib/lp/code/tests/helpers.py 2016-10-12 12:51:40 +0000
170@@ -7,6 +7,7 @@
171 __all__ = [
172 'add_revision_to_branch',
173 'get_non_existant_source_package_branch_unique_name',
174+ 'GitHostingFixture',
175 'make_erics_fooix_project',
176 'make_linked_package_branch',
177 'make_merge_proposal_without_reviewers',
178
179=== modified file 'lib/lp/snappy/browser/tests/test_hassnaps.py'
180--- lib/lp/snappy/browser/tests/test_hassnaps.py 2016-09-07 11:12:58 +0000
181+++ lib/lp/snappy/browser/tests/test_hassnaps.py 2016-10-12 12:51:40 +0000
182@@ -93,7 +93,7 @@
183
184 layer = DatabaseFunctionalLayer
185
186- needs_hosting_fixture = False
187+ needs_git_hosting_fixture = False
188
189 scenarios = [
190 ("Branch", {
191@@ -101,13 +101,13 @@
192 }),
193 ("GitRef", {
194 "context_factory": make_git_ref,
195- "needs_hosting_fixture": True,
196+ "needs_git_hosting_fixture": True,
197 }),
198 ]
199
200 def setUp(self):
201 super(TestHasSnapsMenu, self).setUp()
202- if self.needs_hosting_fixture:
203+ if self.needs_git_hosting_fixture:
204 self.useFixture(GitHostingFixture())
205
206 def makeSnap(self, context):