8687.15.17
by Karl Fogel
Add the copyright header block to the rest of the files under lib/lp/. |
1 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
7349.1.2
by Jonathan Lange
Files I forgot to add |
3 |
|
4 |
"""Tests for ISeriesSourcePackageBranch."""
|
|
5 |
||
6 |
__metaclass__ = type |
|
7 |
||
8 |
from datetime import datetime |
|
9 |
import unittest |
|
10 |
||
11 |
import pytz |
|
12 |
import transaction |
|
13 |
from zope.component import getUtility |
|
7921.1.30
by Jonathan Lange
getBranchLink is gone. Remove it from the interface and move the security |
14 |
from zope.security.interfaces import Unauthorized |
7921.1.19
by Jonathan Lange
Fix the tests for the new security permissions. |
15 |
from zope.security.proxy import removeSecurityProxy |
7349.1.2
by Jonathan Lange
Files I forgot to add |
16 |
|
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
17 |
from canonical.launchpad.ftests import ( |
18 |
ANONYMOUS, |
|
19 |
login, |
|
20 |
login_person, |
|
21 |
logout, |
|
22 |
)
|
|
7921.1.19
by Jonathan Lange
Fix the tests for the new security permissions. |
23 |
from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities |
11666.3.5
by Curtis Hovey
Import layers from canonical.testing.layers. |
24 |
from canonical.testing.layers import DatabaseFunctionalLayer |
8138.1.2
by Jonathan Lange
Run migrater over lp.code. Many tests broken and imports failing. |
25 |
from lp.code.interfaces.seriessourcepackagebranch import ( |
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
26 |
IFindOfficialBranchLinks, |
27 |
IMakeOfficialBranchLinks, |
|
28 |
ISeriesSourcePackageBranch, |
|
29 |
)
|
|
9113.7.4
by Jonathan Lange
Update many imports of pocket. |
30 |
from lp.registry.interfaces.pocket import PackagePublishingPocket |
8440.1.2
by Curtis Hovey
Updated lp.testing imports. Removed the shim |
31 |
from lp.testing import TestCaseWithFactory |
7349.1.2
by Jonathan Lange
Files I forgot to add |
32 |
|
33 |
||
34 |
class TestSeriesSourcePackageBranch(TestCaseWithFactory): |
|
7921.1.1
by Jonathan Lange
Tweaks to copyright string and docstrings. |
35 |
"""Tests for `ISeriesSourcePackageBranch`."""
|
7349.1.2
by Jonathan Lange
Files I forgot to add |
36 |
|
37 |
layer = DatabaseFunctionalLayer |
|
38 |
||
7921.1.19
by Jonathan Lange
Fix the tests for the new security permissions. |
39 |
def setUp(self): |
40 |
TestCaseWithFactory.setUp(self) |
|
41 |
person = self.factory.makePerson() |
|
42 |
ubuntu_branches = getUtility(ILaunchpadCelebrities).ubuntu_branches |
|
43 |
removeSecurityProxy(ubuntu_branches).addMember( |
|
44 |
person, ubuntu_branches.teamowner) |
|
45 |
login_person(person) |
|
46 |
self.addCleanup(logout) |
|
47 |
||
7349.1.2
by Jonathan Lange
Files I forgot to add |
48 |
def test_new_sets_attributes(self): |
49 |
# ISeriesSourcePackageBranchSet.new sets all the defined attributes on
|
|
50 |
# the interface.
|
|
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
51 |
series_set = getUtility(IMakeOfficialBranchLinks) |
7349.1.2
by Jonathan Lange
Files I forgot to add |
52 |
distroseries = self.factory.makeDistroRelease() |
53 |
sourcepackagename = self.factory.makeSourcePackageName() |
|
54 |
registrant = self.factory.makePerson() |
|
7362.12.24
by Jonathan Lange
Restore change that somehow got lost. |
55 |
branch = self.factory.makeAnyBranch() |
7349.1.2
by Jonathan Lange
Files I forgot to add |
56 |
now = datetime.now(pytz.UTC) |
57 |
sspb = series_set.new( |
|
58 |
distroseries, PackagePublishingPocket.RELEASE, sourcepackagename, |
|
59 |
branch, registrant, now) |
|
60 |
self.assertEqual(distroseries, sspb.distroseries) |
|
61 |
self.assertEqual(PackagePublishingPocket.RELEASE, sspb.pocket) |
|
62 |
self.assertEqual(sourcepackagename, sspb.sourcepackagename) |
|
63 |
self.assertEqual(branch, sspb.branch) |
|
64 |
self.assertEqual(registrant, sspb.registrant) |
|
65 |
self.assertEqual(now, sspb.date_created) |
|
66 |
||
67 |
def test_new_inserts_into_db(self): |
|
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
68 |
# IMakeOfficialBranchLinks.new inserts the new object into the
|
7349.1.2
by Jonathan Lange
Files I forgot to add |
69 |
# database, giving it an ID.
|
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
70 |
series_set = getUtility(IMakeOfficialBranchLinks) |
7349.1.2
by Jonathan Lange
Files I forgot to add |
71 |
distroseries = self.factory.makeDistroRelease() |
72 |
sourcepackagename = self.factory.makeSourcePackageName() |
|
73 |
registrant = self.factory.makePerson() |
|
7362.12.24
by Jonathan Lange
Restore change that somehow got lost. |
74 |
branch = self.factory.makeAnyBranch() |
7349.1.2
by Jonathan Lange
Files I forgot to add |
75 |
sspb = series_set.new( |
76 |
distroseries, PackagePublishingPocket.RELEASE, sourcepackagename, |
|
77 |
branch, registrant) |
|
78 |
transaction.commit() |
|
79 |
self.assertIsNot(sspb.id, None) |
|
80 |
||
81 |
def test_new_returns_ISeriesSourcePackageBranch(self): |
|
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
82 |
# IMakeOfficialBranchLinks.new returns an
|
7349.1.2
by Jonathan Lange
Files I forgot to add |
83 |
# ISeriesSourcePackageBranch, know what I mean?
|
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
84 |
series_set = getUtility(IMakeOfficialBranchLinks) |
7349.1.2
by Jonathan Lange
Files I forgot to add |
85 |
distroseries = self.factory.makeDistroRelease() |
86 |
sourcepackagename = self.factory.makeSourcePackageName() |
|
87 |
registrant = self.factory.makePerson() |
|
7362.12.24
by Jonathan Lange
Restore change that somehow got lost. |
88 |
branch = self.factory.makeAnyBranch() |
7349.1.2
by Jonathan Lange
Files I forgot to add |
89 |
sspb = series_set.new( |
90 |
distroseries, PackagePublishingPocket.RELEASE, sourcepackagename, |
|
91 |
branch, registrant) |
|
92 |
self.assertProvides(sspb, ISeriesSourcePackageBranch) |
|
93 |
||
8211.4.8
by Jonathan Lange
Rename getLinks to findForSourcePackage. |
94 |
def test_findForSourcePackage(self): |
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
95 |
# IFindOfficialBranchLinks.findForSourcePackage returns an empty
|
8211.4.8
by Jonathan Lange
Rename getLinks to findForSourcePackage. |
96 |
# result set if there are no links from that source package.
|
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
97 |
series_set = getUtility(IFindOfficialBranchLinks) |
8211.4.4
by Jonathan Lange
Add a method for getting the links to branches from a source package. |
98 |
package = self.factory.makeSourcePackage() |
8211.4.8
by Jonathan Lange
Rename getLinks to findForSourcePackage. |
99 |
self.assertEqual([], list(series_set.findForSourcePackage(package))) |
8211.4.4
by Jonathan Lange
Add a method for getting the links to branches from a source package. |
100 |
|
8211.4.8
by Jonathan Lange
Rename getLinks to findForSourcePackage. |
101 |
def test_findForSourcePackage_non_empty(self): |
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
102 |
# IFindOfficialBranchLinks.findForSourcePackage returns a result
|
8211.4.9
by Jonathan Lange
Add a findForBranch method. |
103 |
# set of links from the source package. Each link is an
|
8211.4.8
by Jonathan Lange
Rename getLinks to findForSourcePackage. |
104 |
# ISeriesSourcePackageBranch.
|
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
105 |
make_branch_links = getUtility(IMakeOfficialBranchLinks) |
8211.4.5
by Jonathan Lange
Remove a link between a branch and a sourcepackage, pocket. |
106 |
branch = self.factory.makePackageBranch() |
107 |
package = branch.sourcepackage |
|
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
108 |
make_branch_links.new( |
8211.4.5
by Jonathan Lange
Remove a link between a branch and a sourcepackage, pocket. |
109 |
package.distroseries, PackagePublishingPocket.RELEASE, |
110 |
package.sourcepackagename, branch, self.factory.makePerson()) |
|
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
111 |
find_branch_links = getUtility(IFindOfficialBranchLinks) |
112 |
[link] = list(find_branch_links.findForSourcePackage(package)) |
|
8211.4.5
by Jonathan Lange
Remove a link between a branch and a sourcepackage, pocket. |
113 |
self.assertEqual(PackagePublishingPocket.RELEASE, link.pocket) |
114 |
self.assertEqual(branch, link.branch) |
|
115 |
self.assertEqual(link.distroseries, package.distroseries) |
|
116 |
self.assertEqual(link.sourcepackagename, package.sourcepackagename) |
|
117 |
||
8211.4.9
by Jonathan Lange
Add a findForBranch method. |
118 |
def test_findForBranch(self): |
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
119 |
# IFindOfficialBranchLinks.findForBranch returns a result set of
|
8211.4.9
by Jonathan Lange
Add a findForBranch method. |
120 |
# links from the branch to source packages & pockets. Each link is an
|
121 |
# ISeriesSourcePackageBranch.
|
|
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
122 |
make_branch_links = getUtility(IMakeOfficialBranchLinks) |
8211.4.9
by Jonathan Lange
Add a findForBranch method. |
123 |
branch = self.factory.makePackageBranch() |
124 |
package = branch.sourcepackage |
|
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
125 |
make_branch_links.new( |
8211.4.9
by Jonathan Lange
Add a findForBranch method. |
126 |
package.distroseries, PackagePublishingPocket.RELEASE, |
127 |
package.sourcepackagename, branch, self.factory.makePerson()) |
|
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
128 |
find_branch_links = getUtility(IFindOfficialBranchLinks) |
129 |
[link] = list(find_branch_links.findForBranch(branch)) |
|
8211.4.9
by Jonathan Lange
Add a findForBranch method. |
130 |
self.assertEqual(PackagePublishingPocket.RELEASE, link.pocket) |
131 |
self.assertEqual(branch, link.branch) |
|
132 |
self.assertEqual(link.distroseries, package.distroseries) |
|
133 |
self.assertEqual(link.sourcepackagename, package.sourcepackagename) |
|
134 |
||
8211.4.5
by Jonathan Lange
Remove a link between a branch and a sourcepackage, pocket. |
135 |
def test_delete(self): |
136 |
# `delete` ensures that there is no branch associated with that
|
|
137 |
# sourcepackage and pocket.
|
|
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
138 |
make_branch_links = getUtility(IMakeOfficialBranchLinks) |
8211.4.5
by Jonathan Lange
Remove a link between a branch and a sourcepackage, pocket. |
139 |
branch = self.factory.makePackageBranch() |
140 |
package = branch.sourcepackage |
|
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
141 |
make_branch_links.new( |
8211.4.5
by Jonathan Lange
Remove a link between a branch and a sourcepackage, pocket. |
142 |
package.distroseries, PackagePublishingPocket.RELEASE, |
143 |
package.sourcepackagename, branch, self.factory.makePerson()) |
|
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
144 |
make_branch_links.delete(package, PackagePublishingPocket.RELEASE) |
145 |
find_branch_links = getUtility(IFindOfficialBranchLinks) |
|
146 |
self.assertEqual( |
|
147 |
[], list(find_branch_links.findForSourcePackage(package))) |
|
8211.4.5
by Jonathan Lange
Remove a link between a branch and a sourcepackage, pocket. |
148 |
|
7921.1.30
by Jonathan Lange
getBranchLink is gone. Remove it from the interface and move the security |
149 |
def test_cannot_edit_branch_link(self): |
150 |
# You can only edit an ISeriesSourcePackageBranch if you have edit
|
|
151 |
# permissions, which almost no one has.
|
|
8211.4.14
by Jonathan Lange
Further split the interfaces, correct the permissions. |
152 |
series_set = getUtility(IMakeOfficialBranchLinks) |
7921.1.30
by Jonathan Lange
getBranchLink is gone. Remove it from the interface and move the security |
153 |
distroseries = self.factory.makeDistroRelease() |
154 |
sourcepackagename = self.factory.makeSourcePackageName() |
|
155 |
registrant = self.factory.makePerson() |
|
156 |
branch = self.factory.makeAnyBranch() |
|
157 |
sspb = series_set.new( |
|
158 |
distroseries, PackagePublishingPocket.RELEASE, sourcepackagename, |
|
159 |
branch, registrant) |
|
160 |
logout() |
|
161 |
login(ANONYMOUS) |
|
162 |
self.assertRaises( |
|
163 |
Unauthorized, setattr, sspb, 'pocket', |
|
164 |
PackagePublishingPocket.BACKPORTS) |
|
165 |
||
7349.1.2
by Jonathan Lange
Files I forgot to add |
166 |
|
167 |
def test_suite(): |
|
168 |
return unittest.TestLoader().loadTestsFromName(__name__) |
|
169 |