def test_app_icon_loading(self):
     # get icon
     self.set_mock_app_and_details(
         cached_icon_file_path="download-icon-test", icon="favicon.ico",
         icon_url="http://de.wikipedia.org/favicon.ico")
     self.view.show_app(self.view.app)
     do_events()
Example #2
0
    def test_appmanager(self):
        app_manager = get_appmanager()
        self.assertNotEqual(app_manager, None)
        # test interface
        app_manager.reload()
        app = Application("", "2vcard")
        # call and ensure the stuff is passed to the backend
        app_manager.install(app, [], [])
        self.assertTrue(self.backend.install.called)

        app_manager.remove(app, [], [])
        self.assertTrue(self.backend.remove.called)

        app_manager.upgrade(app, [], [])
        self.assertTrue(self.backend.upgrade.called)

        app_manager.apply_changes(app, [], [])
        self.assertTrue(self.backend.apply_changes.called)

        app_manager.enable_software_source(app)
        self.assertTrue(self.backend.enable_component.called)

        app_manager.reinstall_purchased(app)
        self.assertTrue(self.backend.add_repo_add_key_and_install_app.called)

        # buy is special as it needs help from the purchase view
        app_manager.connect("purchase-requested", self._on_purchase_requested)
        app_manager.buy_app(app)
        self.assertTrue(self._purchase_requested_signal)
        do_events()
Example #3
0
    def test_app_view(self):
        from softwarecenter.ui.gtk3.views.appview import get_test_window
        enquirer = AppEnquire(self.cache, self.db)
        enquirer.set_query(xapian.Query(""),
                           sortmode=SortMethods.BY_CATALOGED_TIME,
                           limit=10,
                           nonblocking_load=False)

        # get test window
        win = get_test_window()
        appview = win.get_data("appview")
        # set matches
        appview.clear_model()
        appview.display_matches(enquirer.matches)
        do_events()
        # verify that the order is actually the correct one
        model = appview.tree_view.get_model()
        docs_in_model = [item[0] for item in model]
        docs_from_enquirer = [m.document for m in enquirer.matches]
        self.assertEqual(len(docs_in_model), 
                         len(docs_from_enquirer))
        for i in range(len(docs_in_model)):
            self.assertEqual(self.db.get_pkgname(docs_in_model[i]),
                             self.db.get_pkgname(docs_from_enquirer[i]))
        win.destroy()
 def test_add_where_is_it(self):
     app = Application("", "software-center")
     self.view.show_app(app)
     self.view._add_where_is_it_commandline("apt")
     do_events()
     self.view._add_where_is_it_launcher("/usr/share/applications/ubuntu-software-center.desktop")
     do_events()
    def _make_statusbar_view_for_state(self, state):
        app_details = make_purchased_app_details(db=self.db)
        # XXX 2011-01-23 It's unfortunate we need multiple mocks to test this
        # correctly, but I don't know the code well enough to refactor
        # dependencies yet so that it wouldn't be necessary. In this case, we
        # need a *real* app details object for displaying in the view, but want
        # to specify its state for the purpose of the test. As an Application
        # normally loads its details from the database, we patch
        # Application.get_details also.  Patch app_details.pkg_state for the
        # test.
        pkg_state_fn = 'softwarecenter.db.application.AppDetails.pkg_state'
        pkg_state_patcher = patch(pkg_state_fn)
        self.addCleanup(pkg_state_patcher.stop)
        mock_pkg_state = pkg_state_patcher.start()
        mock_pkg_state.__get__ = Mock(return_value=state)

        get_details_fn = 'softwarecenter.db.application.Application.get_details'
        get_details_patcher = patch(get_details_fn)
        self.addCleanup(get_details_patcher.stop)
        mock_get_details = get_details_patcher.start()
        mock_get_details.return_value = app_details

        app = app_details._app
        details_view = self.win.get_data("view")
        details_view.show_app(app)
        do_events()

        statusbar_view = details_view.pkg_statusbar
        statusbar_view.configure(app_details, state)

        return statusbar_view
 def test_show_hardware_requirements(self):
     self.app_mock.details.hardware_requirements = {
         'hardware::video:opengl': 'yes',
         'hardware::gps': 'no',
     }
     self.app_mock.details.hardware_requirements_satisfied = False
     self.view.show_app(self.app_mock)
     do_events()
     # ensure we have the data
     self.assertTrue(
         self.view.hardware_info.value_label.get_property("visible"))
     self.assertEqual(type(HardwareRequirementsBox()),
                      type(self.view.hardware_info.value_label))
     self.assertEqual(self.view.hardware_info.key, _("Also requires"))
     # ensure that the button is correct
     self.assertEqual(self.view.pkg_statusbar.button.get_label(),
                      "Install Anyway")
     # and again for purchase
     self.app_mock.details.pkg_state = PkgStates.NEEDS_PURCHASE
     self.view.show_app(self.app_mock)
     self.assertEqual(self.view.pkg_statusbar.button.get_label(),
                      _(u"Buy Anyway\u2026").encode("utf-8"))
     # check if the warning bar is displayed
     self.assertTrue(self.view.pkg_warningbar.get_property("visible"))
     self.assertEqual(
         self.view.pkg_warningbar.label.get_text(),
         _('This software requires a GPS, '
           'but the computer does not have one.'))
