~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/app/browser/tests/test_vocabulary.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-17 02:55:39 UTC
  • mfrom: (13970.5.2 target-pickers-go)
  • Revision ID: launchpad@pqm.canonical.com-20110917025539-5bumljanv43bn801
[r=sinzui][bug=820005, 851437,
        851440] Updates the target pickers to an enhanced version similar to
        person pickers, behind a feature flag.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    )
36
36
from lp.app.errors import UnexpectedFormData
37
37
from lp.registry.interfaces.irc import IIrcIDSet
 
38
from lp.registry.interfaces.series import SeriesStatus
38
39
from lp.services.features.testing import FeatureFixture
39
40
from lp.testing import (
40
41
    login_person,
158
159
 
159
160
    layer = DatabaseFunctionalLayer
160
161
 
 
162
    def setUp(self):
 
163
        super(TestDistributionSourcePackagePickerEntrySourceAdapter,
 
164
              self).setUp()
 
165
        flag = {'disclosure.target_picker_enhancements.enabled':'on'}
 
166
        self.useFixture(FeatureFixture(flag))
 
167
 
161
168
    def test_dsp_to_picker_entry(self):
162
169
        dsp = self.factory.makeDistributionSourcePackage()
163
170
        adapter = IPickerEntrySource(dsp)
164
171
        self.assertTrue(IPickerEntrySource.providedBy(adapter))
165
172
 
 
173
    def test_dsp_target_type(self):
 
174
        dsp = self.factory.makeDistributionSourcePackage()
 
175
        series = self.factory.makeDistroSeries(distribution=dsp.distribution)
 
176
        release = self.factory.makeSourcePackageRelease(
 
177
            distroseries=series,
 
178
            sourcepackagename=dsp.sourcepackagename)
 
179
        self.factory.makeSourcePackagePublishingHistory(
 
180
            distroseries=series,
 
181
            sourcepackagerelease=release)
 
182
        [entry] = IPickerEntrySource(dsp).getPickerEntries([dsp], object())
 
183
        self.assertEqual('package', entry.target_type)
 
184
 
 
185
    def test_dsp_provides_details(self):
 
186
        dsp = self.factory.makeDistributionSourcePackage()
 
187
        series = self.factory.makeDistroSeries(distribution=dsp.distribution)
 
188
        release = self.factory.makeSourcePackageRelease(
 
189
            distroseries=series,
 
190
            sourcepackagename=dsp.sourcepackagename)
 
191
        self.factory.makeSourcePackagePublishingHistory(
 
192
            distroseries=series,
 
193
            sourcepackagerelease=release)
 
194
        [entry] = IPickerEntrySource(dsp).getPickerEntries([dsp], object())
 
195
        expected = "Maintainer: %s" % dsp.currentrelease.maintainer.displayname
 
196
        self.assertEqual([expected], entry.details)
 
197
 
166
198
    def test_dsp_provides_summary(self):
167
199
        dsp = self.factory.makeDistributionSourcePackage()
168
200
        series = self.factory.makeDistroSeries(distribution=dsp.distribution)
190
222
 
191
223
    layer = DatabaseFunctionalLayer
192
224
 
 
225
    def setUp(self):
 
226
        super(TestProductPickerEntrySourceAdapter, self).setUp()
 
227
        flag = {'disclosure.target_picker_enhancements.enabled':'on'}
 
228
        self.useFixture(FeatureFixture(flag))
 
229
 
193
230
    def test_product_to_picker_entry(self):
194
231
        product = self.factory.makeProduct()
195
232
        adapter = IPickerEntrySource(product)
196
233
        self.assertTrue(IPickerEntrySource.providedBy(adapter))
197
234
 
 
235
    def test_product_provides_alt_title(self):
 
236
        with FeatureFixture({
 
237
            'disclosure.target_picker_enhancements.enabled':'on'}):
 
238
            product = self.factory.makeProduct()
 
239
            [entry] = IPickerEntrySource(product).getPickerEntries(
 
240
                    [product], object())
 
241
            self.assertEqual(entry.alt_title, product.name)
 
242
 
 
243
    def test_product_target_type(self):
 
244
        product = self.factory.makeProduct()
 
245
        [entry] = IPickerEntrySource(product).getPickerEntries(
 
246
                [product], object())
 
247
        # We check for project, not product, because users don't see products.
 
248
        self.assertEqual('project', entry.target_type)
 
249
 
 
250
    def test_product_provides_details(self):
 
251
        product = self.factory.makeProduct()
 
252
        [entry] = IPickerEntrySource(product).getPickerEntries(
 
253
                [product], object())
 
254
        expected = "Maintainer: %s" % product.owner.displayname
 
255
        self.assertEqual([expected], entry.details)
 
256
 
198
257
    def test_product_provides_summary(self):
199
258
        product = self.factory.makeProduct()
200
259
        [entry] = IPickerEntrySource(product).getPickerEntries(
202
261
        self.assertEqual(entry.description, product.summary)
203
262
 
204
263
 
 
264
class TestProjectGroupPickerEntrySourceAdapter(TestCaseWithFactory):
 
265
 
 
266
    layer = DatabaseFunctionalLayer
 
267
 
 
268
    def setUp(self):
 
269
        super(TestProjectGroupPickerEntrySourceAdapter, self).setUp()
 
270
        flag = {'disclosure.target_picker_enhancements.enabled':'on'}
 
271
        self.useFixture(FeatureFixture(flag))
 
272
 
 
273
    def test_projectgroup_to_picker_entry(self):
 
274
        projectgroup = self.factory.makeProject()
 
275
        adapter = IPickerEntrySource(projectgroup)
 
276
        self.assertTrue(IPickerEntrySource.providedBy(adapter))
 
277
 
 
278
    def test_projectgroup_provides_alt_title(self):
 
279
        with FeatureFixture({
 
280
            'disclosure.target_picker_enhancements.enabled':'on'}):
 
281
            projectgroup = self.factory.makeProject()
 
282
            [entry] = IPickerEntrySource(projectgroup).getPickerEntries(
 
283
                    [projectgroup], object())
 
284
            self.assertEqual(entry.alt_title, projectgroup.name)
 
285
 
 
286
    def test_projectgroup_target_type(self):
 
287
        projectgroup = self.factory.makeProject()
 
288
        [entry] = IPickerEntrySource(projectgroup).getPickerEntries(
 
289
                [projectgroup], object())
 
290
        self.assertEqual('project group', entry.target_type)
 
291
 
 
292
    def test_projectgroup_provides_details(self):
 
293
        projectgroup = self.factory.makeProject()
 
294
        [entry] = IPickerEntrySource(projectgroup).getPickerEntries(
 
295
                [projectgroup], object())
 
296
        expected = "Maintainer: %s" % projectgroup.owner.displayname
 
297
        self.assertEqual([expected], entry.details)
 
298
 
 
299
    def test_projectgroup_provides_summary(self):
 
300
        projectgroup = self.factory.makeProject()
 
301
        [entry] = IPickerEntrySource(projectgroup).getPickerEntries(
 
302
                [projectgroup], object())
 
303
        self.assertEqual(entry.description, projectgroup.summary)
 
304
 
 
305
 
205
306
class TestDistributionPickerEntrySourceAdapter(TestCaseWithFactory):
206
307
 
207
308
    layer = DatabaseFunctionalLayer
208
309
 
 
310
    def setUp(self):
 
311
        super(TestDistributionPickerEntrySourceAdapter, self).setUp()
 
312
        flag = {'disclosure.target_picker_enhancements.enabled':'on'}
 
313
        self.useFixture(FeatureFixture(flag))
 
314
 
209
315
    def test_distribution_to_picker_entry(self):
210
316
        distribution = self.factory.makeDistribution()
211
317
        adapter = IPickerEntrySource(distribution)
212
318
        self.assertTrue(IPickerEntrySource.providedBy(adapter))
213
319
 
 
320
    def test_distribution_provides_alt_title(self):
 
321
        with FeatureFixture({
 
322
            'disclosure.target_picker_enhancements.enabled':'on'}):
 
323
            distribution = self.factory.makeDistribution()
 
324
            [entry] = IPickerEntrySource(distribution).getPickerEntries(
 
325
                    [distribution], object())
 
326
            self.assertEqual(entry.alt_title, distribution.name)
 
327
 
 
328
    def test_distribution_provides_details(self):
 
329
        distribution = self.factory.makeDistribution()
 
330
        series = self.factory.makeDistroSeries(
 
331
            distribution=distribution,
 
332
            status=SeriesStatus.CURRENT)
 
333
        [entry] = IPickerEntrySource(distribution).getPickerEntries(
 
334
                [distribution], object())
 
335
        maintain_name = distribution.currentseries.owner.displayname
 
336
        expected = "Maintainer: %s" % maintain_name
 
337
        self.assertEqual([expected], entry.details)
 
338
 
214
339
    def test_distribution_provides_summary(self):
215
340
        distribution = self.factory.makeDistribution()
216
341
        [entry] = IPickerEntrySource(distribution).getPickerEntries(
217
342
                [distribution], object())
218
343
        self.assertEqual(entry.description, distribution.summary)
219
344
 
 
345
    def test_distribution_target_type(self):
 
346
        distribution = self.factory.makeDistribution()
 
347
        [entry] = IPickerEntrySource(distribution).getPickerEntries(
 
348
                [distribution], object())
 
349
        self.assertEqual('distribution', entry.target_type)
220
350
 
221
351
class TestPersonVocabulary:
222
352
    implements(IHugeVocabulary)