Пример #1
0
class RegressionsTestCase(unittest.TestCase):

    def setUp(self):
        self.sca = SoftwareCenterAgent()
        self.sca.emit = Mock()
        
    def _get_exhibit_list_from_emit_call(self):
        args, kwargs = self.sca.emit.call_args
        scagent, exhibit_list = args
        return exhibit_list

    def test_regression_lp1004417(self):
        mock_ex = Mock()
        mock_ex.package_names = "foo,bar\n\r"
        results = [mock_ex]
        self.sca._on_exhibits_data_available(None, results)
        self.assertTrue(self.sca.emit.called)
        # and ensure we get the right list len
        exhibit_list = self._get_exhibit_list_from_emit_call()
        self.assertEqual(len(exhibit_list), 1)
        # and the right data in the list
        exhibit = exhibit_list[0]
        self.assertEqual(exhibit.package_names, "foo,bar")
        self.assertFalse(exhibit.package_names.endswith("\n\r"))

    def test_regression_lp1043152(self):
        mock_ex = Mock()
        mock_ex.package_names = "moo, baa, lalala"
        results = [mock_ex]
        self.sca._on_exhibits_data_available(None, results)
        # ensure that the right data in the list
        exhibit = self._get_exhibit_list_from_emit_call()[0]
        self.assertEqual(exhibit.package_names, "moo,baa,lalala")
Пример #2
0
class RegressionsTestCase(unittest.TestCase):
    def setUp(self):
        self.sca = SoftwareCenterAgent()
        self.sca.emit = Mock()

    def _get_exhibit_list_from_emit_call(self):
        args, kwargs = self.sca.emit.call_args
        scagent, exhibit_list = args
        return exhibit_list

    def test_regression_lp1004417(self):
        mock_ex = Mock()
        mock_ex.package_names = "foo,bar\n\r"
        results = [mock_ex]
        self.sca._on_exhibits_data_available(None, results)
        self.assertTrue(self.sca.emit.called)
        # and ensure we get the right list len
        exhibit_list = self._get_exhibit_list_from_emit_call()
        self.assertEqual(len(exhibit_list), 1)
        # and the right data in the list
        exhibit = exhibit_list[0]
        self.assertEqual(exhibit.package_names, "foo,bar")
        self.assertFalse(exhibit.package_names.endswith("\n\r"))

    def test_regression_lp1043152(self):
        mock_ex = Mock()
        mock_ex.package_names = "moo, baa, lalala"
        results = [mock_ex]
        self.sca._on_exhibits_data_available(None, results)
        # ensure that the right data in the list
        exhibit = self._get_exhibit_list_from_emit_call()[0]
        self.assertEqual(exhibit.package_names, "moo,baa,lalala")
Пример #3
0
    def test_scaagent_query_available_for_me_uses_complete_only(self):
        run_generic_piston_helper_fn = (
            'softwarecenter.backend.spawn_helper.SpawnHelper.'
            'run_generic_piston_helper')
        with patch(run_generic_piston_helper_fn) as mock_run_piston_helper:
            sca = SoftwareCenterAgent()
            sca.query_available_for_me()

            mock_run_piston_helper.assert_called_with(
                'SoftwareCenterAgentAPI', 'subscriptions_for_me',
                complete_only=True)
    def test_scaagent_query_available_for_me_uses_complete_only(self):
        run_generic_piston_helper_fn = (
            'softwarecenter.backend.spawn_helper.SpawnHelper.'
            'run_generic_piston_helper')
        with patch(run_generic_piston_helper_fn) as mock_run_piston_helper:
            sca = SoftwareCenterAgent()
            sca.query_available_for_me()

            mock_run_piston_helper.assert_called_with('SoftwareCenterAgentAPI',
                                                      'subscriptions_for_me',
                                                      complete_only=True)
 def test_scagent_query_available(self):
     sca = SoftwareCenterAgent()
     sca.connect("available", self.on_query_done)
     sca.connect("error", self.on_query_error)
     sca.query_available()
     self.loop.run()
     self.assertFalse(self.error)
 def test_scagent_query_exhibits(self):
     sca = SoftwareCenterAgent()
     sca.connect("exhibits", self.on_query_done)
     sca.connect("error", self.on_query_error)
     sca.query_exhibits()
     self.loop.run()
     self.assertFalse(self.error)