Example #7
0
 def test_show_hardware_requirements(self):
     self.app_mock.details.hardware_requirements = { 
         'hardware::video:opengl' : 'yes',
         'hardware::gps' : 'no',
         }
     self.app_mock.details.hardware_requirements_satisfied = False
     self.view.show_app(self.app_mock)
     do_events()
     # ensure we have the data
     self.assertTrue(
         self.view.hardware_info.value_label.get_property("visible"))
     self.assertEqual(
         type(HardwareRequirementsBox()),
         type(self.view.hardware_info.value_label))
     self.assertEqual(
         self.view.hardware_info.key, _("Also requires"))
     # ensure that the button is correct
     self.assertEqual(
         self.view.pkg_statusbar.button.get_label(), "Install Anyway")
     # and again for purchase
     self.app_mock.details.pkg_state = PkgStates.NEEDS_PURCHASE
     self.view.show_app(self.app_mock)
     self.assertEqual(
         self.view.pkg_statusbar.button.get_label(), 
         _(u"Buy Anyway\u2026").encode("utf-8"))
     # check if the warning bar is displayed
     self.assertTrue(self.view.pkg_warningbar.get_property("visible"))
     self.assertEqual(self.view.pkg_warningbar.label.get_text(),
                      _('This software requires a GPS, '
                        'but the computer does not have one.'))
Example #8
0
 def test_add_where_is_it(self):
     app = Application("", "software-center")
     self.view.show_app(app)
     self.view._add_where_is_it_commandline("apt")
     do_events()
     self.view._add_where_is_it_launcher("/usr/share/applications/ubuntu-software-center.desktop")
     do_events()
Example #9
0
    def _make_statusbar_view_for_state(self, state):
        app_details = make_purchased_app_details(db=self.db)
        # XXX 2011-01-23 It's unfortunate we need multiple mocks to test this
        # correctly, but I don't know the code well enough to refactor
        # dependencies yet so that it wouldn't be necessary. In this case, we
        # need a *real* app details object for displaying in the view, but want
        # to specify its state for the purpose of the test. As an Application
        # normally loads its details from the database, we patch
        # Application.get_details also.  Patch app_details.pkg_state for the
        # test.
        pkg_state_fn = 'softwarecenter.db.application.AppDetails.pkg_state'
        pkg_state_patcher = patch(pkg_state_fn)
        self.addCleanup(pkg_state_patcher.stop)
        mock_pkg_state = pkg_state_patcher.start()
        mock_pkg_state.__get__ = Mock(return_value=state)

        get_details_fn = 'softwarecenter.db.application.Application.get_details'
        get_details_patcher = patch(get_details_fn)
        self.addCleanup(get_details_patcher.stop)
        mock_get_details = get_details_patcher.start()
        mock_get_details.return_value = app_details

        app = app_details._app
        details_view = self.win.get_data("view")
        details_view.show_app(app)
        do_events()

        statusbar_view = details_view.pkg_statusbar
        statusbar_view.configure(app_details, state)

        return statusbar_view
    def test_appmanager(self):
        app_manager = get_appmanager()
        self.assertNotEqual(app_manager, None)
        # test interface
        app_manager.reload()
        app = Application("", "2vcard")
        # call and ensure the stuff is passed to the backend
        app_manager.install(app, [], [])
        self.assertTrue(self.backend.install.called)

        app_manager.remove(app, [], [])
        self.assertTrue(self.backend.remove.called)

        app_manager.upgrade(app, [], [])
        self.assertTrue(self.backend.upgrade.called)

        app_manager.apply_changes(app, [], [])
        self.assertTrue(self.backend.apply_changes.called)

        app_manager.enable_software_source(app)
        self.assertTrue(self.backend.enable_component.called)

        app_manager.reinstall_purchased(app)
        self.assertTrue(self.backend.add_repo_add_key_and_install_app.called)

        # buy is special as it needs help from the purchase view
        app_manager.connect("purchase-requested", self._on_purchase_requested)
        app_manager.buy_app(app)
        self.assertTrue(self._purchase_requested_signal)
        do_events()
Example #11
0
    def test_new_no_sort_info_yet(self):
        # ensure that we don't show a empty "whats new" category
        # see LP: #865985
        from softwarecenter.testutils import get_test_db
        db = get_test_db()
        cache = db._aptcache
        # simulate a fresh install with no catalogedtime info
        del db._axi_values["catalogedtime"]

        from softwarecenter.testutils import get_test_gtk3_icon_cache
        icons = get_test_gtk3_icon_cache()

        from softwarecenter.db.appfilter import AppFilter
        apps_filter = AppFilter(db, cache)

        from softwarecenter.distro import get_distro
        from softwarecenter.ui.gtk3.views.catview_gtk import LobbyViewGtk
        view = LobbyViewGtk(softwarecenter.paths.datadir,
                            softwarecenter.paths.APP_INSTALL_PATH,
                            cache, db, icons, get_distro(), apps_filter)
        view.show()

        # gui
        win = Gtk.Window()
        self.addCleanup(win.destroy)
        win.set_size_request(800, 400)

        scroll = Gtk.ScrolledWindow()
        scroll.add(view)
        scroll.show()
        win.add(scroll)
        win.show()
        # test visibility
        do_events()
        self.assertFalse(view.whats_new_frame.get_property("visible"))
