def test_recagent_post_submit_profile(self): # NOTE: This requires a working recommender host that is reachable db = get_test_db() self.recommender_agent.connect( "submit-profile-finished", self.on_query_done) self.recommender_agent.post_submit_profile(db) self.assertServerReturnsWithNoError()
def get_test_window_confirm_remove(): # test real remove dialog icons = get_test_gtk3_icon_cache() db = get_test_db() app = application.Application("", "p7zip-full") return dependency_dialogs.confirm_remove(None, app, db, icons)
def get_test_window_apptreeview(): cache = get_test_pkg_info() db = get_test_db() icons = get_test_gtk3_icon_cache() # create a filter app_filter = appfilter.AppFilter(db, cache) app_filter.set_supported_only(False) app_filter.set_installed_only(True) # get the TREEstore store = appstore2.AppTreeStore(db, cache, icons) # populate from data cats = get_test_categories(db) for cat in cats[:3]: with ExecutionTime("query cat '%s'" % cat.name): docs = db.get_docs_from_query(cat.query) store.set_category_documents(cat, docs) # ok, this is confusing - the AppView contains the AppTreeView that # is a tree or list depending on the model app_view = appview.AppView(db, cache, icons, show_ratings=True) app_view.set_model(store) box = Gtk.VBox() box.pack_start(app_view, True, True, 0) win = get_test_window(child=box) return win
def get_test_window_appview(): db = get_test_db() cache = get_test_pkg_info() icons = get_test_gtk3_icon_cache() # create a filter app_filter = appfilter.AppFilter(db, cache) app_filter.set_supported_only(False) app_filter.set_installed_only(True) # appview enquirer = enquire.AppEnquire(cache, db) store = appstore2.AppListStore(db, cache, icons) view = appview.AppView(db, cache, icons, show_ratings=True) view.set_model(store) entry = Gtk.Entry() entry.stamp = 0 entry.connect("changed", on_entry_changed, (view, enquirer)) entry.set_text("gtk3") box = Gtk.VBox() box.pack_start(entry, False, True, 0) box.pack_start(view, True, True, 0) win = get_test_window(child=box) win.set_data("appview", view) win.set_data("entry", entry) return win
def get_test_window_availablepane(): # needed because available pane will try to get it vm = get_test_gtk3_viewmanager() assert vm is not None db = get_test_db() cache = get_test_pkg_info() icons = get_test_gtk3_icon_cache() backend = get_test_install_backend() distro = softwarecenter.distro.get_distro() manager = appmanager.get_appmanager() if manager is None: # create global AppManager instance manager = appmanager.ApplicationManager(db, backend, icons) navhistory_back_action = Gtk.Action.new("navhistory_back_action", "Back", "Back", None) navhistory_forward_action = Gtk.Action.new("navhistory_forward_action", "Forward", "Forward", None) zl = "softwarecenter.backend.zeitgeist_logger.ZeitgeistLogger"; patch(zl + ".log_install_event").start().return_value = False patch(zl + ".log_uninstall_event").start().return_value = False patch("softwarecenter.utils.is_unity_running").start().return_value = False w = availablepane.AvailablePane(cache, db, distro, icons, navhistory_back_action, navhistory_forward_action) w.init_view() w.show() win = get_test_window(child=w, width=800, height=600) # this is used later in tests win.set_data("pane", w) win.set_data("vm", vm) return win
def test_recagent_post_submit_profile(self): # NOTE: This requires a working recommender host that is reachable db = get_test_db() self.recommender_agent.connect("submit-profile-finished", self.on_query_done) self.recommender_agent.post_submit_profile(db) self.assertServerReturnsWithNoError()
def test_not_automatic_version(self): db = get_test_db() app = Application("", "software-center") details = app.get_details(db) normal_version = self._make_version(not_automatic=False) not_automatic_version = self._make_version(not_automatic=True) details._pkg.versions = [normal_version, not_automatic_version] # force not-automatic with invalid data self.assertRaises(ValueError, details.force_not_automatic_archive_suite, "random-string") # force not-automatic with valid data self.assertTrue( details.force_not_automatic_archive_suite( not_automatic_version.origins[0].archive)) # ensure we get the description of the not-automatic version self.assertEqual(details.description, not_automatic_version.description) self.assertEqual(details.summary, not_automatic_version.summary) self.assertEqual(details.version, not_automatic_version.version) self.assertEqual(app.archive_suite, not_automatic_version.origins[0].archive) # clearing works details.force_not_automatic_archive_suite("") self.assertEqual(app.archive_suite, "")
def setUp(self): # create a fake database to simualte a run of software-center-agent # create a StoreDatabase and add our other db self.db = get_test_db() self.db.add_database(xapian.Database(TEST_DB)) self.db.open(use_axi=True) self.enquire = AppEnquire(self.db._aptcache, self.db)
def test_generic(self): from softwarecenter.backend.channel import ChannelsManager db = get_test_db() m = ChannelsManager(db) channels = m._get_channels_from_db(installed_only=False) self.assertNotEqual(channels, []) channels_installed = m._get_channels_from_db(installed_only=True) self.assertNotEqual(channels_installed, [])
def test_utils_get_installed_apps_list(self): db = get_test_db() # installed pkgs installed_pkgs = get_installed_package_list() # the installed apps installed_apps = get_installed_apps_list(db) self.assertTrue(len(installed_apps) > 0) self.assertTrue(len(installed_pkgs) > len(installed_apps))
def test_mocked_recagent_post_submit_profile(self, mock_spawn_helper_run): recommender_agent = RecommenderAgent() recommender_agent._calc_profile_id = lambda profile: "i-am-random" db = get_test_db() recommender_agent.post_submit_profile(db) args, kwargs = mock_spawn_helper_run.call_args # ensure we have packages in the package list and the # kwargs have the names we expect self.assertNotEqual(kwargs['data'][0]['package_list'], [])
def test_aptchannels(self): from softwarecenter.backend.channel_impl.aptchannels import ( AptChannelsManager) db = get_test_db() m = AptChannelsManager(db) channels = m.channels self.assertNotEqual(channels, []) channels_installed = m.channels_installed_only self.assertNotEqual(channels_installed, [])
def test_regression_lp1041004(self): from softwarecenter.ui.gtk3.views import appdetailsview db = get_test_db() cache = get_test_pkg_info() icons = get_test_gtk3_icon_cache() distro = get_distro() view = appdetailsview.AppDetailsView(db, distro, icons, cache) cache.emit("query-total-size-on-install-done", "apt", 10, 10) do_events_with_sleep() self.assertEqual(view.totalsize_info.value_label.get_text(), "")
def test_appdetails(self): app = Application("Foo app", "dpkg") db = get_test_db() appdetails = app.get_details(db) # patching properties is a bit cumbersome with patch.object(AppDetails, "raw_price") as mock_price: with patch.object(AppDetails, "currency") as mock_currency: mock_price.__get__ = Mock(return_value="2.99") mock_currency.__get__ = Mock(return_value="USD") self.assertEqual("USD 2.99", appdetails.price)
def test_memleak_catview(self): db = get_test_db() win = get_test_window_catview(db) lobby = win.get_data("lobby") # get baseline do_events_with_sleep() with TraceMemoryUsage("LobbyView.on_db_reopen()"): for i in range(self.ITERATIONS): lobby._on_db_reopen(db) do_events_with_sleep()
def setUp(self): # get required test stuff self.db = get_test_db() self.backend = Mock() self.distro = get_distro() self.datadir = softwarecenter.paths.datadir self.icons = get_test_gtk3_icon_cache() # create it once, it becomes global instance if get_appmanager() is None: ApplicationManager(self.db, self.backend, self.icons)
def test_not_automatic_channel_support(self): db = get_test_db() app = Application("", "software-center") details = app.get_details(db) versions = [self._make_version(not_automatic=True), self._make_version(not_automatic=False)] details._pkg.versions = versions details._pkg.candidate = versions[1] self.assertEqual( details.get_not_automatic_archive_versions(), [(versions[1].version, "precise"), (versions[0].version, "precise-backports")], )
def setUp(self): # get required test stuff self.db = get_test_db() self.backend = Mock() self.distro = get_distro() self.datadir = softwarecenter.paths.datadir self.icons = get_test_gtk3_icon_cache() # create it once, it becomes global instance if get_appmanager() is None: ApplicationManager( self.db, self.backend, self.icons)
def get_test_window_globalpane(): vm = get_test_gtk3_viewmanager() db = get_test_db() cache = get_test_pkg_info() icons = get_test_gtk3_icon_cache() p = globalpane.GlobalPane(vm, db, cache, icons) win = get_test_window(child=p) win.set_data("pane", p) return win
def test_memleak_subcatview(self): db = get_test_db() win = get_test_window_catview(db) lobby = win.get_data("lobby") cat = [cat for cat in lobby.categories if cat.name == "Internet"][0] subcat = win.get_data("subcat") # get baseline subcat.set_subcategory(cat) do_events_with_sleep() with TraceMemoryUsage("SubcategoryView.set_subcategory()"): for i in range(self.ITERATIONS): subcat._set_subcategory(cat, 0) do_events_with_sleep()
def test_not_automatic_channel_support(self): db = get_test_db() app = Application("", "software-center") details = app.get_details(db) versions = [ self._make_version(not_automatic=True), self._make_version(not_automatic=False) ] details._pkg.versions = versions details._pkg.candidate = versions[1] self.assertEqual(details.get_not_automatic_archive_versions(), [(versions[1].version, "precise"), (versions[0].version, "precise-backports")])
def get_test_window_dependency_dialog(): icons = get_test_gtk3_icon_cache() db = get_test_db() depends = ["apt", "synaptic"] app = application.Application("", "software-center") primary = "primary text" button_text = "button_text" dia = dependency_dialogs._get_confirm_internal_dialog( parent=None, app=app, db=db, icons=icons, primary=primary, button_text=button_text, depends=depends, cache=db._aptcache) return dia
def test_multiple_version_pkg_states(self): db = get_test_db() app = Application("", "software-center") details = app.get_details(db) normal_version = self._make_version(not_automatic=False) not_automatic_version = self._make_version(not_automatic=True) details._pkg.versions = [normal_version, not_automatic_version] details._pkg.installed = normal_version details._pkg.is_installed = True # disabled for now # details._pkg.is_upgradable = True self.assertEqual(details.pkg_state, PkgStates.INSTALLED) app.archive_suite = not_automatic_version self.assertEqual(details.pkg_state, PkgStates.FORCE_VERSION)
def get_test_screenshot_thumbnail_window(): class CycleState(object): def __init__(self): self.app_n = 0 self.apps = [application.Application("Movie Player", "totem"), application.Application("Comix", "comix"), application.Application("Gimp", "gimp"), #application.Application("ACE", "uace"), ] def testing_cycle_apps(widget, thumb, db, cycle_state): d = cycle_state.apps[cycle_state.app_n].get_details(db) if cycle_state.app_n + 1 < len(cycle_state.apps): cycle_state.app_n += 1 else: cycle_state.app_n = 0 thumb.fetch_screenshots(d) return True cycle_state = CycleState() vb = Gtk.VBox(spacing=6) win = get_test_window(child=vb) icons = get_test_gtk3_icon_cache() distro = softwarecenter.distro.get_distro() t = thumbnail.ScreenshotGallery(distro, icons) t.connect('draw', t.draw) frame = containers.FramedBox() frame.add(t) win.set_data("screenshot_thumbnail_widget", t) b = Gtk.Button(label='A button for cycle testing') vb.pack_start(b, False, False, 8) win.set_data("screenshot_button_widget", b) vb.pack_start(frame, True, True, 0) win.set_data("screenshot_thumbnail_cycle_test_button", b) db = get_test_db() win.show_all() testing_cycle_apps(None, t, db, cycle_state) b.connect("clicked", testing_cycle_apps, t, db, cycle_state) return win
def get_test_window_historypane(): # needed because available pane will try to get it vm = get_test_gtk3_viewmanager() vm # make pyflakes happy db = get_test_db() cache = get_test_pkg_info() icons = get_test_gtk3_icon_cache() widget = historypane.HistoryPane(cache, db, None, icons) widget.show() win = get_test_window(child=widget) widget.init_view() return win
def test_multiple_version_pkg_states(self): db = get_test_db() app = Application("", "software-center") details = app.get_details(db) normal_version = self._make_version(not_automatic=False) not_automatic_version = self._make_version(not_automatic=True) details._pkg.versions = [normal_version, not_automatic_version] details._pkg.installed = normal_version details._pkg.is_installed = True # disabled for now #details._pkg.is_upgradable = True self.assertEqual(details.pkg_state, PkgStates.INSTALLED) app.archive_suite = not_automatic_version self.assertEqual(details.pkg_state, PkgStates.FORCE_VERSION)
def get_test_window_viewswitcher(): cache = get_test_pkg_info() db = get_test_db() icons = get_test_gtk3_icon_cache() manager = get_test_gtk3_viewmanager() view = viewswitcher.ViewSwitcher(manager, db, cache, icons) scroll = Gtk.ScrolledWindow() box = Gtk.VBox() box.pack_start(scroll, True, True, 0) win = get_test_window(child=box) scroll.add_with_viewport(view) return win
def test_multiple_versions_sorting(self): db = get_test_db() app = Application("", "software-center") details = AppDetails(db, application=app) details._pkg = Mock() details._pkg.installed = Mock() details._pkg.installed.version = "2.0" self.assertEqual(details.version, "2.0") v0 = {"version": None} v1 = {"version": "1.0"} v2 = {"version": "2.0"} v3 = {"version": "3.0"} screenshots_list = [v0, v1, v2, v3] res = details._sort_screenshots_by_best_version(screenshots_list) self.assertEqual(res, [v2, v1, v0])
def test_hardware_requirements_satisfied(self): with patch.object(AppDetails, "hardware_requirements") as mock_hw: # setup env db = get_test_db() app = Application("", "software-center") mock_hw.__get__ = Mock() # not good mock_hw.__get__.return_value = {"hardware::gps": "no", "hardware::video:opengl": "yes"} details = AppDetails(db, application=app) self.assertFalse(details.hardware_requirements_satisfied) # this if good mock_hw.__get__.return_value = {"hardware::video:opengl": "yes"} self.assertTrue(details.hardware_requirements_satisfied) # empty is satisfied mock_hw.__get__.return_value = {} self.assertTrue(details.hardware_requirements_satisfied)
def test_region_requirements_satisfied(self, mock_region_discover): mock_region_discover.return_value = {"country": "Germany", "countrycode": "DE"} with patch.object(AppDetails, "tags") as mock_tags: # setup env db = get_test_db() app = Application("", "software-center") mock_tags.__get__ = Mock() # not good mock_tags.__get__.return_value = [REGIONTAG + "ZM"] details = AppDetails(db, application=app) self.assertFalse(details.region_requirements_satisfied) # this if good mock_tags.__get__.return_value = [REGIONTAG + "DE"] self.assertTrue(details.region_requirements_satisfied) # empty is satisfied mock_tags.__get__.return_value = ["other::tag"] self.assertTrue(details.region_requirements_satisfied)
def test_no_axi_cataloged_time_info_yet(self): """ ensure that we show "whats new" DB_CATALOGED_TIME data if there is no x-a-i yet """ db = get_test_db() cache = db._aptcache icons = get_test_gtk3_icon_cache() apps_filter = AppFilter(db, cache) # simulate a fresh install with no catalogedtime info in a-x-i if "catalogedtime" in db._axi_values: del db._axi_values["catalogedtime"] # create it view = lobbyview.LobbyView(cache, db, icons, softwarecenter.distro.get_distro(), apps_filter) view.show_all() # and ensure its visible self.assertTrue(view.whats_new_frame.get_property("visible"))
def test_not_automatic_version(self): db = get_test_db() app = Application("", "software-center") details = app.get_details(db) normal_version = self._make_version(not_automatic=False) not_automatic_version = self._make_version(not_automatic=True) details._pkg.versions = [normal_version, not_automatic_version] # force not-automatic with invalid data self.assertRaises(ValueError, details.force_not_automatic_archive_suite, "random-string") # force not-automatic with valid data self.assertTrue(details.force_not_automatic_archive_suite(not_automatic_version.origins[0].archive)) # ensure we get the description of the not-automatic version self.assertEqual(details.description, not_automatic_version.description) self.assertEqual(details.summary, not_automatic_version.summary) self.assertEqual(details.version, not_automatic_version.version) self.assertEqual(app.archive_suite, not_automatic_version.origins[0].archive) # clearing works details.force_not_automatic_archive_suite("") self.assertEqual(app.archive_suite, "")
def test_region_requirements_satisfied(self, mock_region_discover): mock_region_discover.return_value = { 'country': 'Germany', 'countrycode': 'DE', } with patch.object(AppDetails, 'tags') as mock_tags: # setup env db = get_test_db() app = Application("", "software-center") mock_tags.__get__ = Mock() # not good mock_tags.__get__.return_value = [REGIONTAG + "ZM"] details = AppDetails(db, application=app) self.assertFalse(details.region_requirements_satisfied) # this if good mock_tags.__get__.return_value = [REGIONTAG + "DE"] self.assertTrue(details.region_requirements_satisfied) # empty is satisfied mock_tags.__get__.return_value = ["other::tag"] self.assertTrue(details.region_requirements_satisfied)
def get_test_window_recommendations(panel_type="lobby"): cache = get_test_pkg_info() db = get_test_db() icons = get_test_gtk3_icon_cache() from softwarecenter.ui.gtk3.models.appstore2 import AppPropertiesHelper properties_helper = AppPropertiesHelper(db, cache, icons) if panel_type is "lobby": view = recommendations.RecommendationsPanelLobby(db, properties_helper) elif panel_type is "category": cats = get_test_categories(db) view = recommendations.RecommendationsPanelCategory( db, properties_helper, cats[0]) else: # panel_type is "details": view = recommendations.RecommendationsPanelDetails( db, properties_helper) win = get_test_window(child=view, width=600, height=300) win.set_data("rec_panel", view) return win
def test_app_enquire(self): db = get_test_db() cache = get_test_pkg_info() xfilter = AppFilter(cache, db) enquirer = AppEnquire(cache, db) terms = [ "app", "this", "the", "that", "foo", "tool", "game", "graphic", "ubuntu", "debian", "gtk", "this", "bar", "baz" ] # run a bunch of the queries in parallel for nonblocking in [False, True]: for i in range(10): for term in terms: enquirer.set_query(search_query=xapian.Query(term), limit=0, filter=xfilter, nonblocking_load=nonblocking) # give the threads a bit of time time.sleep(5)
def test_hardware_requirements_satisfied(self): with patch.object(AppDetails, 'hardware_requirements') as mock_hw: # setup env db = get_test_db() app = Application("", "software-center") mock_hw.__get__ = Mock() # not good mock_hw.__get__.return_value = { 'hardware::gps': 'no', 'hardware::video:opengl': 'yes', } details = AppDetails(db, application=app) self.assertFalse(details.hardware_requirements_satisfied) # this if good mock_hw.__get__.return_value = { 'hardware::video:opengl': 'yes', } self.assertTrue(details.hardware_requirements_satisfied) # empty is satisfied mock_hw.__get__.return_value = {} self.assertTrue(details.hardware_requirements_satisfied)
def get_test_window_recommendations(panel_type="lobby"): cache = get_test_pkg_info() db = get_test_db() icons = get_test_gtk3_icon_cache() from softwarecenter.ui.gtk3.models.appstore2 import AppPropertiesHelper properties_helper = AppPropertiesHelper(db, cache, icons) if panel_type is "lobby": view = recommendations.RecommendationsPanelLobby( db, properties_helper) elif panel_type is "category": cats = get_test_categories(db) view = recommendations.RecommendationsPanelCategory( db, properties_helper, cats[0]) else: # panel_type is "details": view = recommendations.RecommendationsPanelDetails( db, properties_helper) win = get_test_window(child=view, width=600, height=300) win.set_data("rec_panel", view) return win
def test_app_enquire(self): db = get_test_db() cache = get_test_pkg_info() xfilter = AppFilter(cache, db) enquirer = AppEnquire(cache, db) terms = [ "app", "this", "the", "that", "foo", "tool", "game", "graphic", "ubuntu", "debian", "gtk", "this", "bar", "baz"] # run a bunch of the queries in parallel for nonblocking in [False, True]: for i in range(10): for term in terms: enquirer.set_query( search_query=xapian.Query(term), limit=0, filter=xfilter, nonblocking_load=nonblocking) # give the threads a bit of time time.sleep(5)
def get_test_window_installedpane(): # needed because available pane will try to get it vm = get_test_gtk3_viewmanager() vm # make pyflakes happy db = get_test_db() cache = get_test_pkg_info() icons = get_test_gtk3_icon_cache() w = installedpane.InstalledPane(cache, db, 'Ubuntu', icons) w.show() # init the view w.init_view() w.state.channel = channel.AllInstalledChannel() view_state = displaystate.DisplayState() view_state.channel = channel.AllInstalledChannel() w.display_overview_page(view_state) win = get_test_window(child=w) win.set_data("pane", w) return win
def test_multiple_versions_sorting(self): db = get_test_db() app = Application("", "software-center") details = AppDetails(db, application=app) details._pkg = Mock() details._pkg.installed = Mock() details._pkg.installed.version = "2.0" self.assertEqual(details.version, "2.0") v0 = { "version": None, } v1 = { "version": "1.0", } v2 = { "version": "2.0", } v3 = { "version": "3.0", } screenshots_list = [v0, v1, v2, v3] res = details._sort_screenshots_by_best_version(screenshots_list) self.assertEqual(res, [v2, v1, v0])
def test_track_db_open(self): tmpdir = tempfile.mkdtemp() tmpstamp = os.path.join(tmpdir, "update-stamp") open(tmpstamp, "w") softwarecenter.paths.APT_XAPIAN_INDEX_UPDATE_STAMP_PATH = tmpstamp softwarecenter.paths.APT_XAPIAN_INDEX_DB_PATH = \ softwarecenter.paths.XAPIAN_PATH db = get_test_db() db._axi_stamp_monitor = None db._on_axi_stamp_changed = Mock() self.assertFalse(db._on_axi_stamp_changed.called) db.open(use_axi=True) do_events() self.assertFalse(db._on_axi_stamp_changed.called) do_events() #print "modifiyng stampfile: ", tmpstamp os.utime(tmpstamp, (0, 0)) # wait up to 5s until the gvfs delivers the signal for i in range(50): do_events() time.sleep(0.1) if db._on_axi_stamp_changed.called: break self.assertTrue(db._on_axi_stamp_changed.called)