Пример #7
0
    def _append_banner_ads(self):
        self.exhibit_banner = ExhibitBanner()
        self.exhibit_banner.set_exhibits([FeaturedExhibit()])
        self.exhibit_banner.connect(
            "show-exhibits-clicked", self._on_show_exhibits)

        # query using the agent
        scagent = SoftwareCenterAgent()
        scagent.connect("exhibits", self._filter_and_set_exhibits)
        scagent.query_exhibits()

        a = Gtk.Alignment()
        a.set_padding(0, StockEms.SMALL, 0, 0)
        a.add(self.exhibit_banner)
        self.vbox.pack_start(a, False, False, 0)
Пример #8
0
def update_from_software_center_agent(db, cache, ignore_cache=False, include_sca_qa=False):
    """ update index based on the software-center-agent data """

    def _available_cb(sca, available):
        # print "available: ", available
        LOG.debug("available: '%s'" % available)
        sca.available = available
        sca.good_data = True
        loop.quit()

    def _error_cb(sca, error):
        LOG.warn("error: %s" % error)
        sca.available = []
        sca.good_data = False
        loop.quit()

    # use the anonymous interface to s-c-agent, scales much better and is
    # much cache friendlier
    from softwarecenter.backend.scagent import SoftwareCenterAgent

    # FIXME: honor ignore_etag here somehow with the new piston based API
    sca = SoftwareCenterAgent(ignore_cache)
    sca.connect("available", _available_cb)
    sca.connect("error", _error_cb)
    sca.available = None
    if include_sca_qa:
        sca.query_available_qa()
    else:
        sca.query_available()
    # create event loop and run it until data is available
    # (the _available_cb and _error_cb will quit it)
    context = GObject.main_context_default()
    loop = GObject.MainLoop(context)
    loop.run()
    # process data
    for entry in sca.available:
        # process events
        while context.pending():
            context.iteration()
        try:
            # now the normal parser
            parser = SCAApplicationParser(entry)
            index_app_info_from_parser(parser, db, cache)
        except Exception as e:
            LOG.warning("error processing: %s " % e)
    # return true if we have updated entries (this can also be an empty list)
    # but only if we did not got a error from the agent
    return sca.good_data
Пример #9
0
 def disabled_test_scagent_query_exhibits(self):
     sca = SoftwareCenterAgent()
     sca.connect("exhibits", self.on_query_done)
     sca.connect("error", self.on_query_error)
     sca.query_exhibits()
     self.loop.run()  
     self.assertFalse(self.error)
Пример #10
0
 def test_scagent_query_available(self):
     sca = SoftwareCenterAgent()
     sca.connect("available", self.on_query_done)
     sca.connect("error", self.on_query_error)
     sca.query_available()
     self.loop.run()        
     self.assertFalse(self.error)
Пример #11
0
 def test_regression_lp1004417(self):
     mock_ex = Mock()
     mock_ex.package_names = "foo,bar\n\r"
     results = [mock_ex]
     sca = SoftwareCenterAgent()
     sca.emit = Mock()
     sca._on_exhibits_data_available(None, results)
     self.assertTrue(sca.emit.called)
     # get the args to "emit()"
     args, kwargs = sca.emit.call_args
     # split the args up
     scagent, exhibit_list = args
     # and ensure we get the right list len
     self.assertEqual(len(exhibit_list), 1)
     # and the right data in the list
     exhibit = exhibit_list[0]
     self.assertEqual(exhibit.package_names, "foo,bar")
     self.assertFalse(exhibit.package_names.endswith("\n\r"))
 def test_regression_lp1004417(self):
     mock_ex = Mock()
     mock_ex.package_names = "foo,bar\n\r"
     results = [mock_ex]
     sca = SoftwareCenterAgent()
     sca.emit = Mock()
     sca._on_exhibits_data_available(None, results)
     self.assertTrue(sca.emit.called)
     # get the args to "emit()"
     args, kwargs = sca.emit.call_args
     # split the args up
     scagent, exhibit_list = args
     # and ensure we get the right list len
     self.assertEqual(len(exhibit_list), 1)
     # and the right data in the list
     exhibit = exhibit_list[0]
     self.assertEqual(exhibit.package_names, "foo,bar")
     self.assertFalse(exhibit.package_names.endswith("\n\r"))