Example #12
0
    def test_new_no_sort_info_yet(self):
        # ensure that we don't show a empty "whats new" category
        # see LP: #865985
        from softwarecenter.testutils import get_test_db
        db = get_test_db()
        cache = db._aptcache
        # simulate a fresh install with no catalogedtime info
        del db._axi_values["catalogedtime"]

        from softwarecenter.testutils import get_test_gtk3_icon_cache
        icons = get_test_gtk3_icon_cache()

        from softwarecenter.db.appfilter import AppFilter
        apps_filter = AppFilter(db, cache)

        from softwarecenter.distro import get_distro
        from softwarecenter.ui.gtk3.views.catview_gtk import LobbyViewGtk
        view = LobbyViewGtk(softwarecenter.paths.datadir,
                            softwarecenter.paths.APP_INSTALL_PATH, cache, db,
                            icons, get_distro(), apps_filter)
        view.show()

        # gui
        win = Gtk.Window()
        self.addCleanup(win.destroy)
        win.set_size_request(800, 400)

        scroll = Gtk.ScrolledWindow()
        scroll.add(view)
        scroll.show()
        win.add(scroll)
        win.show()
        # test visibility
        do_events()
        self.assertFalse(view.whats_new_frame.get_property("visible"))
    def test_recommended_for_you_opt_in_display(self, mock_get_recommender_opted_in):
        # patch the recommender UUID value to ensure that we are not opted-in
        # for this test
        mock_get_recommender_opted_in.return_value = False

        do_events()
        self.assertEqual(self.rec_panel.spinner_notebook.get_current_page(), FramedHeaderBox.CONTENT)
        self.assertTrue(self.rec_panel.opt_in_vbox.get_property("visible"))
 def test_app_icon_loading(self):
     # get icon
     self.set_mock_app_and_details(
         cached_icon_file_path="download-icon-test",
         icon="favicon.ico",
         icon_url="http://de.wikipedia.org/favicon.ico",
     )
     self.view.show_app(self.view.app)
     do_events()
Example #15
0
    def test_recommended_for_you_opt_in_display(self,
                                                mock_get_recommender_opted_in):
        # patch the recommender UUID value to ensure that we are not opted-in
        # for this test
        mock_get_recommender_opted_in.return_value = False

        do_events()
        self.assertEqual(self.rec_panel.spinner_notebook.get_current_page(),
                         FramedHeaderBox.CONTENT)
        self.assertTrue(self.rec_panel.opt_in_vbox.get_property("visible"))
 def test_show_recommendations_for_app(self, mock_query):
     self.view.show_app(self.app_mock)
     do_events()
     self.view.recommended_for_app_panel._update_app_recommendations_content()
     do_events()
     # we fake the callback from the agent here
     self.view.recommended_for_app_panel.app_recommendations_cat._recommend_app_result(
         None, make_recommend_app_data()
     )
     self.assertNotEqual(self.view.recommended_for_app_panel.app_recommendations_cat.get_documents(self.db), [])
    def test_recommended_for_you_display_recommendations_not_opted_in(self, mock_query, mock_get_recommender_opted_in):
        # patch the recommender UUID value to insure that we are not opted-in
        # for this test
        mock_get_recommender_opted_in.return_value = False

        # we want to work in the "subcat" view
        self.notebook.next_page()

        do_events()
        visible = self.subcat_view.recommended_for_you_in_cat.get_property("visible")
        self.assertFalse(visible)
 def test_show_recommendations_for_app(self, mock_query):
     self.view.show_app(self.app_mock)
     do_events()
     self.view.recommended_for_app_panel._update_app_recommendations_content()
     do_events()
     # we fake the callback from the agent here
     self.view.recommended_for_app_panel.app_recommendations_cat._recommend_app_result(
                             None,
                             make_recommend_app_data())
     self.assertNotEqual(
             self.view.recommended_for_app_panel.app_recommendations_cat.get_documents(self.db), [])
    def test_recommended_for_you_spinner_display(self, mock_query, mock_get_recommender_opted_in):
        # patch the recommender UUID value to insure that we are not opted-in
        # for this test
        mock_get_recommender_opted_in.return_value = False

        # click the opt-in button to initiate the process,
        # this will show the spinner
        self.rec_panel.opt_in_button.emit("clicked")
        do_events()
        self.assertEqual(self.rec_panel.spinner_notebook.get_current_page(), SpinnerNotebook.SPINNER_PAGE)
        self.assertTrue(self.rec_panel.opt_in_vbox.get_property("visible"))
 def test_app_icon_loading(self):
     # get icon
     app = Application("", "software-center")
     mock_app = get_mock_app_from_real_app(app)
     self.view.app = mock_app
     mock_details = mock_app.get_details(None)
     mock_details.cached_icon_file_path = "download-icon-test"
     mock_details.icon = "favicon.ico"
     mock_details.icon_url = "http://de.wikipedia.org/favicon.ico"
     self.view.app_details = mock_details
     self.view.show_app(mock_app)
     do_events()
