コード例 #1
0
    def test_exhibit_with_url(self):
        # available exhibit
        exhibit = Mock()
        exhibit.package_names = ""
        exhibit.click_url = "http://example.com"
        exhibit.banner_url = "banner"
        exhibit.title_translated = ""

        sca = ObjectWithSignals()
        sca.query_exhibits = lambda: sca.emit("exhibits", sca, [exhibit])

        with patch.object(catview_gtk, "SoftwareCenterAgent", lambda: sca):
            # add the banners
            self.lobby._append_banner_ads()
            # fake click
            alloc = self.lobby.exhibit_banner.get_allocation()
            mock_event = Mock()
            mock_event.x = alloc.x
            mock_event.y = alloc.y
            with patch.object(self.lobby.exhibit_banner, "emit") as mock_emit:
                self.lobby.exhibit_banner.on_button_press(None, mock_event)
                self.lobby.exhibit_banner.on_button_release(None, mock_event)
                mock_emit.assert_called()
                signal_name = mock_emit.call_args[0][0]
                call_exhibit = mock_emit.call_args[0][1]
                self.assertEqual(signal_name, "show-exhibits-clicked")
                self.assertEqual(call_exhibit.click_url, "http://example.com")
コード例 #2
0
    def test_exhibit_with_url(self):
        # available exhibit
        exhibit = Mock()
        exhibit.package_names = ''
        exhibit.click_url = 'http://example.com'
        exhibit.banner_url = 'banner'
        exhibit.title_translated = ''

        sca = ObjectWithSignals()
        sca.query_exhibits = lambda: sca.emit('exhibits', sca, [exhibit])

        with patch.object(catview_gtk, 'SoftwareCenterAgent', lambda: sca):
            # add the banners
            self.lobby._append_banner_ads()
            # fake click
            alloc = self.lobby.exhibit_banner.get_allocation()
            mock_event = Mock()
            mock_event.x = alloc.x
            mock_event.y = alloc.y
            with patch.object(self.lobby.exhibit_banner, 'emit') as mock_emit:
                self.lobby.exhibit_banner.on_button_press(None, mock_event)
                self.lobby.exhibit_banner.on_button_release(None, mock_event)
                mock_emit.assert_called()
                signal_name = mock_emit.call_args[0][0]
                call_exhibit = mock_emit.call_args[0][1]
                self.assertEqual(signal_name, "show-exhibits-clicked")
                self.assertEqual(call_exhibit.click_url, "http://example.com")
コード例 #3
0
    def test_no_exhibit_if_not_available(self):
        """The exhibit should not be shown if the package is not available."""
        exhibit = Mock()
        exhibit.package_names = u'foobarbaz'

        sca = ObjectWithSignals()
        sca.query_exhibits = lambda: sca.emit('exhibits', sca, [exhibit])

        with patch.object(catview_gtk, 'SoftwareCenterAgent', lambda: sca):
            self.lobby._append_banner_ads()

        banner = self._get_banner_from_lobby()
        self.assertEqual(1, len(banner.exhibits))
        self.assertIsInstance(banner.exhibits[0], catview_gtk.FeaturedExhibit)
コード例 #4
0
    def test_no_exhibit_if_not_available(self):
        """The exhibit should not be shown if the package is not available."""
        exhibit = Mock()
        exhibit.package_names = u'foobarbaz'

        sca = ObjectWithSignals()
        sca.query_exhibits = lambda: sca.emit('exhibits', sca, [exhibit])

        with patch.object(catview_gtk, 'SoftwareCenterAgent', lambda: sca):
            self.lobby._append_banner_ads()

        banner = self._get_banner_from_lobby()
        self.assertEqual(1, len(banner.exhibits))
        self.assertIsInstance(banner.exhibits[0], catview_gtk.FeaturedExhibit)
コード例 #5
0
    def test_exhibit_if_available(self):
        """The exhibit should be shown if the package is available."""
        exhibit = Mock()
        exhibit.package_names = u'foobarbaz'
        exhibit.banner_url = 'banner'
        exhibit.title_translated = ''

        self.cache[u'foobarbaz'] = Mock()

        sca = ObjectWithSignals()
        sca.query_exhibits = lambda: sca.emit('exhibits', sca, [exhibit])

        with patch.object(catview_gtk, 'SoftwareCenterAgent', lambda: sca):
            self.lobby._append_banner_ads()

        banner = self._get_banner_from_lobby()
        self.assertEqual(1, len(banner.exhibits))
        self.assertIs(banner.exhibits[0], exhibit)
コード例 #6
0
    def test_exhibit_if_available(self):
        """The exhibit should be shown if the package is available."""
        exhibit = Mock()
        exhibit.package_names = u'foobarbaz'
        exhibit.banner_url = 'banner'
        exhibit.title_translated = ''

        self.cache[u'foobarbaz'] = Mock()

        sca = ObjectWithSignals()
        sca.query_exhibits = lambda: sca.emit('exhibits', sca, [exhibit])

        with patch.object(catview_gtk, 'SoftwareCenterAgent', lambda: sca):
            self.lobby._append_banner_ads()

        banner = self._get_banner_from_lobby()
        self.assertEqual(1, len(banner.exhibits))
        self.assertIs(banner.exhibits[0], exhibit)
コード例 #7
0
    def test_exhibit_if_mixed_availability(self):
        """The exhibit should be shown even if some are not available."""
        # available exhibit
        exhibit = Mock()
        exhibit.package_names = u"foobarbaz"
        exhibit.banner_url = "banner"
        exhibit.title_translated = ""

        self.cache[u"foobarbaz"] = Mock()

        # not available exhibit
        other = Mock()
        other.package_names = u"not-there"

        sca = ObjectWithSignals()
        sca.query_exhibits = lambda: sca.emit("exhibits", sca, [exhibit, other])

        with patch.object(catview_gtk, "SoftwareCenterAgent", lambda: sca):
            self.lobby._append_banner_ads()

        banner = self._get_banner_from_lobby()
        self.assertEqual(1, len(banner.exhibits))
        self.assertIs(banner.exhibits[0], exhibit)