~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

[r=stevenk][bug=798873] Add a changed_by parameter to
        DistroSeriesDifference.getForDistroSeries() that limits the
        DSDs returned to those associated with SPRs created by the
        given user, users, or teams.

Show diffs side-by-side

added added

removed removed

Lines of Context:
982
982
        self.makeDiffsForDistroSeries(derived_series)
983
983
        diff_for_other_series = self.factory.makeDistroSeriesDifference()
984
984
 
985
 
        result = getUtility(IDistroSeriesDifferenceSource).getForDistroSeries(
986
 
            derived_series)
 
985
        dsd_source = getUtility(IDistroSeriesDifferenceSource)
 
986
        results = set(dsd_source.getForDistroSeries(derived_series))
987
987
 
988
 
        self.assertFalse(diff_for_other_series in result)
 
988
        self.assertFalse(diff_for_other_series in results)
989
989
 
990
990
    def test_getForDistroSeries_filters_by_type(self):
991
991
        # Only differences for the specified types are returned.
1138
1138
            [], dsd_source.getForDistroSeries(
1139
1139
                dsd.derived_series, packagesets=(packageset, )))
1140
1140
 
 
1141
    def makeDistroSeriesDifferenceForUser(self, series, user):
 
1142
        dsd = self.factory.makeDistroSeriesDifference(derived_series=series)
 
1143
        removeSecurityProxy(dsd.source_package_release).creator = user
 
1144
        return dsd
 
1145
 
 
1146
    def test_getForDistroSeries_filters_by_spr_creator(self):
 
1147
        # Specifiying changed_by limits the DSDs returned to those where the
 
1148
        # associated SPR was created by the given user or team.
 
1149
        megatron = self.factory.makePersonByName("Megatron")
 
1150
        alderney = self.factory.makePersonByName("Alderney")
 
1151
        bulgaria = self.factory.makePersonByName("Bulgaria")
 
1152
        # Create the derived distroseries and a DSD for each of the users
 
1153
        # above.
 
1154
        derived_distroseries = self.factory.makeDistroSeries()
 
1155
        dsd_megatron = self.makeDistroSeriesDifferenceForUser(
 
1156
            derived_distroseries, megatron)
 
1157
        dsd_alderney = self.makeDistroSeriesDifferenceForUser(
 
1158
            derived_distroseries, alderney)
 
1159
        dsd_bulgaria = self.makeDistroSeriesDifferenceForUser(
 
1160
            derived_distroseries, bulgaria)
 
1161
        # When changed_by is a person we see DSDs created only by that person.
 
1162
        dsd_source = getUtility(IDistroSeriesDifferenceSource)
 
1163
        self.assertContentEqual(
 
1164
            [dsd_alderney],
 
1165
            dsd_source.getForDistroSeries(
 
1166
                derived_distroseries, changed_by=alderney))
 
1167
        # When changed_by is a team we see DSDs created by any member of the
 
1168
        # team.
 
1169
        wombles = self.factory.makeTeam(members=(alderney, bulgaria))
 
1170
        self.assertContentEqual(
 
1171
            [dsd_alderney, dsd_bulgaria],
 
1172
            dsd_source.getForDistroSeries(
 
1173
                derived_distroseries, changed_by=wombles))
 
1174
        # When changed_by is not a person or team it is treated as a
 
1175
        # collection, and we see DSDs created by any person in the collection
 
1176
        # or member of a team in the collection.
 
1177
        self.assertContentEqual(
 
1178
            [dsd_alderney, dsd_bulgaria, dsd_megatron],
 
1179
            dsd_source.getForDistroSeries(
 
1180
                derived_distroseries, changed_by=(megatron, wombles)))
 
1181
 
1141
1182
    def test_getByDistroSeriesNameAndParentSeries(self):
1142
1183
        # An individual difference is obtained using the name.
1143
1184
        ds_diff = self.factory.makeDistroSeriesDifference(