Example #21
0
 def test_app_icon_loading(self):
     # get icon
     app = Application("", "software-center")
     mock_app = get_mock_app_from_real_app(app)
     self.view.app = mock_app
     mock_details = mock_app.get_details(None)
     mock_details.cached_icon_file_path = "download-icon-test"
     mock_details.icon = "favicon.ico"
     mock_details.icon_url = "http://de.wikipedia.org/favicon.ico"
     self.view.app_details = mock_details
     self.view.show_app(mock_app)
     do_events()
Example #22
0
    def test_top_rated(self):
        # simulate review-stats refresh
        self.lobby._update_top_rated_content = Mock()
        self.lobby.reviews_loader.emit("refresh-review-stats-finished", [])
        self.assertTrue(self.lobby._update_top_rated_content.called)

        # test clicking top_rated
        self.lobby.connect("category-selected", self._on_category_selected)
        self.lobby.top_rated_frame.more.clicked()
        do_events()
        self.assertNotEqual(self._cat, None)
        self.assertEqual(self._cat.name, "Top Rated")
        self.assertEqual(self._cat.sortmode, SortMethods.BY_TOP_RATED)
 def test_show_region_requirements(self):
     self.app_mock.details.region_requirements_satisfied = False
     self.view.show_app(self.app_mock)
     do_events()
     # ensure that the button is correct
     self.assertEqual(self.view.pkg_statusbar.button.get_label(), "Install Anyway")
     # and again for purchase
     self.app_mock.details.pkg_state = PkgStates.NEEDS_PURCHASE
     self.view.show_app(self.app_mock)
     self.assertEqual(self.view.pkg_statusbar.button.get_label(), _(u"Buy Anyway\u2026").encode("utf-8"))
     # check if the warning bar is displayed
     self.assertTrue(self.view.pkg_warningbar.get_property("visible"))
     self.assertEqual(self.view.pkg_warningbar.label.get_text(), REGION_WARNING_STRING)
Example #24
0
    def test_top_rated(self):
        # simulate review-stats refresh
        self.lobby._update_top_rated_content = Mock()
        self.lobby.reviews_loader.emit("refresh-review-stats-finished", [])
        self.assertTrue(self.lobby._update_top_rated_content.called)

        # test clicking top_rated
        self.lobby.connect("category-selected", self._on_category_selected)
        self.lobby.top_rated_frame.more.clicked()
        do_events()
        self.assertNotEqual(self._cat, None)
        self.assertEqual(self._cat.name, "Top Rated")
        self.assertEqual(self._cat.sortmode, SortMethods.BY_TOP_RATED)
Example #25
0
    def test_recommended_for_you_display_recommendations_not_opted_in(
            self, mock_query, mock_get_recommender_opted_in):
        # patch the recommender UUID value to insure that we are not opted-in
        # for this test
        mock_get_recommender_opted_in.return_value = False

        # we want to work in the "subcat" view
        self.notebook.next_page()

        do_events()
        visible = self.subcat_view.recommended_for_you_in_cat.get_property(
            "visible")
        self.assertFalse(visible)
Example #26
0
    def test_recommended_for_you_spinner_display(
            self, mock_query, mock_get_recommender_opted_in):
        # patch the recommender UUID value to insure that we are not opted-in
        # for this test
        mock_get_recommender_opted_in.return_value = False

        # click the opt-in button to initiate the process,
        # this will show the spinner
        self.rec_panel.opt_in_button.emit('clicked')
        do_events()
        self.assertEqual(self.rec_panel.spinner_notebook.get_current_page(),
                         SpinnerNotebook.SPINNER_PAGE)
        self.assertTrue(self.rec_panel.opt_in_vbox.get_property("visible"))
Example #27
0
    def test_new(self):
        # test db reopen triggers whats-new update
        self.lobby._update_whats_new_content = Mock()
        self.lobby.db.emit("reopen")
        self.assertTrue(self.lobby._update_whats_new_content.called)

        # test clicking new
        self.lobby.connect("category-selected", self._on_category_selected)
        self.lobby.whats_new_frame.more.clicked()
        do_events()
        self.assertNotEqual(self._cat, None)
        # encoding is utf-8 (since r2218, see category.py)
        self.assertEqual(self._cat.name, 'What\xe2\x80\x99s New')
        self.assertEqual(self._cat.sortmode, SortMethods.BY_CATALOGED_TIME)
Example #28
0
    def test_new(self):
        # test db reopen triggers whats-new update
        self.lobby._update_whats_new_content = Mock()
        self.lobby.db.emit("reopen")
        self.assertTrue(self.lobby._update_whats_new_content.called)

        # test clicking new
        self.lobby.connect("category-selected", self._on_category_selected)
        self.lobby.whats_new_frame.more.clicked()
        do_events()
        self.assertNotEqual(self._cat, None)
        # encoding is utf-8 (since r2218, see category.py)
        self.assertEqual(self._cat.name, 'What\xe2\x80\x99s New')
        self.assertEqual(self._cat.sortmode, SortMethods.BY_CATALOGED_TIME)
 def test_no_show_hardware_requirements(self):
     self.app_mock.details.hardware_requirements = {}
     self.app_mock.details.hardware_requirements_satisfied = True
     self.view.show_app(self.app_mock)
     do_events()
     # ensure we do not show anything if there are no HW requirements
     self.assertFalse(self.view.hardware_info.get_property("visible"))
     # ensure that the button is correct
     self.assertEqual(self.view.pkg_statusbar.button.get_label(), _("Install"))
     # and again for purchase
     self.app_mock.details.pkg_state = PkgStates.NEEDS_PURCHASE
     self.view.show_app(self.app_mock)
     self.assertEqual(self.view.pkg_statusbar.button.get_label(), _(u"Buy\u2026").encode("utf-8"))
     # check if the warning bar is invisible
     self.assertFalse(self.view.pkg_warningbar.get_property("visible"))
    def test_videoplayer(self):
        # show app with no video
        app = Application("", "2vcard")
        self.view.show_app(app)
        do_events()
        self.assertFalse(self.view.videoplayer.get_property("visible"))

        # create app with video and ensure its visible
        self.set_mock_app_and_details(
            app_name="synaptic",
            # this is a example html - any html5 video will do
            video_url="http://people.canonical.com/~mvo/totem.html")
        self.view.show_app(self.view.app)
        do_events()
        self.assertTrue(self.view.videoplayer.get_property("visible"))
