Example #1
0
    def test_reinstall_purchased_xapian(self, mock_helper, mock_agent):
        small_available =  [ self.available[0] ]
        mock_agent.return_value = self._make_fake_scagent(
            small_available, self.available_for_me)

        db = xapian.inmemory_open()
        cache = get_test_pkg_info()

        # now create purchased debs xapian index (in memory because
        # we store the repository passwords in here)
        old_db_len = db.get_doccount()
        update_from_software_center_agent(db, cache)
        # ensure we have the new item
        self.assertEqual(db.get_doccount(), old_db_len+2)
        # query
        query = get_reinstall_previous_purchases_query()
        enquire = xapian.Enquire(db)
        enquire.set_query(query)
        matches = enquire.get_mset(0, db.get_doccount())
        self.assertEqual(len(matches), 1)
        distroseries = platform.dist()[2]
        for m in matches:
            doc = db.get_document(m.docid)
            self.assertEqual(doc.get_value(XapianValues.PKGNAME), "photobomb")
            self.assertEqual(
                doc.get_value(XapianValues.ARCHIVE_SIGNING_KEY_ID),
                "1024R/75254D99")
            self.assertEqual(doc.get_value(XapianValues.ARCHIVE_DEB_LINE),
                "deb https://username:random3atoken@"
                 "private-ppa.launchpad.net/commercial-ppa-uploaders"
                 "/photobomb/ubuntu %s main" % distroseries)
Example #2
0
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
Example #3
0
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
Example #4
0
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
Example #5
0
 def test_get_total_size(self):
     def _on_query_total_size_on_install_done(pkginfo, pkgname, 
                                              download, space):
         self.need_download = download
         self.need_space = space
         loop.quit()
     TEST_PKG = "casper"
     ADDONS_TO_INSTALL = [ "lupin-casper" ]
     ADDONS_TO_REMOVE = []
     loop =  GLib.MainLoop(GLib.main_context_default())
     cache = get_test_pkg_info()
     cache.connect(
         "query-total-size-on-install-done", 
         _on_query_total_size_on_install_done)
     cache.query_total_size_on_install(
         TEST_PKG, ADDONS_TO_INSTALL, ADDONS_TO_REMOVE)
     loop.run()
     # ensure the test eventually stops and does not hang
     GLib.timeout_add_seconds(10, loop.quit)
     # work out the numbers that we at least need to get (this will
     # not include dependencies so it is probably lower)
     need_at_least_download = (
         cache[TEST_PKG].candidate.size + 
         sum([cache[pkg].candidate.size for pkg in ADDONS_TO_INSTALL]))
     need_at_least_installed = (
         cache[TEST_PKG].candidate.installed_size +
         sum([cache[pkg].candidate.installed_size for pkg in ADDONS_TO_INSTALL]))
     self.assertTrue(self.need_download >= need_at_least_download)
     self.assertTrue(self.need_space >= need_at_least_installed)
     del self.need_download
     del self.need_space
Example #6
0
 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(), "")
Example #7
0
 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(), "")
Example #8
0
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_license_string_data_from_software_center_agent(self):
     # os.environ["SOFTWARE_CENTER_DEBUG_HTTP"] = "1"
     # os.environ["SOFTWARE_CENTER_AGENT_HOST"] = "http://sc.staging.ubuntu.com/"
     # staging does not have a valid cert
     os.environ["PISTON_MINI_CLIENT_DISABLE_SSL_VALIDATION"] = "1"
     cache = get_test_pkg_info()
     db = xapian.WritableDatabase(TEST_DB, xapian.DB_CREATE_OR_OVERWRITE)
     res = update_from_software_center_agent(db, cache, ignore_cache=True)
     self.assertTrue(res)
     for p in db.postlist(""):
         doc = db.get_document(p.docid)
         license = doc.get_value(XapianValues.LICENSE)
         self.assertNotEqual(license, "")
         self.assertNotEqual(license, None)
