~mvo/software-center/fix-size-calc-race

« back to all changes in this revision

Viewing changes to tests/gtk3/test_catview.py

* lp:~mvo/software-center/support-multiple-exhibit-images:
  - add support for multiple images in the exhibit banners
    (LP: #920542)

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
from tests.utils import (
7
7
    do_events,
8
8
    do_events_with_sleep,
9
 
    FakedCache,
10
9
    get_test_db,
11
10
    get_test_gtk3_icon_cache,
12
11
    make_recommender_agent_recommend_me_dict,
13
 
    ObjectWithSignals,
14
12
    setup_test_env,
15
13
)
16
14
setup_test_env()
19
17
import softwarecenter.paths
20
18
 
21
19
from softwarecenter.db.appfilter import AppFilter
22
 
from softwarecenter.db.database import StoreDatabase
23
20
from softwarecenter.enums import (SortMethods,
24
21
                                  TransactionTypes,
25
22
                                  RecommenderFeedbackActions)
35
32
    def setUpClass(cls):
36
33
        cls.db = get_test_db()
37
34
 
38
 
    def setUp(self):
 
35
    def setUp(self, selected_category=None):
39
36
        self._cat = None
40
37
        self._app = None
41
 
        self.win = get_test_window_catview(self.db)
 
38
        self.win = get_test_window_catview(self.db, selected_category)
42
39
        self.addCleanup(self.win.destroy)
43
40
        self.notebook = self.win.get_child()
44
41
        self.lobby = self.win.get_data("lobby")
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):
125
 
        self._cat = None
126
 
        self._app = None
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
139
129
 
140
130
    def test_recommended_for_you_opt_in_display(self):
371
361
                                    mock_result)
372
362
        do_events()
373
363
 
374
 
 
375
 
class ExhibitsTestCase(unittest.TestCase):
376
 
    """The test suite for the exhibits carousel."""
377
 
 
378
 
    def setUp(self):
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)
384
 
 
385
 
    def _get_banner_from_lobby(self):
386
 
        return self.lobby.vbox.get_children()[-1].get_child()
387
 
 
388
 
    def test_featured_exhibit_by_default(self):
389
 
        """Show the featured exhibit before querying the remote service."""
390
 
        self.lobby._append_banner_ads()
391
 
 
392
 
        banner = self._get_banner_from_lobby()
393
 
        self.assertEqual(1, len(banner.exhibits))
394
 
        self.assertIsInstance(banner.exhibits[0], lobbyview.FeaturedExhibit)
395
 
 
396
 
    def test_no_exhibit_if_not_available(self):
397
 
        """The exhibit should not be shown if the package is not available."""
398
 
        exhibit = Mock()
399
 
        exhibit.package_names = u'foobarbaz'
400
 
 
401
 
        sca = ObjectWithSignals()
402
 
        sca.query_exhibits = lambda: sca.emit('exhibits', sca, [exhibit])
403
 
 
404
 
        with patch.object(lobbyview, 'SoftwareCenterAgent', lambda: sca):
405
 
            self.lobby._append_banner_ads()
406
 
 
407
 
        banner = self._get_banner_from_lobby()
408
 
        self.assertEqual(1, len(banner.exhibits))
409
 
        self.assertIsInstance(banner.exhibits[0], lobbyview.FeaturedExhibit)
410
 
 
411
 
    def test_exhibit_if_available(self):
412
 
        """The exhibit should be shown if the package is available."""
413
 
        exhibit = Mock()
414
 
        exhibit.package_names = u'foobarbaz'
415
 
        exhibit.banner_url = 'banner'
416
 
        exhibit.title_translated = ''
417
 
 
418
 
        self.cache[u'foobarbaz'] = Mock()
419
 
 
420
 
        sca = ObjectWithSignals()
421
 
        sca.query_exhibits = lambda: sca.emit('exhibits', sca, [exhibit])
422
 
 
423
 
        with patch.object(lobbyview, 'SoftwareCenterAgent', lambda: sca):
424
 
            self.lobby._append_banner_ads()
425
 
 
426
 
        banner = self._get_banner_from_lobby()
427
 
        self.assertEqual(1, len(banner.exhibits))
428
 
        self.assertIs(banner.exhibits[0], exhibit)
429
 
 
430
 
    def test_exhibit_if_mixed_availability(self):
431
 
        """The exhibit should be shown even if some are not available."""
432
 
        # available exhibit
433
 
        exhibit = Mock()
434
 
        exhibit.package_names = u'foobarbaz'
435
 
        exhibit.banner_url = 'banner'
436
 
        exhibit.title_translated = ''
437
 
 
438
 
        self.cache[u'foobarbaz'] = Mock()
439
 
 
440
 
        # not available exhibit
441
 
        other = Mock()
442
 
        other.package_names = u'not-there'
443
 
 
444
 
        sca = ObjectWithSignals()
445
 
        sca.query_exhibits = lambda: sca.emit('exhibits', sca,
446
 
                                              [exhibit, other])
447
 
 
448
 
        with patch.object(lobbyview, 'SoftwareCenterAgent', lambda: sca):
449
 
            self.lobby._append_banner_ads()
450
 
 
451
 
        banner = self._get_banner_from_lobby()
452
 
        self.assertEqual(1, len(banner.exhibits))
453
 
        self.assertIs(banner.exhibits[0], exhibit)
454
 
 
455
 
    def test_exhibit_with_url(self):
456
 
        # available exhibit
457
 
        exhibit = Mock()
458
 
        exhibit.package_names = ''
459
 
        exhibit.click_url = 'http://example.com'
460
 
        exhibit.banner_url = 'banner'
461
 
        exhibit.title_translated = ''
462
 
 
463
 
        sca = ObjectWithSignals()
464
 
        sca.query_exhibits = lambda: sca.emit('exhibits', sca,
465
 
                                              [exhibit])
466
 
 
467
 
        with patch.object(lobbyview, 'SoftwareCenterAgent', lambda: sca):
468
 
            # add the banners
469
 
            self.lobby._append_banner_ads()
470
 
            # fake click
471
 
            alloc = self.lobby.exhibit_banner.get_allocation()
472
 
            mock_event = Mock()
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")
483
 
 
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()])
489
 
 
490
 
        with patch.object(lobbyview, 'SoftwareCenterAgent', lambda: sca):
491
 
            # add the banners
492
 
            self.lobby._append_banner_ads()
493
 
            # fake click
494
 
            alloc = self.lobby.exhibit_banner.get_allocation()
495
 
            mock_event = Mock()
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")
506
364
        
507
365
if __name__ == "__main__":
508
366
    unittest.main()