Пример #13
0
    def _append_banner_ads(self):
        self.exhibit_banner = ExhibitBanner()
        self.exhibit_banner.set_exhibits([FeaturedExhibit()])
        self.exhibit_banner.connect(
            "show-exhibits-clicked", self._on_show_exhibits)

        # query using the agent
        scagent = SoftwareCenterAgent()
        scagent.connect("exhibits", self._filter_and_set_exhibits)
        scagent.query_exhibits()

        a = Gtk.Alignment()
        a.set_padding(0, StockEms.SMALL, 0, 0)
        a.add(self.exhibit_banner)
        self.vbox.pack_start(a, False, False, 0)
Пример #14
0
def update_from_software_center_agent(db, cache, ignore_cache=False,
                                      include_sca_qa=False):
    """ update index based on the software-center-agent data """
    def _available_cb(sca, available):
        # print "available: ", available
        LOG.debug("available: '%s'" % available)
        sca.available = available
        sca.good_data = True
        loop.quit()
    def _error_cb(sca, error):
        LOG.warn("error: %s" % error)
        sca.available = []
        sca.good_data = False
        loop.quit()
    # use the anonymous interface to s-c-agent, scales much better and is
    # much cache friendlier
    from softwarecenter.backend.scagent import SoftwareCenterAgent
    # FIXME: honor ignore_etag here somehow with the new piston based API
    sca = SoftwareCenterAgent(ignore_cache)
    sca.connect("available", _available_cb)
    sca.connect("error", _error_cb)
    sca.available = None
    if include_sca_qa:
        sca.query_available_qa()
    else:
        sca.query_available()
    # create event loop and run it until data is available 
    # (the _available_cb and _error_cb will quit it)
    context = GObject.main_context_default()
    loop = GObject.MainLoop(context)
    loop.run()
    # process data
    for entry in sca.available:
        # process events
        while context.pending():
            context.iteration()
        try:
            # magic channel
            entry.channel = AVAILABLE_FOR_PURCHASE_MAGIC_CHANNEL_NAME
            # icon is transmited inline
            if hasattr(entry, "icon_data") and entry.icon_data:
                icondata = base64.b64decode(entry.icon_data)
            elif hasattr(entry, "icon_64_data") and entry.icon_64_data:
                # workaround for scagent bug #740112
                icondata = base64.b64decode(entry.icon_64_data)
            else:
                icondata = ""
            # write it if we have data
            if icondata:
            # the iconcache gets mightly confused if there is a "." in the name
                iconname = "sc-agent-%s" % entry.package_name.replace(".", "__")
                open(os.path.join(
                        softwarecenter.paths.SOFTWARE_CENTER_ICON_CACHE_DIR,
                        "%s.png" % iconname),"w").write(icondata)
                entry.icon = iconname
            # now the normal parser
            parser = SoftwareCenterAgentParser(entry)
            index_app_info_from_parser(parser, db, cache)
        except Exception as e:
            LOG.warning("error processing: %s " % e)
    # return true if we have updated entries (this can also be an empty list)
    # but only if we did not got a error from the agent
    return sca.good_data
