~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# Copyright 2010 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Tests for BugTargets."""

__metaclass__ = type

from zope.security.interfaces import ForbiddenAttribute

from canonical.testing.layers import DatabaseFunctionalLayer
from lp.bugs.interfaces.bugtarget import ISeriesBugTarget
from lp.testing import (
    person_logged_in,
    TestCaseWithFactory,
    )


class BugTargetBugFilingDuplicateSearchAlwaysOn:
    """A base class for tests of bug targets where dupes are always searched.
    """

    def test_enable_bugfiling_duplicate_search(self):
        # enable_bugfiling_duplicate_search is always True.
        self.assertTrue(self.bugtarget.enable_bugfiling_duplicate_search)

    def test_enable_bugfiling_duplicate_search_is_read_only(self):
        # enable_bugfiling_duplicate_search is a read-only attribute
        with person_logged_in(self.bugtarget.owner):
            self.assertRaises(
                ForbiddenAttribute, setattr, self.bugtarget,
                'enable_bugfiling_duplicate_search', False)


class TestDistribution(BugTargetBugFilingDuplicateSearchAlwaysOn,
                       TestCaseWithFactory):
    """Tests for distributions as bug targets."""

    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestDistribution, self).setUp()
        self.bugtarget = self.factory.makeDistribution()


class TestDistroSeries(BugTargetBugFilingDuplicateSearchAlwaysOn,
                       TestCaseWithFactory):
    """Tests for distributions as bug targets."""

    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestDistroSeries, self).setUp()
        self.bugtarget = self.factory.makeDistroSeries()

    def test_bugtarget_parent(self):
        self.assertTrue(ISeriesBugTarget.providedBy(self.bugtarget))
        self.assertEqual(
            self.bugtarget.distribution, self.bugtarget.bugtarget_parent)


class TestProjectGroup(BugTargetBugFilingDuplicateSearchAlwaysOn,
                       TestCaseWithFactory):
    """Tests for distributions as bug targets."""

    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestProjectGroup, self).setUp()
        self.bugtarget = self.factory.makeProject()


class BugTargetBugFilingDuplicateSearchSettable:
    """A base class for tests of bug targets where dupe search is settable.
    """

    def test_enable_bugfiling_duplicate_search_default(self):
        # The default value of enable_bugfiling_duplicate_search is True.
        self.assertTrue(self.bugtarget.enable_bugfiling_duplicate_search)

    def test_enable_bugfiling_duplicate_search_is_changeable(self):
        # The bug supervisor can change enable_bugfiling_duplicate_search.
        with person_logged_in(self.bug_supervisor):
            self.bugtarget.enable_bugfiling_duplicate_search = False
        self.assertFalse(self.bugtarget.enable_bugfiling_duplicate_search)


class TestProduct(BugTargetBugFilingDuplicateSearchSettable,
                  TestCaseWithFactory):
    """Tests for products as bug targets."""

    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestProduct, self).setUp()
        self.bug_supervisor = self.factory.makePerson()
        self.bugtarget = self.factory.makeProduct(
            bug_supervisor=self.bug_supervisor)


class TestDistributionSourcePackage(BugTargetBugFilingDuplicateSearchSettable,
                                    TestCaseWithFactory):
    """Tests for distributionsourcepackages as bug targets."""

    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestDistributionSourcePackage, self).setUp()
        self.bug_supervisor = self.factory.makePerson()
        distribution = self.factory.makeDistribution(
            bug_supervisor=self.bug_supervisor)
        self.bugtarget = self.factory.makeDistributionSourcePackage(
            distribution=distribution)


class BugTargetBugFilingDuplicateSearchInherited:
    """A base class for tests of bug targets where the dupe search policy
    is inherited from a parent object.
    """

    def test_enable_bugfiling_duplicate_search_default(self):
        # The default value of enable_bugfiling_duplicate_search is True.
        self.assertTrue(self.bugtarget.enable_bugfiling_duplicate_search)

    def test_enable_bugfiling_duplicate_search_changed_by_parent_change(self):
        # If enable_bugfiling_duplicate_search is changed for the parent
        # object, it is changed for the bug traget too.
        with person_logged_in(self.bug_supervisor):
            parent = self.bugtarget.bugtarget_parent
            parent.enable_bugfiling_duplicate_search = False
        self.assertFalse(self.bugtarget.enable_bugfiling_duplicate_search)


class TestProductSeries(BugTargetBugFilingDuplicateSearchInherited,
                        TestCaseWithFactory):
    """Tests for product serieses as bug targets."""

    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestProductSeries, self).setUp()
        self.bug_supervisor = self.factory.makePerson()
        self.bugtarget = self.factory.makeProductSeries(
            product=self.factory.makeProduct(
                bug_supervisor=self.bug_supervisor))

    def test_bugtarget_parent(self):
        self.assertTrue(ISeriesBugTarget.providedBy(self.bugtarget))
        self.assertEqual(
            self.bugtarget.product, self.bugtarget.bugtarget_parent)


class TestSourcePackage(BugTargetBugFilingDuplicateSearchInherited,
                       TestCaseWithFactory):
    """Tests for product serieses as bug targets."""

    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestSourcePackage, self).setUp()
        self.bug_supervisor = self.factory.makePerson()
        distribution = self.factory.makeDistribution(
            bug_supervisor=self.bug_supervisor)
        distroseries = self.factory.makeDistroSeries(
            distribution=distribution)
        self.bugtarget = self.factory.makeSourcePackage(
            distroseries=distroseries)

    def test_bugtarget_parent(self):
        self.assertTrue(ISeriesBugTarget.providedBy(self.bugtarget))
        self.assertEqual(
            self.bugtarget.distribution_sourcepackage,
            self.bugtarget.bugtarget_parent)