Example #10
0
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_license_string_data_from_software_center_agent(self):
     #os.environ["SOFTWARE_CENTER_DEBUG_HTTP"] = "1"
     #os.environ["SOFTWARE_CENTER_AGENT_HOST"] = "http://sc.staging.ubuntu.com/"
     # staging does not have a valid cert
     os.environ["PISTON_MINI_CLIENT_DISABLE_SSL_VALIDATION"] = "1"
     cache = get_test_pkg_info()
     db = xapian.WritableDatabase(TEST_DB, xapian.DB_CREATE_OR_OVERWRITE)
     res = update_from_software_center_agent(db, cache, ignore_cache=True)
     self.assertTrue(res)
     for p in db.postlist(""):
         doc = db.get_document(p.docid)
         license = doc.get_value(XapianValues.LICENSE)
         self.assertNotEqual(license, "")
         self.assertNotEqual(license, None)
Example #12
0
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_for_purchase_apps_date_published(self, mock_find_oauth):
        # pretend we have no token
        mock_find_oauth.return_value = None
        # os.environ["SOFTWARE_CENTER_DEBUG_HTTP"] = "1"
        # os.environ["SOFTWARE_CENTER_AGENT_HOST"] = "http://sc.staging.ubuntu.com/"
        # staging does not have a valid cert
        os.environ["PISTON_MINI_CLIENT_DISABLE_SSL_VALIDATION"] = "1"
        cache = get_test_pkg_info()
        db = xapian.inmemory_open()
        res = update_from_software_center_agent(db, cache, ignore_cache=True)
        self.assertTrue(res)

        for p in db.postlist(""):
            doc = db.get_document(p.docid)
            date_published = doc.get_value(XapianValues.DATE_PUBLISHED)
            # make sure that a date_published value is provided
            self.assertNotEqual(date_published, "")
            self.assertNotEqual(date_published, None)
    def test_for_purchase_apps_date_published(self, mock_find_oauth):
        # pretend we have no token
        mock_find_oauth.return_value = None
        #os.environ["SOFTWARE_CENTER_DEBUG_HTTP"] = "1"
        #os.environ["SOFTWARE_CENTER_AGENT_HOST"] = "http://sc.staging.ubuntu.com/"
        # staging does not have a valid cert
        os.environ["PISTON_MINI_CLIENT_DISABLE_SSL_VALIDATION"] = "1"
        cache = get_test_pkg_info()
        db = xapian.inmemory_open()
        res = update_from_software_center_agent(db, cache, ignore_cache=True)
        self.assertTrue(res)

        for p in db.postlist(""):
            doc = db.get_document(p.docid)
            date_published = doc.get_value(XapianValues.DATE_PUBLISHED)
            # make sure that a date_published value is provided
            self.assertNotEqual(date_published, "")
            self.assertNotEqual(date_published, None)
Example #15
0
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
Example #16
0
    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_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
Example #18
0
    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)
Example #19
0
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
Example #20
0
 def setUpClass(cls):
     cls.cache = get_test_pkg_info()
     cls.icons = get_test_gtk3_icon_cache()
     cls.db = get_test_db()
Example #21
0
 def setUp(self):
     self.cache = get_test_pkg_info()
     self.icons = get_test_gtk3_icon_cache()
     self.db = get_test_db()
Example #22
0
 def setUp(self):
     self.cache = get_test_pkg_info()
     self.icons = get_test_gtk3_icon_cache()
     self.db = get_test_db()
Example #23
0
class TestReviewLoader(unittest.TestCase):
    cache = get_test_pkg_info()
    db = get_test_db()

    def _review_stats_ready_callback(self, review_stats):
        self._stats_ready = True
        self._review_stats = review_stats