Example #31
0
    def test_videoplayer(self):
        # show app with no video
        app = Application("", "2vcard")
        self.view.show_app(app)
        do_events()
        self.assertFalse(self.view.videoplayer.get_property("visible"))

        # create app with video and ensure its visible
        app = Application("", "synaptic")
        mock = get_mock_app_from_real_app(app)
        details = mock.get_details(None)
        # this is a example html - any html5 video will do
        details.video_url = "http://people.canonical.com/~mvo/totem.html"
        self.view.show_app(mock)
        do_events()
        self.assertTrue(self.view.videoplayer.get_property("visible"))
 def test_show_region_requirements(self):
     self.app_mock.details.region_requirements_satisfied = False
     self.view.show_app(self.app_mock)
     do_events()
     # ensure that the button is correct
     self.assertEqual(self.view.pkg_statusbar.button.get_label(),
                      "Install Anyway")
     # and again for purchase
     self.app_mock.details.pkg_state = PkgStates.NEEDS_PURCHASE
     self.view.show_app(self.app_mock)
     self.assertEqual(self.view.pkg_statusbar.button.get_label(),
                      _(u"Buy Anyway\u2026").encode("utf-8"))
     # check if the warning bar is displayed
     self.assertTrue(self.view.pkg_warningbar.get_property("visible"))
     self.assertEqual(self.view.pkg_warningbar.label.get_text(),
                      REGION_WARNING_STRING)
    def test_videoplayer(self):
        # show app with no video
        app = Application("", "2vcard")
        self.view.show_app(app)
        do_events()
        self.assertFalse(self.view.videoplayer.get_property("visible"))

        # create app with video and ensure its visible
        app = Application("", "synaptic")
        mock = get_mock_app_from_real_app(app)
        details = mock.get_details(None)
        # this is a example html - any html5 video will do
        details.video_url = "http://people.canonical.com/~mvo/totem.html"
        self.view.show_app(mock)
        do_events()
        self.assertTrue(self.view.videoplayer.get_property("visible"))
    def test_videoplayer(self):
        # show app with no video
        app = Application("", "2vcard")
        self.view.show_app(app)
        do_events()
        self.assertFalse(self.view.videoplayer.get_property("visible"))

        # create app with video and ensure its visible
        self.set_mock_app_and_details(
            app_name="synaptic",
            # this is a example html - any html5 video will do
            video_url="http://people.canonical.com/~mvo/totem.html",
        )
        self.view.show_app(self.view.app)
        do_events()
        self.assertTrue(self.view.videoplayer.get_property("visible"))
 def test_no_show_hardware_requirements(self):
     self.app_mock.details.hardware_requirements = {}
     self.app_mock.details.hardware_requirements_satisfied = True
     self.view.show_app(self.app_mock)
     do_events()
     # ensure we do not show anything if there are no HW requirements
     self.assertFalse(self.view.hardware_info.get_property("visible"))
     # ensure that the button is correct
     self.assertEqual(self.view.pkg_statusbar.button.get_label(),
                      _("Install"))
     # and again for purchase
     self.app_mock.details.pkg_state = PkgStates.NEEDS_PURCHASE
     self.view.show_app(self.app_mock)
     self.assertEqual(self.view.pkg_statusbar.button.get_label(),
                      _(u'Buy\u2026').encode("utf-8"))
     # check if the warning bar is invisible
     self.assertFalse(self.view.pkg_warningbar.get_property("visible"))
