~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

[r=adeuring][bug=808680] Fix a permission error happening when
        initializing a series from multiple parents with publications.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
    LaunchpadZopelessLayer,
17
17
    )
18
18
from lp.registry.interfaces.distroseries import DerivationError
 
19
from lp.services.features.testing import FeatureFixture
19
20
from lp.soyuz.interfaces.distributionjob import (
20
21
    IInitializeDistroSeriesJobSource,
21
22
    )
 
23
from lp.soyuz.model.distroseriesdifferencejob import (
 
24
    FEATURE_FLAG_ENABLE_MODULE,
 
25
    )
22
26
from lp.soyuz.scripts.tests.test_initialize_distroseries import (
23
27
    InitializationHelperTestCase,
24
28
    )
71
75
 
72
76
    layer = LaunchpadZopelessLayer
73
77
 
 
78
    def setUpParents(self, packages1, packages2):
 
79
        parent1, unused = self.setupParent(packages=packages1)
 
80
        parent2, unused = self.setupParent(packages=packages2)
 
81
        return parent1, parent2
 
82
 
 
83
    def assertBinPackagesAndVersions(self, series, pack_versions):
 
84
        # Helper to assert that series contains the required binaries
 
85
        # pack_version should be of the form [(packagname1, version1), ...]
 
86
        # e.g. [(u'p1', u'0.1-1'), (u'p2', u'2.1')])
 
87
        pub_sources = series.main_archive.getPublishedSources(
 
88
            distroseries=series)
 
89
        binaries = sorted(
 
90
            [(p.getBuiltBinaries()[0].binarypackagerelease.sourcepackagename,
 
91
              p.getBuiltBinaries()[0].binarypackagerelease.version)
 
92
                 for p in pub_sources])
 
93
 
 
94
        self.assertEquals(pack_versions, binaries)
 
95
 
74
96
    def test_multiple_parents_binary_packages(self):
75
97
        # An initialization from many parents (using the package copier)
76
98
        # can happen using the same the db user the job will use
77
99
        # ('initializedistroseries').
78
 
        self.parent1, unused = self.setupParent(
79
 
            packages={'p1': '0.1-1'})
80
 
        self.parent2, unused = self.setupParent(
81
 
            packages={'p2': '2.1'})
82
 
        child = self.factory.makeDistroSeries()
83
 
        transaction.commit()
84
 
        self.layer.switchDbUser('initializedistroseries')
85
 
 
86
 
        child = self._fullInitialize(
87
 
            [self.parent1, self.parent2], child=child)
88
 
        pub_sources = child.main_archive.getPublishedSources(
89
 
            distroseries=child)
90
 
        binaries = sorted(
91
 
            [(p.getBuiltBinaries()[0].binarypackagerelease.sourcepackagename,
92
 
              p.getBuiltBinaries()[0].binarypackagerelease.version)
93
 
                 for p in pub_sources])
94
 
 
95
 
        self.assertEquals(
96
 
            [(u'p1', u'0.1-1'), (u'p2', u'2.1')],
97
 
            binaries)
 
100
        parent1, parent2 = self.setUpParents(
 
101
            packages1={'p1': '0.1-1'}, packages2={'p2': '2.1'})
 
102
        child = self.factory.makeDistroSeries()
 
103
        transaction.commit()
 
104
        self.layer.switchDbUser('initializedistroseries')
 
105
 
 
106
        child = self._fullInitialize(
 
107
            [parent1, parent2], child=child)
 
108
        self.assertBinPackagesAndVersions(
 
109
            child,
 
110
            [(u'p1', u'0.1-1'), (u'p2', u'2.1')])
 
111
 
 
112
    def test_multiple_parents_dsd_flag_on(self):
 
113
        # An initialization can happen if the flag for distroseries
 
114
        # difference creation is on.
 
115
        self.useFixture(FeatureFixture({FEATURE_FLAG_ENABLE_MODULE: u'on'}))
 
116
        parent1, parent2 = self.setUpParents(
 
117
            packages1={'p1': '0.1-1'}, packages2={'p2': '2.1'})
 
118
        child = self.factory.makeDistroSeries()
 
119
        transaction.commit()
 
120
        self.layer.switchDbUser('initializedistroseries')
 
121
 
 
122
        child = self._fullInitialize(
 
123
            [parent1, parent2], child=child)
 
124
        # Make sure the initialization was successful.
 
125
        self.assertBinPackagesAndVersions(
 
126
            child,
 
127
            [(u'p1', u'0.1-1'), (u'p2', u'2.1')])
 
128
        # Switch back to launchpad_main to be able to cleanup the
 
129
        # feature flags.
 
130
        self.layer.switchDbUser('launchpad_main')