~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/mail/tests/test_commands.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-08-18 13:44:27 UTC
  • mfrom: (13691.1.8 private-bug-1)
  • Revision ID: launchpad@pqm.canonical.com-20110818134427-cmplu2l2iybxdtcy
[r=stevenk][no-qa] Convert doctests to unittests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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).
3
3
 
4
 
from doctest import DocTestSuite
5
 
 
6
 
 
7
 
def test_suite():
8
 
    return DocTestSuite('lp.bugs.mail.commands')
 
4
from canonical.testing.layers import DatabaseFunctionalLayer
 
5
from lp.bugs.mail.commands import (
 
6
    AffectsEmailCommand,
 
7
    )
 
8
from lp.services.mail.interfaces import BugTargetNotFound
 
9
from lp.testing import (
 
10
    login_celebrity,
 
11
    login_person,
 
12
    TestCaseWithFactory,
 
13
    )
 
14
 
 
15
 
 
16
class AffectsEmailCommandTestCase(TestCaseWithFactory):
 
17
 
 
18
    layer = DatabaseFunctionalLayer
 
19
 
 
20
    def test__splitPath_with_slashes(self):
 
21
        self.assertEqual(
 
22
            ('foo', 'bar/baz'), AffectsEmailCommand._splitPath('foo/bar/baz'))
 
23
 
 
24
    def test__splitPath_no_slashes(self):
 
25
        self.assertEqual(
 
26
            ('foo', ''), AffectsEmailCommand._splitPath('foo'))
 
27
 
 
28
    def test__normalizePath_leading_slash(self):
 
29
        self.assertEqual(
 
30
            'foo/bar', AffectsEmailCommand._normalizePath('/foo/bar'))
 
31
 
 
32
    def test__normalizePath_distros(self):
 
33
        self.assertEqual(
 
34
            'foo/bar', AffectsEmailCommand._normalizePath('/distros/foo/bar'))
 
35
 
 
36
    def test__normalizePath_products(self):
 
37
        self.assertEqual(
 
38
            'foo/bar',
 
39
            AffectsEmailCommand._normalizePath('/products/foo/bar'))
 
40
 
 
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')
 
46
 
 
47
    def test_getBugTarget_project_group_error(self):
 
48
        owner = self.factory.makePerson()
 
49
        login_person(owner)
 
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
 
55
        message = (
 
56
            "fnord is a group of projects. To report a bug, you need to "
 
57
            "specify which of these projects the bug applies to: "
 
58
            "pting, snarf")
 
59
        self.assertRaisesWithContent(
 
60
            BugTargetNotFound, message,
 
61
            AffectsEmailCommand.getBugTarget, 'fnord')
 
62
 
 
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')
 
71
 
 
72
    def test_getBugTarget_project(self):
 
73
        project = self.factory.makeProduct(name='fnord')
 
74
        self.assertEqual(project, AffectsEmailCommand.getBugTarget('fnord'))
 
75
 
 
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')
 
82
 
 
83
    def test_getBugTarget_project_series(self):
 
84
        project = self.factory.makeProduct(name='fnord')
 
85
        series = self.factory.makeProductSeries(name='pting', product=project)
 
86
        self.assertEqual(
 
87
            series, AffectsEmailCommand.getBugTarget('fnord/pting'))
 
88
 
 
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')
 
96
 
 
97
    def test_getBugTarget_no_series_or_package_error(self):
 
98
        self.factory.makeDistribution(name='fnord')
 
99
        message = (
 
100
            "Fnord doesn't have a series or source package named 'pting'.")
 
101
        self.assertRaisesWithContent(
 
102
            BugTargetNotFound, message,
 
103
            AffectsEmailCommand.getBugTarget, 'fnord/pting')
 
104
 
 
105
    def test_getBugTarget_distribution(self):
 
106
        distribution = self.factory.makeDistribution(name='fnord')
 
107
        self.assertEqual(
 
108
            distribution, AffectsEmailCommand.getBugTarget('fnord'))
 
109
 
 
110
    def test_getBugTarget_distroseries(self):
 
111
        distribution = self.factory.makeDistribution(name='fnord')
 
112
        series = self.factory.makeDistroSeries(
 
113
            name='pting', distribution=distribution)
 
114
        self.assertEqual(
 
115
            series, AffectsEmailCommand.getBugTarget('fnord/pting'))
 
116
 
 
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)
 
123
        self.assertEqual(
 
124
            package, AffectsEmailCommand.getBugTarget('fnord/pting/snarf'))
 
125
 
 
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)
 
133
        self.assertEqual(
 
134
            dsp, AffectsEmailCommand.getBugTarget('fnord/snarf'))
 
135
 
 
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')