Example #36
0
    def test_appview_search_combo(self):
        from softwarecenter.ui.gtk3.views.appview import get_test_window
        from softwarecenter.testutils import get_test_enquirer_matches

        # test if combox sort option "by relevance" vanishes for non-searches
        # LP: #861778
        expected_normal = ["By Name", "By Top Rated", "By Newest First"]
        expected_search = [
            "By Name", "By Top Rated", "By Newest First", "By Relevance"
        ]

        # setup goo
        win = get_test_window()
        appview = win.get_data("appview")
        #entry = win.get_data("entry")
        do_events()

        # get the model
        model = appview.sort_methods_combobox.get_model()

        # test normal window (no search)
        matches = get_test_enquirer_matches(appview.helper.db)
        appview.display_matches(matches, is_search=False)
        appview.configure_sort_method(is_search=False)
        do_events()
        in_model = []
        for item in model:
            in_model.append(model.get_value(item.iter, 0))
        self.assertEqual(in_model, expected_normal)

        # now repeat and simulate a search
        matches = get_test_enquirer_matches(appview.helper.db)
        appview.display_matches(matches, is_search=True)
        appview.configure_sort_method(is_search=True)
        do_events()
        in_model = []
        for item in model:
            in_model.append(model.get_value(item.iter, 0))
        self.assertEqual(in_model, expected_search)

        # and back again to no search
        matches = get_test_enquirer_matches(appview.helper.db)
        appview.display_matches(matches, is_search=False)
        appview.configure_sort_method(is_search=False)
        do_events()
        # collect items in the model
        in_model = []
        for item in model:
            in_model.append(model.get_value(item.iter, 0))
        self.assertEqual(expected_normal, in_model)

        # destroy
        win.destroy()
Example #37
0
    def test_appview_search_combo(self):
        from softwarecenter.ui.gtk3.views.appview import get_test_window
        from softwarecenter.testutils import get_test_enquirer_matches

        # test if combox sort option "by relevance" vanishes for non-searches
        # LP: #861778
        expected_normal = ["By Name", "By Top Rated", "By Newest First"]
        expected_search = ["By Name", "By Top Rated", "By Newest First", 
                           "By Relevance"]

        # setup goo
        win = get_test_window()
        appview = win.get_data("appview")
        #entry = win.get_data("entry")
        do_events()

        # get the model
        model = appview.sort_methods_combobox.get_model()

        # test normal window (no search)
        matches = get_test_enquirer_matches(appview.helper.db)
        appview.display_matches(matches, is_search=False)
        appview.configure_sort_method(is_search=False)
        do_events()
        in_model = []
        for item in model:
            in_model.append(model.get_value(item.iter, 0))
        self.assertEqual(in_model, expected_normal)

        # now repeat and simulate a search
        matches = get_test_enquirer_matches(appview.helper.db)
        appview.display_matches(matches, is_search=True)
        appview.configure_sort_method(is_search=True)
        do_events()
        in_model = []
        for item in model:
            in_model.append(model.get_value(item.iter, 0))
        self.assertEqual(in_model, expected_search)

        # and back again to no search
        matches = get_test_enquirer_matches(appview.helper.db)
        appview.display_matches(matches, is_search=False)
        appview.configure_sort_method(is_search=False)
        do_events()
        # collect items in the model
        in_model = []
        for item in model:
            in_model.append(model.get_value(item.iter, 0))
        self.assertEqual(expected_normal, in_model)

        # destroy
        win.destroy()
    def test_recommended_for_you_display_recommendations_opted_in(self, mock_query, mock_get_recommender_opted_in):
        # patch the recommender UUID value to insure that we are not opted-in
        # for this test
        mock_get_recommender_opted_in.return_value = True

        # we want to work in the "subcat" view
        self.notebook.next_page()

        rec_cat_panel = self.subcat_view.recommended_for_you_in_cat
        rec_cat_panel._update_recommended_for_you_content()
        do_events()
        # we fake the callback from the agent here
        rec_cat_panel.recommended_for_you_cat._recommend_me_result(None, make_recommender_agent_recommend_me_dict())
        result_docs = rec_cat_panel.recommended_for_you_cat.get_documents(self.db)
        self.assertNotEqual(result_docs, [])
        # check that we are getting the correct number of results,
        # corresponding to the following Internet items:
        #   Mangler, Midori, Midori Private Browsing, Psi
        self.assertTrue(len(result_docs) == 4)
        self.assertEqual(rec_cat_panel.spinner_notebook.get_current_page(), SpinnerNotebook.CONTENT_PAGE)
        # check that the tiles themselves are visible
        do_events()
        self.assertTrue(rec_cat_panel.recommended_for_you_content.get_property("visible"))
        self.assertTrue(rec_cat_panel.recommended_for_you_content.get_children()[0].title.get_property("visible"))
        do_events()
        # test clicking recommended_for_you More button
        self.subcat_view.connect("category-selected", self._on_category_selected)
        rec_cat_panel.more.clicked()
        # this is delayed for some reason so we need to sleep here
        do_events_with_sleep()
        self.assertNotEqual(self._cat, None)
        self.assertEqual(self._cat.name, "Recommended For You in Internet")
Example #39
0
    def test_recommended_for_you_display_recommendations(self,
                                   mock_query, mock_get_recommender_opted_in):
        # patch the recommender UUID value to insure that we are not opted-in
        # for this test
        mock_get_recommender_opted_in.return_value = False

        # click the opt-in button to initiate the process,
        # this will show the spinner
        self.rec_panel.opt_in_button.emit('clicked')
        do_events()
        self.rec_panel._update_recommended_for_you_content()
        do_events()
        # we fake the callback from the agent here
        for_you = self.lobby.recommended_for_you_panel.recommended_for_you_cat
        for_you._recommend_me_result(None,
            make_recommender_agent_recommend_me_dict())
        self.assertNotEqual(for_you.get_documents(self.db), [])
        self.assertEqual(self.rec_panel.spinner_notebook.get_current_page(),
                         SpinnerNotebook.CONTENT_PAGE)
        do_events()
        # test clicking recommended_for_you More button
        self.lobby.connect("category-selected", self._on_category_selected)
        self.lobby.recommended_for_you_panel.more.clicked()
        # this is delayed for some reason so we need to sleep here
        do_events_with_sleep()
        self.assertNotEqual(self._cat, None)
        self.assertEqual(self._cat.name, "Recommended For You")
