~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Stuart Bishop
  • Date: 2011-09-28 12:49:24 UTC
  • mfrom: (9893.10.1 trivial)
  • mto: This revision was merged to the branch mainline in revision 14178.
  • Revision ID: stuart.bishop@canonical.com-20110928124924-m5a22fymqghw6c5i
Merged trivial into distinct-db-users.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    IHugeVocabulary,
27
27
    VocabularyFilter,
28
28
    )
29
 
from canonical.testing.layers import DatabaseFunctionalLayer
 
29
from canonical.testing.layers import (
 
30
    DatabaseFunctionalLayer,
 
31
    LaunchpadFunctionalLayer,
 
32
    )
30
33
from lp.app.browser.vocabulary import (
31
34
    IPickerEntrySource,
32
35
    MAX_DESCRIPTION_LENGTH,
49
52
    return entry
50
53
 
51
54
 
 
55
class DefaultPickerEntrySourceAdapterTestCase(TestCaseWithFactory):
 
56
 
 
57
    layer = LaunchpadFunctionalLayer
 
58
 
 
59
    def test_css_image_entry_without_icon(self):
 
60
        # When the context does not have a custom icon, its sprite is used.
 
61
        product = self.factory.makeProduct()
 
62
        entry = get_picker_entry(product, object())
 
63
        self.assertEqual("sprite product", entry.css)
 
64
        self.assertEqual(None, entry.image)
 
65
 
 
66
    def test_css_image_entry_without_icon_or_sprite(self):
 
67
        # When the context does not have a custom icon, and there is no
 
68
        # sprite adapter rules, the generic sprite is used.
 
69
        thing = object()
 
70
        entry = get_picker_entry(thing, object())
 
71
        self.assertEqual('sprite bullet', entry.css)
 
72
        self.assertEqual(None, entry.image)
 
73
 
 
74
    def test_css_image_entry_with_icon(self):
 
75
        # When the context has a custom icon the URL is used.
 
76
        icon = self.factory.makeLibraryFileAlias(
 
77
            filename='smurf.png', content_type='image/png')
 
78
        product = self.factory.makeProduct(icon=icon)
 
79
        entry = get_picker_entry(product, object())
 
80
        self.assertEqual(None, entry.css)
 
81
        self.assertEqual(icon.getURL(), entry.image)
 
82
 
 
83
 
52
84
class PersonPickerEntrySourceAdapterTestCase(TestCaseWithFactory):
53
85
 
54
86
    layer = DatabaseFunctionalLayer
224
256
            distroarchseries=archseries)
225
257
        self.assertEqual("fnord", self.getPickerEntry(dsp).description)
226
258
 
 
259
    def test_dsp_provides_alt_title_link(self):
 
260
        distro = self.factory.makeDistribution(name='fnord')
 
261
        series = self.factory.makeDistroSeries(
 
262
            name='pting', distribution=distro)
 
263
        self.factory.makeSourcePackage(
 
264
            sourcepackagename='snarf', distroseries=series, publish=True)
 
265
        dsp = distro.getSourcePackage('snarf')
 
266
        self.assertEqual(
 
267
            'http://launchpad.dev/fnord/+source/snarf',
 
268
            self.getPickerEntry(dsp).alt_title_link)
 
269
 
 
270
 
227
271
class TestProductPickerEntrySourceAdapter(TestCaseWithFactory):
228
272
 
229
273
    layer = DatabaseFunctionalLayer
275
319
        self.assertEqual(
276
320
            expected_details, entry.details[0])
277
321
 
 
322
    def test_product_provides_alt_title_link(self):
 
323
        product = self.factory.makeProduct(name='fnord')
 
324
        self.assertEqual(
 
325
            'http://launchpad.dev/fnord',
 
326
            self.getPickerEntry(product).alt_title_link)
 
327
 
278
328
 
279
329
class TestProjectGroupPickerEntrySourceAdapter(TestCaseWithFactory):
280
330
 
328
378
        self.assertEqual(
329
379
            expected_details, entry.details[0])
330
380
 
 
381
    def test_projectgroup_provides_alt_title_link(self):
 
382
        projectgroup = self.factory.makeProject(name='fnord')
 
383
        self.assertEqual(
 
384
            'http://launchpad.dev/fnord',
 
385
            self.getPickerEntry(projectgroup).alt_title_link)
 
386
 
 
387
 
331
388
class TestDistributionPickerEntrySourceAdapter(TestCaseWithFactory):
332
389
 
333
390
    layer = DatabaseFunctionalLayer
370
427
            'distribution', self.getPickerEntry(distribution).target_type)
371
428
 
372
429
    def test_distribution_truncates_summary(self):
373
 
        summary = ("This is a deliberately, overly long summary. It goes on"
374
 
                   "and on and on so as to break things up a good bit.")
375
 
        distribution= self.factory.makeDistribution(summary=summary)
 
430
        summary = (
 
431
            "This is a deliberately, overly long summary. It goes on "
 
432
            "and on and on so as to break things up a good bit.")
 
433
        distribution = self.factory.makeDistribution(summary=summary)
376
434
        index = summary.rfind(' ', 0, 45)
377
435
        expected_summary = summary[:index + 1]
378
436
        expected_details = summary[index:]
382
440
        self.assertEqual(
383
441
            expected_details, entry.details[0])
384
442
 
 
443
    def test_distribution_provides_alt_title_link(self):
 
444
        distribution = self.factory.makeDistribution(name='fnord')
 
445
        self.assertEqual(
 
446
            'http://launchpad.dev/fnord',
 
447
            self.getPickerEntry(distribution).alt_title_link)
 
448
 
 
449
 
385
450
class TestPersonVocabulary:
386
451
    implements(IHugeVocabulary)
387
452
    test_persons = []