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 show_app(self, app): """ show the given application """ if app is None: return self.app = app self.appdetails = AppDetails(self.db, application=app) #print "AppDetailsViewWebkit:" #print self.appdetails self._draw() self._check_for_reviews() self.emit("selected", self.app)
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_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_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 make_purchased_app_details(db=None, supported_series=None): """Return an AppDetail instance with the required attributes.""" app = make_software_center_agent_app_dict() subscription = make_software_center_agent_subscription_dict(app) if supported_series != None: subscription['application']['series'] = supported_series else: # If no supportod_series kwarg was provided, we ensure the # current series/arch is supported. distro = softwarecenter.distro.get_distro() subscription['application']['series'] = { distro.get_codename(): [distro.get_architecture()] } item = PistonResponseObject.from_dict(subscription) parser = SCAPurchasedApplicationParser(item) if db is None: db = get_test_db() doc = parser.make_doc(db._aptcache) app_details = AppDetails(db, doc) return app_details
def test_empty_dict_set(self): self.mock_app_details.empty_set = set() self.mock_app_details.empty_dict = {} properties = AppDetails.as_dbus_property_dict(self.mock_app_details) self.assertEqual(properties["empty_set"], "") self.assertEqual(properties["empty_dict"], "")
def __init__(self, helper, doc, icon_size=48): TileButton.__init__(self) self._pressed = False label = helper.get_appname(doc) icon = helper.get_icon_at_size(doc, icon_size, icon_size) stats = helper.get_review_stats(doc) helper.update_availability(doc) helper.connect("needs-refresh", self._on_needs_refresh, doc, icon_size) self.is_installed = helper.is_installed(doc) self._overlay = helper.icons.load_icon(Icons.INSTALLED_OVERLAY, self.INSTALLED_OVERLAY_SIZE, 0) # flags self.box.set_orientation(Gtk.Orientation.HORIZONTAL) self.box.set_spacing(StockEms.SMALL) self.content_left = Gtk.Box.new(Gtk.Orientation.VERTICAL, StockEms.MEDIUM) self.content_right = Gtk.Box.new(Gtk.Orientation.VERTICAL, 1) self.box.pack_start(self.content_left, False, False, 0) self.box.pack_start(self.content_right, False, False, 0) self.image = Gtk.Image() _update_icon(self.image, icon, icon_size) self.content_left.pack_start(self.image, False, False, 0) self.title = Gtk.Label.new(self._MARKUP % GObject.markup_escape_text(label)) self.title.set_alignment(0.0, 0.5) self.title.set_use_markup(True) self.title.set_tooltip_text(label) self.title.set_ellipsize(Pango.EllipsizeMode.END) self.content_right.pack_start(self.title, False, False, 0) categories = helper.get_categories(doc) if categories is not None: self.category = Gtk.Label.new( '<span font_desc="%i">%s</span>' % (em(0.6), GObject.markup_escape_text(categories))) self.category.set_use_markup(True) self.category.set_alignment(0.0, 0.5) self.category.set_ellipsize(Pango.EllipsizeMode.END) self.content_right.pack_start(self.category, False, False, 4) stats_a11y = None if stats is not None: self.stars = Star(size=StarSize.SMALL) self.stars.render_outline = True self.stars.set_rating(stats.ratings_average) self.rating_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, StockEms.SMALL) self.rating_box.pack_start(self.stars, False, False, 0) self.n_ratings = Gtk.Label.new( '<span font_desc="%i"> (%i)</span>' % (em(0.45), stats.ratings_total)) self.n_ratings.set_use_markup(True) self.n_ratings.set_name("subtle-label") self.n_ratings.set_alignment(0.0, 0.5) self.rating_box.pack_start(self.n_ratings, False, False, 0) self.content_right.pack_start(self.rating_box, False, False, 0) # TRANSLATORS: this is an accessibility description for eg orca and # is not visible in the ui stats_a11y = _('%(stars)d stars - %(reviews)d reviews') % { 'stars': stats.ratings_average, 'reviews': stats.ratings_total } # work out width tile needs to be to ensure ratings text is all # visible req_width = (self.stars.size_request().width + self.image.size_request().width + self.n_ratings.size_request().width + StockEms.MEDIUM * 3) global _global_featured_tile_width _global_featured_tile_width = max(_global_featured_tile_width, req_width) details = AppDetails(db=helper.db, doc=doc) # TRANSLATORS: Free here means Gratis price = details.price or _("Free") if price == '0.00': # TRANSLATORS: Free here means Gratis price = _("Free") # TRANSLATORS: Free here means Gratis if price != _("Free"): price = 'US$ ' + price self.price = Gtk.Label.new('<span font_desc="%i">%s</span>' % (em(0.6), price)) self.price.set_use_markup(True) self.price.set_name("subtle-label") self.price.set_alignment(0.0, 0.5) self.content_right.pack_start(self.price, False, False, 0) self.set_name("featured-tile") a11y_name = '. '.join( [t for t in [label, categories, stats_a11y, price] if t]) self.get_accessible().set_name(a11y_name) backend = get_install_backend() backend.connect("transaction-finished", self.on_transaction_finished, helper, doc) self.connect("enter-notify-event", self.on_enter) self.connect("leave-notify-event", self.on_leave) self.connect("button-press-event", self.on_press) self.connect("button-release-event", self.on_release)
def test_appdetails(self): db = get_test_db() # see "apt-cache show casper|grep ^Tag" details = AppDetails(db, application=Application("", "casper")) self.assertTrue(len(details.tags) > 2)
def test_application_details(self): db = xapian.WritableDatabase(TEST_DB, xapian.DB_CREATE_OR_OVERWRITE) res = update_from_app_install_data(db, self.cache, datadir=os.path.join( DATA_DIR, "desktop")) self.assertTrue(res) db = StoreDatabase(TEST_DB, self.cache) db.open(use_axi=False, use_agent=False) self.assertEqual(len(db), 6) # test details app = Application("Ubuntu Software Center Test", "software-center") details = app.get_details(db) self.assertNotEqual(details, None) # mvo: disabled, we can reenable this once there is a static # apt rootdir and we do not rely on the test system to # have software-center from the main archive and not from # e.g. a custom repo like the ADT environment #self.assertEqual(details.component, "main") self.assertEqual(details.pkgname, "software-center") # get the first document for doc in db: if doc.get_data() == "Ubuntu Software Center Test": appdetails = AppDetails(db, doc=doc) break # test get_appname and get_pkgname self.assertEqual(db.get_appname(doc), "Ubuntu Software Center Test") self.assertEqual(db.get_pkgname(doc), "software-center") # test appdetails self.assertEqual(appdetails.name, "Ubuntu Software Center Test") self.assertEqual(appdetails.pkgname, "software-center") # FIXME: add a dekstop file with a real channel to test # and monkey-patch/modify the APP_INSTALL_CHANNELS_PATH self.assertEqual(appdetails.channelname, None) self.assertEqual(appdetails.channelfile, None) self.assertNotEqual(appdetails.pkg, None) # from the fake test/data/appdetails/var/lib/dpkg/status self.assertEqual(appdetails.pkg.is_installed, True) self.assertTrue(appdetails.pkg_state in (PkgStates.INSTALLED, PkgStates.UPGRADABLE)) # FIXME: test description for unavailable pkg self.assertTrue( appdetails.description.startswith( "Ubuntu Software Center lets you")) # FIXME: test appdetails.website self.assertEqual(appdetails.icon, "softwarecenter") # crude, crude self.assertTrue(len(appdetails.version) > 2) # FIXME: screenshots will only work on ubuntu self.assertTrue( re.match( "http://screenshots.ubuntu.com/screenshot-with-version/software-center/[\d.]+", appdetails.screenshot)) self.assertTrue( re.match( "http://screenshots.ubuntu.com/thumbnail-with-version/software-center/[\d.]+", appdetails.thumbnail)) # FIXME: add document that has a price self.assertEqual(appdetails.price, "Free") self.assertEqual(appdetails.raw_price, "") # mvo: disabled, we can reenable this once there is a static # apt rootdir and we do not rely on the test system to # have software-center from the main archive and not from # e.g. a custom repo like the ADT environment #self.assertEqual(appdetails.license, "Open source") # test lazy history loading for installation date self.ensure_installation_date_and_lazy_history_loading(appdetails) # test apturl replacements # $kernel app = Application("", "linux-headers-$kernel", "channel=$distro-partner") self.assertEqual(app.pkgname, 'linux-headers-' + os.uname()[2]) # $distro details = app.get_details(db) distro = softwarecenter.distro.get_distro().get_codename() self.assertEqual(app.request, 'channel=' + distro + '-partner')
def test_simple(self): self.mock_app_details.name = "fake-app" properties = AppDetails.as_dbus_property_dict(self.mock_app_details) self.assertEqual(properties["name"], "fake-app")
def test_normal_set(self): self.mock_app_details.non_empty_set = set(["foo", "bar", "baz"]) properties = AppDetails.as_dbus_property_dict(self.mock_app_details) self.assertEqual(sorted(properties["non_empty_set"]), ["bar", "baz", "foo"])
def test_application_details(self): db = xapian.WritableDatabase("./data/test.db", xapian.DB_CREATE_OR_OVERWRITE) res = update_from_app_install_data(db, self.cache, datadir="./data/desktop") self.assertTrue(res) db = StoreDatabase("./data/test.db", self.cache) db.open(use_axi=False, use_agent=False) self.assertEqual(len(db), 5) # test details app = Application("Ubuntu Software Center Test", "software-center") details = app.get_details(db) self.assertNotEqual(details, None) self.assertEqual(details.component, "main") self.assertEqual(details.pkgname, "software-center") # get the first document for doc in db: if doc.get_data() == "Ubuntu Software Center Test": appdetails = AppDetails(db, doc=doc) break # test get_appname and get_pkgname self.assertEqual(db.get_appname(doc), "Ubuntu Software Center Test") self.assertEqual(db.get_pkgname(doc), "software-center") # test appdetails self.assertEqual(appdetails.name, "Ubuntu Software Center Test") self.assertEqual(appdetails.pkgname, "software-center") # FIXME: add a dekstop file with a real channel to test # and monkey-patch/modify the APP_INSTALL_CHANNELS_PATH self.assertEqual(appdetails.channelname, None) self.assertEqual(appdetails.channelfile, None) self.assertEqual(appdetails.component, "main") self.assertNotEqual(appdetails.pkg, None) # from the fake test/data/appdetails/var/lib/dpkg/status self.assertEqual(appdetails.pkg.is_installed, True) self.assertEqual(appdetails.pkg_state, PkgStates.INSTALLED) # FIXME: test description for unavailable pkg self.assertTrue( appdetails.description.startswith("Ubuntu Software Center lets you")) # FIXME: test appdetails.website self.assertEqual(appdetails.icon, "softwarecenter") # crude, crude self.assertTrue(len(appdetails.version) > 2) # FIXME: screenshots will only work on ubuntu self.assertTrue(re.match( "http://screenshots.ubuntu.com/screenshot-with-version/software-center/[\d.]+", appdetails.screenshot)) self.assertTrue(re.match( "http://screenshots.ubuntu.com/thumbnail-with-version/software-center/[\d.]+", appdetails.thumbnail)) # FIXME: add document that has a price self.assertEqual(appdetails.price, '') self.assertEqual(appdetails.license, "Open source") # test lazy history loading for installation date self.ensure_installation_date_and_lazy_history_loading(appdetails) # test apturl replacements # $kernel app = Application("", "linux-headers-$kernel", "channel=$distro-partner") self.assertEqual(app.pkgname, 'linux-headers-'+os.uname()[2]) # $distro details = app.get_details(db) from softwarecenter.distro import get_distro distro = get_distro().get_codename() self.assertEqual(app.request, 'channel=' + distro + '-partner')
def _get_app_details_from_app_dict(self, app_dict): item = PistonResponseObject.from_dict(app_dict) parser = SCAApplicationParser(item) doc = parser.make_doc(self.db._aptcache) app_details = AppDetails(self.db, doc) return app_details
def test_normal_dict(self): self.mock_app_details.non_empty_dict = {"moo": "bar"} properties = AppDetails.as_dbus_property_dict(self.mock_app_details) self.assertEqual(properties["non_empty_dict"], {"moo": "bar"})
def test_appdetails(self): from softwarecenter.testutils import get_test_db db = get_test_db() # see "apt-cache show casper|grep ^Tag" details = AppDetails(db, application=Application("", "casper")) self.assertTrue(len(details.tags) > 2)