1
1
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
from doctest import DocTestSuite
8
return DocTestSuite('lp.bugs.mail.commands')
4
from canonical.testing.layers import DatabaseFunctionalLayer
5
from lp.bugs.mail.commands import (
8
from lp.services.mail.interfaces import BugTargetNotFound
9
from lp.testing import (
16
class AffectsEmailCommandTestCase(TestCaseWithFactory):
18
layer = DatabaseFunctionalLayer
20
def test__splitPath_with_slashes(self):
22
('foo', 'bar/baz'), AffectsEmailCommand._splitPath('foo/bar/baz'))
24
def test__splitPath_no_slashes(self):
26
('foo', ''), AffectsEmailCommand._splitPath('foo'))
28
def test__normalizePath_leading_slash(self):
30
'foo/bar', AffectsEmailCommand._normalizePath('/foo/bar'))
32
def test__normalizePath_distros(self):
34
'foo/bar', AffectsEmailCommand._normalizePath('/distros/foo/bar'))
36
def test__normalizePath_products(self):
39
AffectsEmailCommand._normalizePath('/products/foo/bar'))
41
def test_getBugTarget_no_pillar_error(self):
42
message = "There is no project named 'fnord' registered in Launchpad."
43
self.assertRaisesWithContent(
44
BugTargetNotFound, message,
45
AffectsEmailCommand.getBugTarget, 'fnord')
47
def test_getBugTarget_project_group_error(self):
48
owner = self.factory.makePerson()
50
project_group = self.factory.makeProject(name='fnord', owner=owner)
51
project_1 = self.factory.makeProduct(name='pting', owner=owner)
52
project_1.project = project_group
53
project_2 = self.factory.makeProduct(name='snarf', owner=owner)
54
project_2.project = project_group
56
"fnord is a group of projects. To report a bug, you need to "
57
"specify which of these projects the bug applies to: "
59
self.assertRaisesWithContent(
60
BugTargetNotFound, message,
61
AffectsEmailCommand.getBugTarget, 'fnord')
63
def test_getBugTarget_deactivated_project_error(self):
64
project = self.factory.makeProduct(name='fnord')
65
login_celebrity('admin')
66
project.active = False
67
message = "There is no project named 'fnord' registered in Launchpad."
68
self.assertRaisesWithContent(
69
BugTargetNotFound, message,
70
AffectsEmailCommand.getBugTarget, 'fnord')
72
def test_getBugTarget_project(self):
73
project = self.factory.makeProduct(name='fnord')
74
self.assertEqual(project, AffectsEmailCommand.getBugTarget('fnord'))
76
def test_getBugTarget_no_project_series_error(self):
77
self.factory.makeProduct(name='fnord')
78
message = "Fnord doesn't have a series named 'pting'."
79
self.assertRaisesWithContent(
80
BugTargetNotFound, message,
81
AffectsEmailCommand.getBugTarget, 'fnord/pting')
83
def test_getBugTarget_project_series(self):
84
project = self.factory.makeProduct(name='fnord')
85
series = self.factory.makeProductSeries(name='pting', product=project)
87
series, AffectsEmailCommand.getBugTarget('fnord/pting'))
89
def test_getBugTarget_product_extra_path_error(self):
90
product = self.factory.makeProduct(name='fnord')
91
self.factory.makeProductSeries(name='pting', product=product)
92
message = "Unexpected path components: snarf"
93
self.assertRaisesWithContent(
94
BugTargetNotFound, message,
95
AffectsEmailCommand.getBugTarget, 'fnord/pting/snarf')
97
def test_getBugTarget_no_series_or_package_error(self):
98
self.factory.makeDistribution(name='fnord')
100
"Fnord doesn't have a series or source package named 'pting'.")
101
self.assertRaisesWithContent(
102
BugTargetNotFound, message,
103
AffectsEmailCommand.getBugTarget, 'fnord/pting')
105
def test_getBugTarget_distribution(self):
106
distribution = self.factory.makeDistribution(name='fnord')
108
distribution, AffectsEmailCommand.getBugTarget('fnord'))
110
def test_getBugTarget_distroseries(self):
111
distribution = self.factory.makeDistribution(name='fnord')
112
series = self.factory.makeDistroSeries(
113
name='pting', distribution=distribution)
115
series, AffectsEmailCommand.getBugTarget('fnord/pting'))
117
def test_getBugTarget_source_package(self):
118
distribution = self.factory.makeDistribution(name='fnord')
119
series = self.factory.makeDistroSeries(
120
name='pting', distribution=distribution)
121
package = self.factory.makeSourcePackage(
122
sourcepackagename='snarf', distroseries=series, publish=True)
124
package, AffectsEmailCommand.getBugTarget('fnord/pting/snarf'))
126
def test_getBugTarget_distribution_source_package(self):
127
distribution = self.factory.makeDistribution(name='fnord')
128
series = self.factory.makeDistroSeries(
129
name='pting', distribution=distribution)
130
package = self.factory.makeSourcePackage(
131
sourcepackagename='snarf', distroseries=series, publish=True)
132
dsp = distribution.getSourcePackage(package.name)
134
dsp, AffectsEmailCommand.getBugTarget('fnord/snarf'))
136
def test_getBugTarget_distribution_extra_path_error(self):
137
distribution = self.factory.makeDistribution(name='fnord')
138
series = self.factory.makeDistroSeries(
139
name='pting', distribution=distribution)
140
self.factory.makeSourcePackage(
141
sourcepackagename='snarf', distroseries=series, publish=True)
142
message = "Unexpected path components: thrup"
143
self.assertRaisesWithContent(
144
BugTargetNotFound, message,
145
AffectsEmailCommand.getBugTarget, 'fnord/pting/snarf/thrup')