Пример #15
0
def update_from_software_center_agent(db,
                                      cache,
                                      ignore_cache=False,
                                      include_sca_qa=False):
    """ update index based on the software-center-agent data """
    def _available_cb(sca, available):
        # print "available: ", available
        LOG.debug("available: '%s'" % available)
        sca.available = available
        sca.good_data = True
        loop.quit()

    def _error_cb(sca, error):
        LOG.warn("error: %s" % error)
        sca.available = []
        sca.good_data = False
        loop.quit()

    # use the anonymous interface to s-c-agent, scales much better and is
    # much cache friendlier
    from softwarecenter.backend.scagent import SoftwareCenterAgent
    # FIXME: honor ignore_etag here somehow with the new piston based API
    sca = SoftwareCenterAgent(ignore_cache)
    sca.connect("available", _available_cb)
    sca.connect("error", _error_cb)
    sca.available = None
    if include_sca_qa:
        sca.query_available_qa()
    else:
        sca.query_available()
    # create event loop and run it until data is available
    # (the _available_cb and _error_cb will quit it)
    context = GObject.main_context_default()
    loop = GObject.MainLoop(context)
    loop.run()
    # process data
    for entry in sca.available:
        # process events
        while context.pending():
            context.iteration()
        try:
            # magic channel
            entry.channel = AVAILABLE_FOR_PURCHASE_MAGIC_CHANNEL_NAME
            # icon is transmited inline
            if hasattr(entry, "icon_data") and entry.icon_data:
                icondata = base64.b64decode(entry.icon_data)
            elif hasattr(entry, "icon_64_data") and entry.icon_64_data:
                # workaround for scagent bug #740112
                icondata = base64.b64decode(entry.icon_64_data)
            else:
                icondata = ""
            # write it if we have data
            if icondata:
                # the iconcache gets mightly confused if there is a "." in the name
                iconname = "sc-agent-%s" % entry.package_name.replace(
                    ".", "__")
                open(
                    os.path.join(
                        softwarecenter.paths.SOFTWARE_CENTER_ICON_CACHE_DIR,
                        "%s.png" % iconname), "w").write(icondata)
                entry.icon = iconname
            # now the normal parser
            parser = SoftwareCenterAgentParser(entry)
            index_app_info_from_parser(parser, db, cache)
        except Exception as e:
            LOG.warning("error processing: %s " % e)
    # return true if we have updated entries (this can also be an empty list)
    # but only if we did not got a error from the agent
    return sca.good_data
Пример #16
0
 def setUp(self):
     self.sca = SoftwareCenterAgent()
     self.sca.emit = Mock()
Пример #17
0
def update_from_software_center_agent(db,
                                      cache,
                                      ignore_cache=False,
                                      include_sca_qa=False):
    """Update the index based on the software-center-agent data."""
    def _available_cb(sca, available):
        LOG.debug("update_from_software_center_agent: available: %r",
                  available)
        sca.available = available
        sca.good_data = True
        loop.quit()

    def _available_for_me_cb(sca, available_for_me):
        LOG.debug("update_from_software_center_agent: available_for_me: %r",
                  available_for_me)
        sca.available_for_me = available_for_me
        loop.quit()

    def _error_cb(sca, error):
        LOG.warn("update_from_software_center_agent: error: %r", error)
        sca.good_data = False
        loop.quit()

    context = GLib.main_context_default()
    loop = GLib.MainLoop(context)

    sca = SoftwareCenterAgent(ignore_cache)
    sca.connect("available", _available_cb)
    sca.connect("available-for-me", _available_for_me_cb)
    sca.connect("error", _error_cb)
    sca.available = []
    sca.available_for_me = []

    # query what is available for me first
    available_for_me_pkgnames = set()
    # this will ensure we do not trigger a login dialog
    helper = UbuntuSSO()
    token = helper.find_oauth_token_sync()
    if token:
        sca.query_available_for_me(no_relogin=True)
        loop.run()
        for item in sca.available_for_me:
            try:
                parser = SCAPurchasedApplicationParser(item)
                parser.index_app_info(db, cache)
                available_for_me_pkgnames.add(item.application["package_name"])
            except:
                LOG.exception("error processing: %r", item)

    # ... now query all that is available
    if include_sca_qa:
        sca.query_available_qa()
    else:
        sca.query_available()

    # create event loop and run it until data is available
    # (the _available_cb and _error_cb will quit it)
    loop.run()

    # process data
    for entry in sca.available:

        # do not add stuff here that's already purchased to avoid duplication
        if entry.package_name in available_for_me_pkgnames:
            continue

        # process events
        while context.pending():
            context.iteration()
        try:
            # now the normal parser
            parser = SCAApplicationParser(entry)
            parser.index_app_info(db, cache)
        except:
            LOG.exception(
                "update_from_software_center_agent: "
                "error processing %r:", entry.name)

    # return true if we have updated entries (this can also be an empty list)
    # but only if we did not got a error from the agent
    return sca.good_data
