~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/tests/test_distroseriesparent.py

Merge db-devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
    Equals,
10
10
    MatchesStructure,
11
11
    )
12
 
 
13
12
from zope.component import getUtility
14
13
from zope.interface.verify import verifyObject
15
14
from zope.security.interfaces import Unauthorized
23
22
    IDistroSeriesParent,
24
23
    IDistroSeriesParentSet,
25
24
    )
 
25
from lp.registry.interfaces.pocket import PackagePublishingPocket
 
26
from lp.soyuz.interfaces.component import IComponentSet
26
27
from lp.testing import (
27
28
    person_logged_in,
28
29
    TestCaseWithFactory,
55
56
            MatchesStructure(
56
57
                derived_series=Equals(derived_series),
57
58
                parent_series=Equals(parent_series),
58
 
                initialized=Equals(True)
 
59
                initialized=Equals(True),
 
60
                is_overlay=Equals(False),
 
61
                component=Equals(None),
 
62
                pocket=Equals(None),
 
63
                ))
 
64
 
 
65
    def test_properties_overlay(self):
 
66
        # Test the model properties if the DSP represents an overlay.
 
67
        parent_series = self.factory.makeDistroSeries()
 
68
        derived_series = self.factory.makeDistroSeries()
 
69
        universe_component = getUtility(IComponentSet).ensure('universe')
 
70
        dsp = self.factory.makeDistroSeriesParent(
 
71
            derived_series=derived_series,
 
72
            parent_series=parent_series,
 
73
            initialized=True,
 
74
            is_overlay=True,
 
75
            component=universe_component,
 
76
            pocket=PackagePublishingPocket.SECURITY,
 
77
            )
 
78
 
 
79
        self.assertThat(
 
80
            dsp,
 
81
            MatchesStructure(
 
82
                derived_series=Equals(derived_series),
 
83
                parent_series=Equals(parent_series),
 
84
                initialized=Equals(True),
 
85
                is_overlay=Equals(True),
 
86
                component=Equals(universe_component),
 
87
                pocket=Equals(PackagePublishingPocket.SECURITY),
59
88
                ))
60
89
 
61
90
    def test_getByDerivedSeries(self):
78
107
    def test_getByParentSeries(self):
79
108
        parent_series = self.factory.makeDistroSeries()
80
109
        derived_series = self.factory.makeDistroSeries()
81
 
        dsp = self.factory.makeDistroSeriesParent(
 
110
        self.factory.makeDistroSeriesParent(
82
111
            derived_series, parent_series)
83
112
        results = getUtility(IDistroSeriesParentSet).getByParentSeries(
84
113
            parent_series)
130
159
        dsp.derived_series.distribution.owner = person
131
160
        with person_logged_in(person):
132
161
            self.assertCanEdit(dsp)
 
162
 
 
163
 
 
164
class TestOverlayTree(TestCaseWithFactory):
 
165
    """Test the overlay tree."""
 
166
 
 
167
    layer = DatabaseFunctionalLayer
 
168
 
 
169
    def test_getFlattenedOverlayTree(self):
 
170
        #
 
171
        #             series
 
172
        #               |
 
173
        #    ----------------------------------
 
174
        #    |          |          |          |
 
175
        #    o          o          |          o
 
176
        #    |          |          |          |
 
177
        # parent11   parent21   parent31   parent41
 
178
        #    |          |
 
179
        #    o          o
 
180
        #    |          |             type of relation:
 
181
        # parent12   parent22          |           |
 
182
        #    |                         |           o
 
183
        #    |                         |           |
 
184
        #    |                       no overlay  overlay
 
185
        # parent13
 
186
        #
 
187
        distroseries = self.factory.makeDistroSeries()
 
188
        parent11 = self.factory.makeDistroSeries()
 
189
        parent12 = self.factory.makeDistroSeries()
 
190
        parent21 = self.factory.makeDistroSeries()
 
191
        universe_component = getUtility(IComponentSet).ensure('universe')
 
192
        # series -> parent11
 
193
        dsp_series_parent11 = self.factory.makeDistroSeriesParent(
 
194
            derived_series=distroseries, parent_series=parent11,
 
195
            initialized=True, is_overlay=True,
 
196
            pocket=PackagePublishingPocket.RELEASE,
 
197
            component=universe_component)
 
198
        # parent11 -> parent12
 
199
        dsp_parent11_parent12 = self.factory.makeDistroSeriesParent(
 
200
            derived_series=parent11, parent_series=parent12,
 
201
            initialized=True, is_overlay=True,
 
202
            pocket=PackagePublishingPocket.RELEASE,
 
203
            component=universe_component)
 
204
        # parent12 -> parent13
 
205
        self.factory.makeDistroSeriesParent(derived_series=parent12,
 
206
            initialized=True, is_overlay=False)
 
207
        # series -> parent21
 
208
        dsp_series_parent21 = self.factory.makeDistroSeriesParent(
 
209
            derived_series=distroseries, parent_series=parent21,
 
210
            initialized=True, is_overlay=True,
 
211
            pocket=PackagePublishingPocket.RELEASE,
 
212
            component=universe_component)
 
213
        # parent21 -> parent22
 
214
        dsp_parent21_parent22 = self.factory.makeDistroSeriesParent(
 
215
            derived_series=parent21, initialized=True, is_overlay=True,
 
216
            pocket=PackagePublishingPocket.RELEASE,
 
217
            component=universe_component)
 
218
        # series -> parent31
 
219
        self.factory.makeDistroSeriesParent(derived_series=distroseries,
 
220
            initialized=True, is_overlay=False)
 
221
        # series -> parent41
 
222
        dsp_series_parent41 = self.factory.makeDistroSeriesParent(
 
223
            derived_series=distroseries, initialized=True, is_overlay=True,
 
224
            pocket=PackagePublishingPocket.RELEASE,
 
225
            component=universe_component)
 
226
        overlays = getUtility(
 
227
            IDistroSeriesParentSet).getFlattenedOverlayTree(distroseries)
 
228
 
 
229
        self.assertContentEqual(
 
230
            [dsp_series_parent11, dsp_parent11_parent12, dsp_series_parent21,
 
231
             dsp_parent21_parent22, dsp_series_parent41],
 
232
            overlays)
 
233
 
 
234
    def test_getFlattenedOverlayTree_empty(self):
 
235
        distroseries = self.factory.makeDistroSeries()
 
236
        self.factory.makeDistroSeriesParent(derived_series=distroseries,
 
237
            initialized=True, is_overlay=False)
 
238
        overlays = getUtility(
 
239
            IDistroSeriesParentSet).getFlattenedOverlayTree(distroseries)
 
240
 
 
241
        self.assertTrue(overlays.is_empty())