29
from canonical.testing.layers import DatabaseFunctionalLayer
29
from canonical.testing.layers import (
30
DatabaseFunctionalLayer,
31
LaunchpadFunctionalLayer,
30
33
from lp.app.browser.vocabulary import (
31
34
IPickerEntrySource,
32
35
MAX_DESCRIPTION_LENGTH,
55
class DefaultPickerEntrySourceAdapterTestCase(TestCaseWithFactory):
57
layer = LaunchpadFunctionalLayer
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)
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.
70
entry = get_picker_entry(thing, object())
71
self.assertEqual('sprite bullet', entry.css)
72
self.assertEqual(None, entry.image)
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)
52
84
class PersonPickerEntrySourceAdapterTestCase(TestCaseWithFactory):
54
86
layer = DatabaseFunctionalLayer
224
256
distroarchseries=archseries)
225
257
self.assertEqual("fnord", self.getPickerEntry(dsp).description)
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')
267
'http://launchpad.dev/fnord/+source/snarf',
268
self.getPickerEntry(dsp).alt_title_link)
227
271
class TestProductPickerEntrySourceAdapter(TestCaseWithFactory):
229
273
layer = DatabaseFunctionalLayer
275
319
self.assertEqual(
276
320
expected_details, entry.details[0])
322
def test_product_provides_alt_title_link(self):
323
product = self.factory.makeProduct(name='fnord')
325
'http://launchpad.dev/fnord',
326
self.getPickerEntry(product).alt_title_link)
279
329
class TestProjectGroupPickerEntrySourceAdapter(TestCaseWithFactory):
328
378
self.assertEqual(
329
379
expected_details, entry.details[0])
381
def test_projectgroup_provides_alt_title_link(self):
382
projectgroup = self.factory.makeProject(name='fnord')
384
'http://launchpad.dev/fnord',
385
self.getPickerEntry(projectgroup).alt_title_link)
331
388
class TestDistributionPickerEntrySourceAdapter(TestCaseWithFactory):
333
390
layer = DatabaseFunctionalLayer
370
427
'distribution', self.getPickerEntry(distribution).target_type)
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)
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])
443
def test_distribution_provides_alt_title_link(self):
444
distribution = self.factory.makeDistribution(name='fnord')
446
'http://launchpad.dev/fnord',
447
self.getPickerEntry(distribution).alt_title_link)
385
450
class TestPersonVocabulary:
386
451
implements(IHugeVocabulary)
387
452
test_persons = []