Example #40
0
    def test_recommended_for_you_display_recommendations(
            self, mock_query, mock_get_recommender_opted_in):
        # patch the recommender UUID value to insure that we are not opted-in
        # for this test
        mock_get_recommender_opted_in.return_value = False

        # click the opt-in button to initiate the process,
        # this will show the spinner
        self.rec_panel.opt_in_button.emit('clicked')
        do_events()
        self.rec_panel._update_recommended_for_you_content()
        do_events()
        # we fake the callback from the agent here
        for_you = self.lobby.recommended_for_you_panel.recommended_for_you_cat
        for_you._recommend_me_result(
            None, make_recommender_agent_recommend_me_dict())
        self.assertNotEqual(for_you.get_documents(self.db), [])
        self.assertEqual(self.rec_panel.spinner_notebook.get_current_page(),
                         SpinnerNotebook.CONTENT_PAGE)
        do_events()
        # test clicking recommended_for_you More button
        self.lobby.connect("category-selected", self._on_category_selected)
        self.lobby.recommended_for_you_panel.more.clicked()
        # this is delayed for some reason so we need to sleep here
        do_events_with_sleep()
        self.assertNotEqual(self._cat, None)
        self.assertEqual(self._cat.name, "Recommended For You")
Example #41
0
    def test_app_view(self):
        from softwarecenter.ui.gtk3.views.appview import get_test_window
        enquirer = AppEnquire(self.cache, self.db)
        enquirer.set_query(xapian.Query(""),
                           sortmode=SortMethods.BY_CATALOGED_TIME,
                           limit=10,
                           nonblocking_load=False)

        # get test window
        win = get_test_window()
        appview = win.get_data("appview")
        # set matches
        appview.clear_model()
        appview.display_matches(enquirer.matches)
        do_events()
        # verify that the order is actually the correct one
        model = appview.tree_view.get_model()
        docs_in_model = [item[0] for item in model]
        docs_from_enquirer = [m.document for m in enquirer.matches]
        self.assertEqual(len(docs_in_model), len(docs_from_enquirer))
        for i in range(len(docs_in_model)):
            self.assertEqual(self.db.get_pkgname(docs_in_model[i]),
                             self.db.get_pkgname(docs_from_enquirer[i]))
        win.destroy()
Example #42
0
    def test_recommended_for_you_display_recommendations_opted_in(
            self, mock_query, mock_get_recommender_opted_in):
        # patch the recommender UUID value to insure that we are not opted-in
        # for this test
        mock_get_recommender_opted_in.return_value = True

        # we want to work in the "subcat" view
        self.notebook.next_page()

        rec_cat_panel = self.subcat_view.recommended_for_you_in_cat
        rec_cat_panel._update_recommended_for_you_content()
        do_events()
        # we fake the callback from the agent here
        rec_cat_panel.recommended_for_you_cat._recommend_me_result(
            None, make_recommender_agent_recommend_me_dict())
        result_docs = rec_cat_panel.recommended_for_you_cat.get_documents(
            self.db)
        self.assertNotEqual(result_docs, [])
        # check that we are getting the correct number of results,
        # corresponding to the following Internet items:
        #   Mangler, Midori, Midori Private Browsing, Psi
        self.assertTrue(len(result_docs) == 4)
        self.assertEqual(rec_cat_panel.spinner_notebook.get_current_page(),
                         SpinnerNotebook.CONTENT_PAGE)
        # check that the tiles themselves are visible
        do_events()
        self.assertTrue(
            rec_cat_panel.recommended_for_you_content.get_property("visible"))
        self.assertTrue(
            rec_cat_panel.recommended_for_you_content.get_children()
            [0].title.get_property("visible"))
        do_events()
        # test clicking recommended_for_you More button
        self.subcat_view.connect("category-selected",
                                 self._on_category_selected)
        rec_cat_panel.more.clicked()
        # this is delayed for some reason so we need to sleep here
        do_events_with_sleep()
        self.assertNotEqual(self._cat, None)
        self.assertEqual(self._cat.name, "Recommended For You in Internet")
 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)
 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)
Example #45
0
 def test_clear_credentials(self):
     from softwarecenter.utils import clear_token_from_ubuntu_sso_sync
     clear_token_from_ubuntu_sso_sync("fo")
     do_events()
 def test_clear_credentials(self):
     from softwarecenter.utils import clear_token_from_ubuntu_sso_sync
     clear_token_from_ubuntu_sso_sync("fo")
     do_events()
Example #47
0
 def _p(self):
     for i in range(5):
         time.sleep(0.1)
         do_events()
