Merge lp:~cjwatson/launchpad/git-testing into lp:launchpad
- git-testing
- Merge into devel
Proposed by
Colin Watson
Status: | Merged |
---|---|
Approved by: | Colin Watson |
Approved revision: | no longer in the source branch. |
Merged at revision: | 17356 |
Proposed branch: | lp:~cjwatson/launchpad/git-testing |
Merge into: | lp:launchpad |
Prerequisite: | lp:~cjwatson/launchpad/git-sharing |
Diff against target: |
457 lines (+427/-1) 2 files modified
lib/lp/code/model/tests/test_gitrepository.py (+394/-0) lib/lp/testing/factory.py (+33/-1) |
To merge this branch: | bzr merge lp:~cjwatson/launchpad/git-testing |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
William Grant | code | Approve | |
Review via email:
|
Commit message
Add initial Git repository testing support, and a first batch of tests for GitRepository itself.
Description of the change
Add initial Git repository testing support, and a first batch of tests for GitRepository itself.
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
William Grant (wgrant) : | # |
review:
Approve
(code)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file 'lib/lp/code/model/tests/test_gitrepository.py' | |||
2 | --- lib/lp/code/model/tests/test_gitrepository.py 1970-01-01 00:00:00 +0000 | |||
3 | +++ lib/lp/code/model/tests/test_gitrepository.py 2015-02-20 00:57:45 +0000 | |||
4 | @@ -0,0 +1,394 @@ | |||
5 | 1 | # Copyright 2015 Canonical Ltd. This software is licensed under the | ||
6 | 2 | # GNU Affero General Public License version 3 (see the file LICENSE). | ||
7 | 3 | |||
8 | 4 | """Tests for Git repositories.""" | ||
9 | 5 | |||
10 | 6 | __metaclass__ = type | ||
11 | 7 | |||
12 | 8 | from datetime import datetime | ||
13 | 9 | |||
14 | 10 | from lazr.lifecycle.event import ObjectModifiedEvent | ||
15 | 11 | import pytz | ||
16 | 12 | from zope.component import getUtility | ||
17 | 13 | from zope.event import notify | ||
18 | 14 | from zope.security.proxy import removeSecurityProxy | ||
19 | 15 | |||
20 | 16 | from lp.app.enums import ( | ||
21 | 17 | InformationType, | ||
22 | 18 | PRIVATE_INFORMATION_TYPES, | ||
23 | 19 | PUBLIC_INFORMATION_TYPES, | ||
24 | 20 | ) | ||
25 | 21 | from lp.app.interfaces.launchpad import ILaunchpadCelebrities | ||
26 | 22 | from lp.code.errors import ( | ||
27 | 23 | GitRepositoryCreatorNotMemberOfOwnerTeam, | ||
28 | 24 | GitRepositoryCreatorNotOwner, | ||
29 | 25 | GitTargetError, | ||
30 | 26 | ) | ||
31 | 27 | from lp.code.interfaces.gitnamespace import ( | ||
32 | 28 | IGitNamespacePolicy, | ||
33 | 29 | IGitNamespaceSet, | ||
34 | 30 | ) | ||
35 | 31 | from lp.code.interfaces.gitrepository import IGitRepository | ||
36 | 32 | from lp.registry.enums import BranchSharingPolicy | ||
37 | 33 | from lp.services.database.constants import UTC_NOW | ||
38 | 34 | from lp.services.webapp.authorization import check_permission | ||
39 | 35 | from lp.testing import ( | ||
40 | 36 | admin_logged_in, | ||
41 | 37 | celebrity_logged_in, | ||
42 | 38 | person_logged_in, | ||
43 | 39 | TestCaseWithFactory, | ||
44 | 40 | verifyObject, | ||
45 | 41 | ) | ||
46 | 42 | from lp.testing.layers import DatabaseFunctionalLayer | ||
47 | 43 | |||
48 | 44 | |||
49 | 45 | class TestGitRepository(TestCaseWithFactory): | ||
50 | 46 | """Test basic properties about Launchpad database Git repositories.""" | ||
51 | 47 | |||
52 | 48 | layer = DatabaseFunctionalLayer | ||
53 | 49 | |||
54 | 50 | def test_implements_IGitRepository(self): | ||
55 | 51 | repository = self.factory.makeGitRepository() | ||
56 | 52 | verifyObject(IGitRepository, repository) | ||
57 | 53 | |||
58 | 54 | def test_unique_name_project(self): | ||
59 | 55 | project = self.factory.makeProduct() | ||
60 | 56 | repository = self.factory.makeGitRepository(target=project) | ||
61 | 57 | self.assertEqual( | ||
62 | 58 | "~%s/%s/+git/%s" % ( | ||
63 | 59 | repository.owner.name, project.name, repository.name), | ||
64 | 60 | repository.unique_name) | ||
65 | 61 | |||
66 | 62 | def test_unique_name_package(self): | ||
67 | 63 | dsp = self.factory.makeDistributionSourcePackage() | ||
68 | 64 | repository = self.factory.makeGitRepository(target=dsp) | ||
69 | 65 | self.assertEqual( | ||
70 | 66 | "~%s/%s/+source/%s/+git/%s" % ( | ||
71 | 67 | repository.owner.name, dsp.distribution.name, | ||
72 | 68 | dsp.sourcepackagename.name, repository.name), | ||
73 | 69 | repository.unique_name) | ||
74 | 70 | |||
75 | 71 | def test_unique_name_personal(self): | ||
76 | 72 | owner = self.factory.makePerson() | ||
77 | 73 | repository = self.factory.makeGitRepository(owner=owner, target=owner) | ||
78 | 74 | self.assertEqual( | ||
79 | 75 | "~%s/+git/%s" % (owner.name, repository.name), | ||
80 | 76 | repository.unique_name) | ||
81 | 77 | |||
82 | 78 | def test_target_project(self): | ||
83 | 79 | project = self.factory.makeProduct() | ||
84 | 80 | repository = self.factory.makeGitRepository(target=project) | ||
85 | 81 | self.assertEqual(project, repository.target) | ||
86 | 82 | |||
87 | 83 | def test_target_package(self): | ||
88 | 84 | dsp = self.factory.makeDistributionSourcePackage() | ||
89 | 85 | repository = self.factory.makeGitRepository(target=dsp) | ||
90 | 86 | self.assertEqual(dsp, repository.target) | ||
91 | 87 | |||
92 | 88 | def test_target_personal(self): | ||
93 | 89 | owner = self.factory.makePerson() | ||
94 | 90 | repository = self.factory.makeGitRepository(owner=owner, target=owner) | ||
95 | 91 | self.assertEqual(owner, repository.target) | ||
96 | 92 | |||
97 | 93 | |||
98 | 94 | class TestGitIdentityMixin(TestCaseWithFactory): | ||
99 | 95 | """Test the defaults and identities provided by GitIdentityMixin.""" | ||
100 | 96 | |||
101 | 97 | layer = DatabaseFunctionalLayer | ||
102 | 98 | |||
103 | 99 | def assertGitIdentity(self, repository, identity_path): | ||
104 | 100 | """Assert that the Git identity of 'repository' is 'identity_path'. | ||
105 | 101 | |||
106 | 102 | Actually, it'll be lp:<identity_path>. | ||
107 | 103 | """ | ||
108 | 104 | self.assertEqual( | ||
109 | 105 | identity_path, repository.shortened_path, "shortened path") | ||
110 | 106 | self.assertEqual( | ||
111 | 107 | "lp:%s" % identity_path, repository.git_identity, "git identity") | ||
112 | 108 | |||
113 | 109 | def test_git_identity_default(self): | ||
114 | 110 | # By default, the Git identity is the repository's unique name. | ||
115 | 111 | repository = self.factory.makeGitRepository() | ||
116 | 112 | self.assertGitIdentity(repository, repository.unique_name) | ||
117 | 113 | |||
118 | 114 | def test_identities_no_defaults(self): | ||
119 | 115 | # If there are no defaults, the only repository identity is the | ||
120 | 116 | # unique name. | ||
121 | 117 | repository = self.factory.makeGitRepository() | ||
122 | 118 | self.assertEqual( | ||
123 | 119 | [(repository.unique_name, repository)], | ||
124 | 120 | repository.getRepositoryIdentities()) | ||
125 | 121 | |||
126 | 122 | # XXX cjwatson 2015-02-12: This will need to be expanded once support | ||
127 | 123 | # for default repositories is in place. | ||
128 | 124 | |||
129 | 125 | |||
130 | 126 | class TestGitRepositoryDateLastModified(TestCaseWithFactory): | ||
131 | 127 | """Exercise the situations where date_last_modified is updated.""" | ||
132 | 128 | |||
133 | 129 | layer = DatabaseFunctionalLayer | ||
134 | 130 | |||
135 | 131 | def test_initial_value(self): | ||
136 | 132 | # The initial value of date_last_modified is date_created. | ||
137 | 133 | repository = self.factory.makeGitRepository() | ||
138 | 134 | self.assertEqual( | ||
139 | 135 | repository.date_created, repository.date_last_modified) | ||
140 | 136 | |||
141 | 137 | def test_modifiedevent_sets_date_last_modified(self): | ||
142 | 138 | # When a GitRepository receives an object modified event, the last | ||
143 | 139 | # modified date is set to UTC_NOW. | ||
144 | 140 | repository = self.factory.makeGitRepository( | ||
145 | 141 | date_created=datetime(2015, 02, 04, 17, 42, 0, tzinfo=pytz.UTC)) | ||
146 | 142 | notify(ObjectModifiedEvent( | ||
147 | 143 | removeSecurityProxy(repository), repository, | ||
148 | 144 | [IGitRepository["name"]])) | ||
149 | 145 | self.assertSqlAttributeEqualsDate( | ||
150 | 146 | repository, "date_last_modified", UTC_NOW) | ||
151 | 147 | |||
152 | 148 | # XXX cjwatson 2015-02-04: This will need to be expanded once Launchpad | ||
153 | 149 | # actually notices any interesting kind of repository modifications. | ||
154 | 150 | |||
155 | 151 | |||
156 | 152 | class TestCodebrowse(TestCaseWithFactory): | ||
157 | 153 | """Tests for Git repository codebrowse support.""" | ||
158 | 154 | |||
159 | 155 | layer = DatabaseFunctionalLayer | ||
160 | 156 | |||
161 | 157 | def test_simple(self): | ||
162 | 158 | # The basic codebrowse URL for a repository is an 'https' URL. | ||
163 | 159 | repository = self.factory.makeGitRepository() | ||
164 | 160 | self.assertEqual( | ||
165 | 161 | "https://git.launchpad.dev/" + repository.unique_name, | ||
166 | 162 | repository.getCodebrowseUrl()) | ||
167 | 163 | |||
168 | 164 | |||
169 | 165 | class TestGitRepositoryNamespace(TestCaseWithFactory): | ||
170 | 166 | """Test `IGitRepository.namespace`.""" | ||
171 | 167 | |||
172 | 168 | layer = DatabaseFunctionalLayer | ||
173 | 169 | |||
174 | 170 | def test_namespace_personal(self): | ||
175 | 171 | # The namespace attribute of a personal repository points to the | ||
176 | 172 | # namespace that corresponds to ~owner. | ||
177 | 173 | owner = self.factory.makePerson() | ||
178 | 174 | repository = self.factory.makeGitRepository(owner=owner, target=owner) | ||
179 | 175 | namespace = getUtility(IGitNamespaceSet).get(person=owner) | ||
180 | 176 | self.assertEqual(namespace, repository.namespace) | ||
181 | 177 | |||
182 | 178 | def test_namespace_project(self): | ||
183 | 179 | # The namespace attribute of a project repository points to the | ||
184 | 180 | # namespace that corresponds to ~owner/project. | ||
185 | 181 | project = self.factory.makeProduct() | ||
186 | 182 | repository = self.factory.makeGitRepository(target=project) | ||
187 | 183 | namespace = getUtility(IGitNamespaceSet).get( | ||
188 | 184 | person=repository.owner, project=project) | ||
189 | 185 | self.assertEqual(namespace, repository.namespace) | ||
190 | 186 | |||
191 | 187 | def test_namespace_package(self): | ||
192 | 188 | # The namespace attribute of a package repository points to the | ||
193 | 189 | # namespace that corresponds to | ||
194 | 190 | # ~owner/distribution/+source/sourcepackagename. | ||
195 | 191 | dsp = self.factory.makeDistributionSourcePackage() | ||
196 | 192 | repository = self.factory.makeGitRepository(target=dsp) | ||
197 | 193 | namespace = getUtility(IGitNamespaceSet).get( | ||
198 | 194 | person=repository.owner, distribution=dsp.distribution, | ||
199 | 195 | sourcepackagename=dsp.sourcepackagename) | ||
200 | 196 | self.assertEqual(namespace, repository.namespace) | ||
201 | 197 | |||
202 | 198 | |||
203 | 199 | class TestGitRepositoryGetAllowedInformationTypes(TestCaseWithFactory): | ||
204 | 200 | """Test `IGitRepository.getAllowedInformationTypes`.""" | ||
205 | 201 | |||
206 | 202 | layer = DatabaseFunctionalLayer | ||
207 | 203 | |||
208 | 204 | def test_normal_user_sees_namespace_types(self): | ||
209 | 205 | # An unprivileged user sees the types allowed by the namespace. | ||
210 | 206 | repository = self.factory.makeGitRepository() | ||
211 | 207 | policy = IGitNamespacePolicy(repository.namespace) | ||
212 | 208 | self.assertContentEqual( | ||
213 | 209 | policy.getAllowedInformationTypes(), | ||
214 | 210 | repository.getAllowedInformationTypes(repository.owner)) | ||
215 | 211 | self.assertNotIn( | ||
216 | 212 | InformationType.PROPRIETARY, | ||
217 | 213 | repository.getAllowedInformationTypes(repository.owner)) | ||
218 | 214 | self.assertNotIn( | ||
219 | 215 | InformationType.EMBARGOED, | ||
220 | 216 | repository.getAllowedInformationTypes(repository.owner)) | ||
221 | 217 | |||
222 | 218 | def test_admin_sees_namespace_types(self): | ||
223 | 219 | # An admin sees all the types, since they occasionally need to | ||
224 | 220 | # override the namespace rules. This is hopefully temporary, and | ||
225 | 221 | # can go away once the new sharing rules (granting non-commercial | ||
226 | 222 | # projects limited use of private repositories) are deployed. | ||
227 | 223 | repository = self.factory.makeGitRepository() | ||
228 | 224 | admin = self.factory.makeAdministrator() | ||
229 | 225 | self.assertContentEqual( | ||
230 | 226 | PUBLIC_INFORMATION_TYPES + PRIVATE_INFORMATION_TYPES, | ||
231 | 227 | repository.getAllowedInformationTypes(admin)) | ||
232 | 228 | self.assertIn( | ||
233 | 229 | InformationType.PROPRIETARY, | ||
234 | 230 | repository.getAllowedInformationTypes(admin)) | ||
235 | 231 | |||
236 | 232 | |||
237 | 233 | class TestGitRepositoryModerate(TestCaseWithFactory): | ||
238 | 234 | """Test that project owners and commercial admins can moderate Git | ||
239 | 235 | repositories.""" | ||
240 | 236 | |||
241 | 237 | layer = DatabaseFunctionalLayer | ||
242 | 238 | |||
243 | 239 | def test_moderate_permission(self): | ||
244 | 240 | # Test the ModerateGitRepository security checker. | ||
245 | 241 | project = self.factory.makeProduct() | ||
246 | 242 | repository = self.factory.makeGitRepository(target=project) | ||
247 | 243 | with person_logged_in(project.owner): | ||
248 | 244 | self.assertTrue(check_permission("launchpad.Moderate", repository)) | ||
249 | 245 | with celebrity_logged_in("commercial_admin"): | ||
250 | 246 | self.assertTrue(check_permission("launchpad.Moderate", repository)) | ||
251 | 247 | with person_logged_in(self.factory.makePerson()): | ||
252 | 248 | self.assertFalse( | ||
253 | 249 | check_permission("launchpad.Moderate", repository)) | ||
254 | 250 | |||
255 | 251 | def test_attribute_smoketest(self): | ||
256 | 252 | # Users with launchpad.Moderate can set attributes. | ||
257 | 253 | project = self.factory.makeProduct() | ||
258 | 254 | repository = self.factory.makeGitRepository(target=project) | ||
259 | 255 | with person_logged_in(project.owner): | ||
260 | 256 | repository.name = u"not-secret" | ||
261 | 257 | self.assertEqual(u"not-secret", repository.name) | ||
262 | 258 | |||
263 | 259 | |||
264 | 260 | class TestGitRepositorySetOwner(TestCaseWithFactory): | ||
265 | 261 | """Test `IGitRepository.setOwner`.""" | ||
266 | 262 | |||
267 | 263 | layer = DatabaseFunctionalLayer | ||
268 | 264 | |||
269 | 265 | def test_owner_sets_team(self): | ||
270 | 266 | # The owner of the repository can set the owner of the repository to | ||
271 | 267 | # be a team they are a member of. | ||
272 | 268 | repository = self.factory.makeGitRepository() | ||
273 | 269 | team = self.factory.makeTeam(owner=repository.owner) | ||
274 | 270 | with person_logged_in(repository.owner): | ||
275 | 271 | repository.setOwner(team, repository.owner) | ||
276 | 272 | self.assertEqual(team, repository.owner) | ||
277 | 273 | |||
278 | 274 | def test_owner_cannot_set_nonmember_team(self): | ||
279 | 275 | # The owner of the repository cannot set the owner to be a team they | ||
280 | 276 | # are not a member of. | ||
281 | 277 | repository = self.factory.makeGitRepository() | ||
282 | 278 | team = self.factory.makeTeam() | ||
283 | 279 | with person_logged_in(repository.owner): | ||
284 | 280 | self.assertRaises( | ||
285 | 281 | GitRepositoryCreatorNotMemberOfOwnerTeam, | ||
286 | 282 | repository.setOwner, team, repository.owner) | ||
287 | 283 | |||
288 | 284 | def test_owner_cannot_set_other_user(self): | ||
289 | 285 | # The owner of the repository cannot set the new owner to be another | ||
290 | 286 | # person. | ||
291 | 287 | repository = self.factory.makeGitRepository() | ||
292 | 288 | person = self.factory.makePerson() | ||
293 | 289 | with person_logged_in(repository.owner): | ||
294 | 290 | self.assertRaises( | ||
295 | 291 | GitRepositoryCreatorNotOwner, | ||
296 | 292 | repository.setOwner, person, repository.owner) | ||
297 | 293 | |||
298 | 294 | def test_admin_can_set_any_team_or_person(self): | ||
299 | 295 | # A Launchpad admin can set the repository to be owned by any team | ||
300 | 296 | # or person. | ||
301 | 297 | repository = self.factory.makeGitRepository() | ||
302 | 298 | team = self.factory.makeTeam() | ||
303 | 299 | # To get a random administrator, choose the admin team owner. | ||
304 | 300 | admin = getUtility(ILaunchpadCelebrities).admin.teamowner | ||
305 | 301 | with person_logged_in(admin): | ||
306 | 302 | repository.setOwner(team, admin) | ||
307 | 303 | self.assertEqual(team, repository.owner) | ||
308 | 304 | person = self.factory.makePerson() | ||
309 | 305 | repository.setOwner(person, admin) | ||
310 | 306 | self.assertEqual(person, repository.owner) | ||
311 | 307 | |||
312 | 308 | |||
313 | 309 | class TestGitRepositorySetTarget(TestCaseWithFactory): | ||
314 | 310 | """Test `IGitRepository.setTarget`.""" | ||
315 | 311 | |||
316 | 312 | layer = DatabaseFunctionalLayer | ||
317 | 313 | |||
318 | 314 | def test_personal_to_project(self): | ||
319 | 315 | # A personal repository can be moved to a project. | ||
320 | 316 | owner = self.factory.makePerson() | ||
321 | 317 | repository = self.factory.makeGitRepository(owner=owner, target=owner) | ||
322 | 318 | project = self.factory.makeProduct() | ||
323 | 319 | with person_logged_in(owner): | ||
324 | 320 | repository.setTarget(target=project, user=owner) | ||
325 | 321 | self.assertEqual(project, repository.target) | ||
326 | 322 | |||
327 | 323 | def test_personal_to_package(self): | ||
328 | 324 | # A personal repository can be moved to a package. | ||
329 | 325 | owner = self.factory.makePerson() | ||
330 | 326 | repository = self.factory.makeGitRepository(owner=owner, target=owner) | ||
331 | 327 | dsp = self.factory.makeDistributionSourcePackage() | ||
332 | 328 | with person_logged_in(owner): | ||
333 | 329 | repository.setTarget(target=dsp, user=owner) | ||
334 | 330 | self.assertEqual(dsp, repository.target) | ||
335 | 331 | |||
336 | 332 | def test_project_to_other_project(self): | ||
337 | 333 | # Move a repository from one project to another. | ||
338 | 334 | repository = self.factory.makeGitRepository() | ||
339 | 335 | project = self.factory.makeProduct() | ||
340 | 336 | with person_logged_in(repository.owner): | ||
341 | 337 | repository.setTarget(target=project, user=repository.owner) | ||
342 | 338 | self.assertEqual(project, repository.target) | ||
343 | 339 | |||
344 | 340 | def test_project_to_package(self): | ||
345 | 341 | # Move a repository from a project to a package. | ||
346 | 342 | repository = self.factory.makeGitRepository() | ||
347 | 343 | dsp = self.factory.makeDistributionSourcePackage() | ||
348 | 344 | with person_logged_in(repository.owner): | ||
349 | 345 | repository.setTarget(target=dsp, user=repository.owner) | ||
350 | 346 | self.assertEqual(dsp, repository.target) | ||
351 | 347 | |||
352 | 348 | def test_project_to_personal(self): | ||
353 | 349 | # Move a repository from a project to a personal namespace. | ||
354 | 350 | owner = self.factory.makePerson() | ||
355 | 351 | repository = self.factory.makeGitRepository(owner=owner) | ||
356 | 352 | with person_logged_in(owner): | ||
357 | 353 | repository.setTarget(target=owner, user=owner) | ||
358 | 354 | self.assertEqual(owner, repository.target) | ||
359 | 355 | |||
360 | 356 | def test_package_to_other_package(self): | ||
361 | 357 | # Move a repository from one package to another. | ||
362 | 358 | repository = self.factory.makeGitRepository( | ||
363 | 359 | target=self.factory.makeDistributionSourcePackage()) | ||
364 | 360 | dsp = self.factory.makeDistributionSourcePackage() | ||
365 | 361 | with person_logged_in(repository.owner): | ||
366 | 362 | repository.setTarget(target=dsp, user=repository.owner) | ||
367 | 363 | self.assertEqual(dsp, repository.target) | ||
368 | 364 | |||
369 | 365 | def test_package_to_project(self): | ||
370 | 366 | # Move a repository from a package to a project. | ||
371 | 367 | repository = self.factory.makeGitRepository( | ||
372 | 368 | target=self.factory.makeDistributionSourcePackage()) | ||
373 | 369 | project = self.factory.makeProduct() | ||
374 | 370 | with person_logged_in(repository.owner): | ||
375 | 371 | repository.setTarget(target=project, user=repository.owner) | ||
376 | 372 | self.assertEqual(project, repository.target) | ||
377 | 373 | |||
378 | 374 | def test_package_to_personal(self): | ||
379 | 375 | # Move a repository from a package to a personal namespace. | ||
380 | 376 | owner = self.factory.makePerson() | ||
381 | 377 | repository = self.factory.makeGitRepository( | ||
382 | 378 | owner=owner, target=self.factory.makeDistributionSourcePackage()) | ||
383 | 379 | with person_logged_in(owner): | ||
384 | 380 | repository.setTarget(target=owner, user=owner) | ||
385 | 381 | self.assertEqual(owner, repository.target) | ||
386 | 382 | |||
387 | 383 | def test_public_to_proprietary_only_project(self): | ||
388 | 384 | # A repository cannot be moved to a target where the sharing policy | ||
389 | 385 | # does not allow it. | ||
390 | 386 | owner = self.factory.makePerson() | ||
391 | 387 | commercial_project = self.factory.makeProduct( | ||
392 | 388 | owner=owner, branch_sharing_policy=BranchSharingPolicy.PROPRIETARY) | ||
393 | 389 | repository = self.factory.makeGitRepository( | ||
394 | 390 | owner=owner, information_type=InformationType.PUBLIC) | ||
395 | 391 | with admin_logged_in(): | ||
396 | 392 | self.assertRaises( | ||
397 | 393 | GitTargetError, repository.setTarget, | ||
398 | 394 | target=commercial_project, user=owner) | ||
399 | 0 | 395 | ||
400 | === modified file 'lib/lp/testing/factory.py' | |||
401 | --- lib/lp/testing/factory.py 2015-01-29 16:28:30 +0000 | |||
402 | +++ lib/lp/testing/factory.py 2015-02-20 00:57:45 +0000 | |||
403 | @@ -2,7 +2,7 @@ | |||
404 | 2 | # NOTE: The first line above must stay first; do not move the copyright | 2 | # NOTE: The first line above must stay first; do not move the copyright |
405 | 3 | # notice to the top. See http://www.python.org/dev/peps/pep-0263/. | 3 | # notice to the top. See http://www.python.org/dev/peps/pep-0263/. |
406 | 4 | # | 4 | # |
408 | 5 | # Copyright 2009-2014 Canonical Ltd. This software is licensed under the | 5 | # Copyright 2009-2015 Canonical Ltd. This software is licensed under the |
409 | 6 | # GNU Affero General Public License version 3 (see the file LICENSE). | 6 | # GNU Affero General Public License version 3 (see the file LICENSE). |
410 | 7 | 7 | ||
411 | 8 | """Testing infrastructure for the Launchpad application. | 8 | """Testing infrastructure for the Launchpad application. |
412 | @@ -118,6 +118,7 @@ | |||
413 | 118 | from lp.code.interfaces.codeimportevent import ICodeImportEventSet | 118 | from lp.code.interfaces.codeimportevent import ICodeImportEventSet |
414 | 119 | from lp.code.interfaces.codeimportmachine import ICodeImportMachineSet | 119 | from lp.code.interfaces.codeimportmachine import ICodeImportMachineSet |
415 | 120 | from lp.code.interfaces.codeimportresult import ICodeImportResultSet | 120 | from lp.code.interfaces.codeimportresult import ICodeImportResultSet |
416 | 121 | from lp.code.interfaces.gitnamespace import get_git_namespace | ||
417 | 121 | from lp.code.interfaces.linkedbranch import ICanHasLinkedBranch | 122 | from lp.code.interfaces.linkedbranch import ICanHasLinkedBranch |
418 | 122 | from lp.code.interfaces.revision import IRevisionSet | 123 | from lp.code.interfaces.revision import IRevisionSet |
419 | 123 | from lp.code.interfaces.sourcepackagerecipe import ( | 124 | from lp.code.interfaces.sourcepackagerecipe import ( |
420 | @@ -1668,6 +1669,37 @@ | |||
421 | 1668 | revision_date=revision_date) | 1669 | revision_date=revision_date) |
422 | 1669 | return branch.createBranchRevision(sequence, revision) | 1670 | return branch.createBranchRevision(sequence, revision) |
423 | 1670 | 1671 | ||
424 | 1672 | def makeGitRepository(self, owner=None, target=_DEFAULT, registrant=None, | ||
425 | 1673 | name=None, information_type=None, | ||
426 | 1674 | **optional_repository_args): | ||
427 | 1675 | """Create and return a new, arbitrary GitRepository. | ||
428 | 1676 | |||
429 | 1677 | Any parameters for `IGitNamespace.createRepository` can be specified | ||
430 | 1678 | to override the default ones. | ||
431 | 1679 | """ | ||
432 | 1680 | if owner is None: | ||
433 | 1681 | owner = self.makePerson() | ||
434 | 1682 | if name is None: | ||
435 | 1683 | name = self.getUniqueString('gitrepository').decode('utf-8') | ||
436 | 1684 | |||
437 | 1685 | if target is _DEFAULT: | ||
438 | 1686 | target = self.makeProduct() | ||
439 | 1687 | |||
440 | 1688 | if registrant is None: | ||
441 | 1689 | if owner.is_team: | ||
442 | 1690 | registrant = removeSecurityProxy(owner).teamowner | ||
443 | 1691 | else: | ||
444 | 1692 | registrant = owner | ||
445 | 1693 | |||
446 | 1694 | namespace = get_git_namespace(target, owner) | ||
447 | 1695 | repository = namespace.createRepository( | ||
448 | 1696 | registrant=registrant, name=name, **optional_repository_args) | ||
449 | 1697 | naked_repository = removeSecurityProxy(repository) | ||
450 | 1698 | if information_type is not None: | ||
451 | 1699 | naked_repository.transitionToInformationType( | ||
452 | 1700 | information_type, registrant, verify_policy=False) | ||
453 | 1701 | return repository | ||
454 | 1702 | |||
455 | 1671 | def makeBug(self, target=None, owner=None, bug_watch_url=None, | 1703 | def makeBug(self, target=None, owner=None, bug_watch_url=None, |
456 | 1672 | information_type=None, date_closed=None, title=None, | 1704 | information_type=None, date_closed=None, title=None, |
457 | 1673 | date_created=None, description=None, comment=None, | 1705 | date_created=None, description=None, comment=None, |