#    def test_review_stats_caching(self):
#        self._stats_ready = False
#        self._review_stats = []
#        review_loader = ReviewLoader(self.cache, self.db)
#        review_loader.refresh_review_stats(self._review_stats_ready_callback)
#        while not self._stats_ready:
#            do_events()
#        self.assertTrue(len(self._review_stats) > 0)
#        self.assertTrue(os.path.exists(review_loader.REVIEW_STATS_CACHE_FILE))
#        self.assertTrue(os.path.exists(review_loader.REVIEW_STATS_BSDDB_FILE))
#        # once its there, get_top_rated
#        top_rated = review_loader.get_top_rated_apps(quantity=10)
#        self.assertEqual(len(top_rated), 10)
#        # and per-cat
#        top_cat = review_loader.get_top_rated_apps(
#            quantity=8, category="Internet")
#        self.assertEqual(len(top_cat), 8)

    def test_edit_review_screen_has_right_labels(self):
        """Check that LP #880255 stays fixed. """

        review_app = SubmitReviewsApp(datadir=REAL_DATA_DIR,
                                      app=None,
                                      parent_xid='',
                                      iconname='accessories-calculator',
                                      origin=None,
                                      version=None,
                                      action='modify',
                                      review_id=10000)
        # monkey patch away login to avoid that we actually login
        # and the UI changes because of that

        review_app.login = lambda: True

        # run the main app
        review_app.run()

        do_events()
        review_app.login_successful('foobar')
        do_events()
        self.assertEqual(_('Rating:'), review_app.rating_label.get_label())
        self.assertEqual(_('Summary:'),
                         review_app.review_summary_label.get_label())
        self.assertEqual(
            _('Review by: %s') % 'foobar', review_app.review_label.get_label())
        review_app.submit_window.hide()

    def test_get_fade_colour_markup(self):
        review_app = SubmitReviewsApp(datadir=REAL_DATA_DIR,
                                      app=None,
                                      parent_xid='',
                                      iconname='accessories-calculator',
                                      origin=None,
                                      version=None,
                                      action='nothing')
        cases = (
            (('006000', '00A000', 40, 60, 50), ('008000', 10)),
            (('000000', 'FFFFFF', 40, 40, 40), ('000000', 0)),
            (('000000', '808080', 100, 400, 40), ('000000', 360)),
            (('000000', '808080', 100, 400, 1000), ('808080', -600)),
            (('123456', '5294D6', 10, 90, 70), ('427CB6', 20)),
        )
        for args, return_value in cases:
            result = review_app._get_fade_colour_markup(*args)
            expected = '<span fgcolor="#%s">%s</span>' % return_value
            self.assertEqual(expected, result)

    def test_modify_review_is_the_same_supports_unicode(self):
        review_app = SubmitReviewsApp(datadir=REAL_DATA_DIR,
                                      app=None,
                                      parent_xid='',
                                      iconname='accessories-calculator',
                                      origin=None,
                                      version=None,
                                      action='modify',
                                      review_id=10000)
        self.assertTrue(review_app._modify_review_is_the_same())

        cases = ('', 'e', ')!')
        for case in cases:
            modified = review_app.orig_summary_text[:-1] + case
            review_app.review_summary_entry.set_text(modified)
            self.assertFalse(review_app._modify_review_is_the_same())

        review_app.review_summary_entry.set_text(review_app.orig_summary_text)
        for case in cases:
            modified = review_app.orig_review_text[:-1] + case
            review_app.review_buffer.set_text(modified)
            self.assertFalse(review_app._modify_review_is_the_same())

    def test_change_status(self):
        review_app = SubmitReviewsApp(datadir=REAL_DATA_DIR,
                                      app=None,
                                      parent_xid='',
                                      iconname='accessories-calculator',
                                      origin=None,
                                      version=None,
                                      action='nothing')
        msg = 'Something completely different'
        cases = {
            'clear': (True, True, True, True, None, None),
            'progress': (False, True, True, True, msg, None),
            'fail': (True, False, True, True, None, msg),
            'success': (True, True, False, True, msg, None),
            'warning': (True, True, True, False, msg, None),
        }
        review_app.run()

        for status in cases:
            review_app._change_status(status, msg)
            spinner, error, success, warn, label, error_detail = cases[status]
            self.assertEqual(spinner,
                             review_app.submit_spinner.get_parent() is None)
            self.assertEqual(error,
                             review_app.submit_error_img.get_window() is None)
            self.assertEqual(
                success,
                review_app.submit_success_img.get_window() is None)
            self.assertEqual(warn,
                             review_app.submit_warn_img.get_window() is None)
            if label:
                self.assertEqual(label,
                                 review_app.label_transmit_status.get_text())
            if error_detail:
                buff = review_app.error_textview.get_buffer()
                self.assertEqual(
                    error_detail,
                    buff.get_text(buff.get_start_iter(),
                                  buff.get_end_iter(),
                                  include_hidden_chars=False))
                review_app.detail_expander.get_visible()
Example #24
0
 def setUpClass(cls):
     cls.cache = get_test_pkg_info()
     cls.icons = get_test_gtk3_icon_cache()
     cls.db = get_test_db()