def _make_fake_scagent(self, available_data, available_for_me_data): sca = ObjectWithSignals() sca.query_available = lambda **kwargs: GLib.timeout_add( 100, lambda: sca.emit('available', sca, available_data)) sca.query_available_for_me = lambda **kwargs: GLib.timeout_add( 100, lambda: sca.emit('available-for-me', sca, available_for_me_data)) return sca
def test_exhibit_with_url(self): # available exhibit exhibit = Mock() exhibit.package_names = '' exhibit.click_url = 'http://example.com' exhibit.banner_urls = ['banner'] exhibit.title_translated = '' sca = ObjectWithSignals() sca.query_exhibits = lambda: sca.emit('exhibits', sca, [exhibit]) with patch.object(lobbyview, '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")
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(lobbyview, '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], lobbyview.FeaturedExhibit)
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_urls = ['banner'] exhibit.title_translated = '' self.cache[u'foobarbaz'] = Mock() sca = ObjectWithSignals() sca.query_exhibits = lambda: sca.emit('exhibits', sca, [exhibit]) with patch.object(lobbyview, '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)
def test_exhibit_with_featured_exhibit(self): """ regression test for bug #1023777 """ sca = ObjectWithSignals() sca.query_exhibits = lambda: sca.emit('exhibits', sca, [lobbyview.FeaturedExhibit()]) with patch.object(lobbyview, '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, '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_category = mock_emit.call_args[0][1] self.assertEqual(signal_name, "category-selected") self.assertEqual(call_category.name, "Our star apps")
def test_multiple_images(self): downloader = ObjectWithSignals() downloader.download_file = lambda *args, **kwargs: downloader.emit( "file-download-complete", downloader, os.path.basename(args[0])) with patch("softwarecenter.ui.gtk3.widgets.exhibits." "SimpleFileDownloader", lambda: downloader): renderer = _HtmlRenderer() mock_exhibit = Mock() mock_exhibit.banner_urls = [ "http://example.com/path1/banner1.png", "http://example.com/path2/banner2.png", ] mock_exhibit.html = "url('/path1/banner1.png')#"\ "url('/path2/banner2.png')" renderer.set_exhibit(mock_exhibit) # assert the stuff we expected to get downloaded got downloaded self.assertEqual( renderer._downloaded_banner_images, ["banner1.png", "banner2.png"]) # test that the path mangling worked self.assertEqual( mock_exhibit.html, "url('banner1.png')#url('banner2.png')")
def test_multiple_images(self): downloader = ObjectWithSignals() downloader.download_file = lambda *args, **kwargs: downloader.emit( "file-download-complete", downloader, os.path.basename(args[0])) with patch( "softwarecenter.ui.gtk3.widgets.exhibits." "SimpleFileDownloader", lambda: downloader): renderer = _HtmlRenderer() mock_exhibit = Mock() mock_exhibit.banner_urls = [ "http://example.com/path1/banner1.png", "http://example.com/path2/banner2.png", ] mock_exhibit.html = "url('/path1/banner1.png')#"\ "url('/path2/banner2.png')" renderer.set_exhibit(mock_exhibit) # assert the stuff we expected to get downloaded got downloaded self.assertEqual(renderer._downloaded_banner_images, ["banner1.png", "banner2.png"]) # test that the path mangling worked self.assertEqual(mock_exhibit.html, "url('banner1.png')#url('banner2.png')")