def update_from_software_center_agent(db, cache, ignore_cache=False,
                                      include_sca_qa=False):
    """ update index based on the software-center-agent data """
    def _available_cb(sca, available):
        # print "available: ", available
        LOG.debug("available: '%s'" % available)
        sca.available = available
        sca.good_data = True
        loop.quit()

    def _error_cb(sca, error):
        LOG.warn("error: %s" % error)
        sca.available = []
        sca.good_data = False
        loop.quit()
    # use the anonymous interface to s-c-agent, scales much better and is
    # much cache friendlier
    from softwarecenter.backend.scagent import SoftwareCenterAgent
    # FIXME: honor ignore_etag here somehow with the new piston based API
    sca = SoftwareCenterAgent(ignore_cache)
    sca.connect("available", _available_cb)
    sca.connect("error", _error_cb)
    sca.available = None
    if include_sca_qa:
        sca.query_available_qa()
    else:
        sca.query_available()
    # create event loop and run it until data is available
    # (the _available_cb and _error_cb will quit it)
    context = GObject.main_context_default()
    loop = GObject.MainLoop(context)
    loop.run()
    # process data
    for entry in sca.available:
        # process events
        while context.pending():
            context.iteration()
        try:
            # now the normal parser
            parser = SCAApplicationParser(entry)
            index_app_info_from_parser(parser, db, cache)
        except Exception as e:
            LOG.warning("error processing: %s " % e)
    # return true if we have updated entries (this can also be an empty list)
    # but only if we did not got a error from the agent
    return sca.good_data
Пример #19
0
def update_from_software_center_agent(db, cache, ignore_cache=False,
                                      include_sca_qa=False):
    """Update the index based on the software-center-agent data."""

    def _available_cb(sca, available):
        LOG.debug("update_from_software_center_agent: available: %r",
                  available)
        sca.available = available
        sca.good_data = True
        loop.quit()

    def _available_for_me_cb(sca, available_for_me):
        LOG.debug("update_from_software_center_agent: available_for_me: %r",
                  available_for_me)
        sca.available_for_me = available_for_me
        loop.quit()

    def _error_cb(sca, error):
        LOG.warn("update_from_software_center_agent: error: %r", error)
        sca.good_data = False
        loop.quit()

    context = GLib.main_context_default()
    loop = GLib.MainLoop(context)

    sca = SoftwareCenterAgent(ignore_cache)
    sca.connect("available", _available_cb)
    sca.connect("available-for-me", _available_for_me_cb)
    sca.connect("error", _error_cb)
    sca.available = []
    sca.available_for_me = []

    # query what is available for me first
    available_for_me_pkgnames = set()
    # this will ensure we do not trigger a login dialog
    helper = UbuntuSSO()
    token = helper.find_oauth_token_sync()
    if token:
        sca.query_available_for_me(no_relogin=True)
        loop.run()
        for item in sca.available_for_me:
            try:
                parser = SCAPurchasedApplicationParser(item)
                parser.index_app_info(db, cache)
                available_for_me_pkgnames.add(item.application["package_name"])
            except:
                LOG.exception("error processing: %r", item)

    # ... now query all that is available
    if include_sca_qa:
        sca.query_available_qa()
    else:
        sca.query_available()

    # create event loop and run it until data is available
    # (the _available_cb and _error_cb will quit it)
    loop.run()

    # process data
    for entry in sca.available:

        # do not add stuff here that's already purchased to avoid duplication
        if entry.package_name in available_for_me_pkgnames:
            continue

        # process events
        while context.pending():
            context.iteration()
        try:
            # now the normal parser
            parser = SCAApplicationParser(entry)
            parser.index_app_info(db, cache)
        except:
            LOG.exception("update_from_software_center_agent: "
                          "error processing %r:", entry.name)

    # return true if we have updated entries (this can also be an empty list)
    # but only if we did not got a error from the agent
    return sca.good_data
Пример #20
0
 def setUp(self):
     self.sca = SoftwareCenterAgent()
     self.sca.emit = Mock()