Example #48
0
    def test_page_pkgstates(self):
        # show app 
        app = Application("", "abiword")
        self.view.show_app(app)
        do_events()
        
        # check that the action bar is given initial focus in the view
        self.assertTrue(self.view.pkg_statusbar.button.is_focus())

        # create mock app
        mock_app = get_mock_app_from_real_app(app)
        self.view.app = mock_app
        mock_details = mock_app.get_details(None)
        mock_details.purchase_date = "2011-11-20 17:45:01"
        mock_details._error_not_found = "error not found"
        mock_details.price = "1.00"
        mock_details.pkgname = "abiword"
        mock_details.error = "error-text"
        self.view.app_details = mock_details

        # the states and what labels we expect in the pkgstatusbar
        # first string is status text, second is button text
        pkg_states_to_labels = {
            PkgStates.INSTALLED : ("Purchased on 2011-11-20", "Remove"),
            PkgStates.UNINSTALLED : ('Free', 'Install'),
            PkgStates.NEEDS_PURCHASE : ('US$ 1.00', u'Buy\u2026'),
            PkgStates.PURCHASED_BUT_REPO_MUST_BE_ENABLED : ('Purchased on 2011-11-20', 'Install'),
        }
        # this describes if a button is visible or invisible
        button_invisible = [ PkgStates.ERROR,
                             PkgStates.NOT_FOUND,
                             PkgStates.INSTALLING_PURCHASED,
                             PkgStates.PURCHASED_BUT_NOT_AVAILABLE_FOR_SERIES,
                             PkgStates.UNKNOWN,
                           ]

        # show a app through the various states and test if the right ui
        # elements are visible and have the right text
        for var in vars(PkgStates):
            state = getattr(PkgStates, var)
            mock_details.pkg_state = state
            # reset app to ensure its shown again
            self.view.app = None
            # show it
            self.view.show_app(mock_app)
            #do_events()
            # check button label
            if state in pkg_states_to_labels:
                label, button_label = pkg_states_to_labels[state]
                self.assertEqual(
                    self.view.pkg_statusbar.get_label(), 
                    label.decode("utf-8"))
                self.assertEqual(
                    self.view.pkg_statusbar.get_button_label().decode("utf-8"),
                    button_label)
            # check if button should be there or not
            if state in button_invisible:
                self.assertFalse(
                    self.view.pkg_statusbar.button.get_property("visible"),
                    "button visible error for state %s" % state)
            else:
                self.assertTrue(
                    self.view.pkg_statusbar.button.get_property("visible"),
                    "button visible error for state %s" % state)
            # regression test for #955005
            if state == PkgStates.NOT_FOUND:
                self.assertFalse(self.view.review_stats.get_property("visible"))
                self.assertFalse(self.view.reviews.get_property("visible"))
    def test_page_pkgstates(self):
        # show app
        app = Application("", "abiword")
        self.view.show_app(app)
        do_events()

        # check that the action bar is given initial focus in the view
        self.assertTrue(self.view.pkg_statusbar.button.is_focus())

        # create mock app
        mock_app = get_mock_app_from_real_app(app)
        self.view.app = mock_app
        mock_details = mock_app.get_details(None)
        mock_details.purchase_date = "2011-11-20 17:45:01"
        mock_details._error_not_found = "error not found"
        mock_details.price = "1.00"
        mock_details.pkgname = "abiword"
        mock_details.error = "error-text"
        self.view.app_details = mock_details

        # the states and what labels we expect in the pkgstatusbar
        # first string is status text, second is button text
        pkg_states_to_labels = {
            PkgStates.INSTALLED: ("Purchased on 2011-11-20", "Remove"),
            PkgStates.UNINSTALLED: ('Free', 'Install'),
            PkgStates.NEEDS_PURCHASE: ('US$ 1.00', u'Buy\u2026'),
            PkgStates.PURCHASED_BUT_REPO_MUST_BE_ENABLED:
            ('Purchased on 2011-11-20', 'Install'),
        }
        # this describes if a button is visible or invisible
        button_invisible = [
            PkgStates.ERROR,
            PkgStates.NOT_FOUND,
            PkgStates.INSTALLING_PURCHASED,
            PkgStates.PURCHASED_BUT_NOT_AVAILABLE_FOR_SERIES,
            PkgStates.UNKNOWN,
        ]

        # show a app through the various states and test if the right ui
        # elements are visible and have the right text
        for var in vars(PkgStates):
            state = getattr(PkgStates, var)
            mock_details.pkg_state = state
            # reset app to ensure its shown again
            self.view.app = None
            # show it
            self.view.show_app(mock_app)
            #do_events()
            # check button label
            if state in pkg_states_to_labels:
                label, button_label = pkg_states_to_labels[state]
                self.assertEqual(self.view.pkg_statusbar.get_label(),
                                 label.decode("utf-8"))
                self.assertEqual(
                    self.view.pkg_statusbar.get_button_label().decode("utf-8"),
                    button_label)
            # check if button should be there or not
            if state in button_invisible:
                self.assertFalse(
                    self.view.pkg_statusbar.button.get_property("visible"),
                    "button visible error for state %s" % state)
            else:
                self.assertTrue(
                    self.view.pkg_statusbar.button.get_property("visible"),
                    "button visible error for state %s" % state)
            # regression test for #955005
            if state == PkgStates.NOT_FOUND:
                self.assertFalse(
                    self.view.review_stats.get_property("visible"))
                self.assertFalse(self.view.reviews.get_property("visible"))
Example #50
0
 def _p(self):
     for i in range(5):
         time.sleep(0.1)
         do_events()