122
119
@patch('softwarecenter.ui.gtk3.widgets.recommendations.RecommenderAgent'
123
120
'.post_submit_profile')
124
121
def setUp(self, mock_query, mock_recommender_is_opted_in, mock_sso):
127
122
# patch the recommender to specify that we are not opted-in at
128
123
# the start of each test
129
124
mock_recommender_is_opted_in.return_value = False
130
125
# we specify the "Internet" category because we do specific checks
131
126
# in the following tests that depend on this being the category choice
132
self.win = get_test_window_catview(self.db,
133
selected_category="Internet")
134
self.addCleanup(self.win.destroy)
135
self.notebook = self.win.get_child()
136
self.lobby = self.win.get_data("lobby")
137
self.subcat_view = self.win.get_data("subcat")
127
super(RecommendationsTestCase, self).setUp(selected_category="Internet")
138
128
self.rec_panel = self.lobby.recommended_for_you_panel
140
130
def test_recommended_for_you_opt_in_display(self):
375
class ExhibitsTestCase(unittest.TestCase):
376
"""The test suite for the exhibits carousel."""
379
self.cache = FakedCache()
380
self.db = StoreDatabase(cache=self.cache)
381
self.lobby = lobbyview.LobbyView(cache=self.cache, db=self.db,
382
icons=None, apps_filter=None)
383
self.addCleanup(self.lobby.destroy)
385
def _get_banner_from_lobby(self):
386
return self.lobby.vbox.get_children()[-1].get_child()
388
def test_featured_exhibit_by_default(self):
389
"""Show the featured exhibit before querying the remote service."""
390
self.lobby._append_banner_ads()
392
banner = self._get_banner_from_lobby()
393
self.assertEqual(1, len(banner.exhibits))
394
self.assertIsInstance(banner.exhibits[0], lobbyview.FeaturedExhibit)
396
def test_no_exhibit_if_not_available(self):
397
"""The exhibit should not be shown if the package is not available."""
399
exhibit.package_names = u'foobarbaz'
401
sca = ObjectWithSignals()
402
sca.query_exhibits = lambda: sca.emit('exhibits', sca, [exhibit])
404
with patch.object(lobbyview, 'SoftwareCenterAgent', lambda: sca):
405
self.lobby._append_banner_ads()
407
banner = self._get_banner_from_lobby()
408
self.assertEqual(1, len(banner.exhibits))
409
self.assertIsInstance(banner.exhibits[0], lobbyview.FeaturedExhibit)
411
def test_exhibit_if_available(self):
412
"""The exhibit should be shown if the package is available."""
414
exhibit.package_names = u'foobarbaz'
415
exhibit.banner_url = 'banner'
416
exhibit.title_translated = ''
418
self.cache[u'foobarbaz'] = Mock()
420
sca = ObjectWithSignals()
421
sca.query_exhibits = lambda: sca.emit('exhibits', sca, [exhibit])
423
with patch.object(lobbyview, 'SoftwareCenterAgent', lambda: sca):
424
self.lobby._append_banner_ads()
426
banner = self._get_banner_from_lobby()
427
self.assertEqual(1, len(banner.exhibits))
428
self.assertIs(banner.exhibits[0], exhibit)
430
def test_exhibit_if_mixed_availability(self):
431
"""The exhibit should be shown even if some are not available."""
434
exhibit.package_names = u'foobarbaz'
435
exhibit.banner_url = 'banner'
436
exhibit.title_translated = ''
438
self.cache[u'foobarbaz'] = Mock()
440
# not available exhibit
442
other.package_names = u'not-there'
444
sca = ObjectWithSignals()
445
sca.query_exhibits = lambda: sca.emit('exhibits', sca,
448
with patch.object(lobbyview, 'SoftwareCenterAgent', lambda: sca):
449
self.lobby._append_banner_ads()
451
banner = self._get_banner_from_lobby()
452
self.assertEqual(1, len(banner.exhibits))
453
self.assertIs(banner.exhibits[0], exhibit)
455
def test_exhibit_with_url(self):
458
exhibit.package_names = ''
459
exhibit.click_url = 'http://example.com'
460
exhibit.banner_url = 'banner'
461
exhibit.title_translated = ''
463
sca = ObjectWithSignals()
464
sca.query_exhibits = lambda: sca.emit('exhibits', sca,
467
with patch.object(lobbyview, 'SoftwareCenterAgent', lambda: sca):
469
self.lobby._append_banner_ads()
471
alloc = self.lobby.exhibit_banner.get_allocation()
473
mock_event.x = alloc.x
474
mock_event.y = alloc.y
475
with patch.object(self.lobby.exhibit_banner, 'emit') as mock_emit:
476
self.lobby.exhibit_banner.on_button_press(None, mock_event)
477
self.lobby.exhibit_banner.on_button_release(None, mock_event)
478
mock_emit.assert_called()
479
signal_name = mock_emit.call_args[0][0]
480
call_exhibit = mock_emit.call_args[0][1]
481
self.assertEqual(signal_name, "show-exhibits-clicked")
482
self.assertEqual(call_exhibit.click_url, "http://example.com")
484
def test_exhibit_with_featured_exhibit(self):
485
""" regression test for bug #1023777 """
486
sca = ObjectWithSignals()
487
sca.query_exhibits = lambda: sca.emit('exhibits', sca,
488
[lobbyview.FeaturedExhibit()])
490
with patch.object(lobbyview, 'SoftwareCenterAgent', lambda: sca):
492
self.lobby._append_banner_ads()
494
alloc = self.lobby.exhibit_banner.get_allocation()
496
mock_event.x = alloc.x
497
mock_event.y = alloc.y
498
with patch.object(self.lobby, 'emit') as mock_emit:
499
self.lobby.exhibit_banner.on_button_press(None, mock_event)
500
self.lobby.exhibit_banner.on_button_release(None, mock_event)
501
mock_emit.assert_called()
502
signal_name = mock_emit.call_args[0][0]
503
call_category = mock_emit.call_args[0][1]
504
self.assertEqual(signal_name, "category-selected")
505
self.assertEqual(call_category.name, "Our star apps")
507
365
if __name__ == "__main__":