Пример #1
0
def download_language_pack(lang):
    logging.debug("Downloading base language pack %s for creating the debugging language." % BASE_LANGUAGE_PACK)
    url = get_language_pack_url(lang)

    try:
        logging.debug("Downloading from {url}.".format(url=url))
        resp = requests.get(url)
        resp.raise_for_status()
    except requests.ConnectionError as e:
        logging.error("Error downloading %s language pack: %s" % (lang, e))
        sys.exit(1)

    logging.debug("Successfully downloaded base language pack %s" % lang)
    return zipfile.ZipFile(StringIO(resp.content))
    def test_download_language_pack(self, get_method):

        # so the next n lines before a newline separator are all about
        # creating a dummy zipfile that is readable by zipfile.ZipFile
        dummy_file = StringIO()
        zf = zipfile.ZipFile(dummy_file, mode="w")
        zf.write(__file__)      # write the current file into the zipfile, just so we have something in here
        zf.close()
        get_method.return_value.content = dummy_file.getvalue()  # should still be convertible to a zipfile

        lang = "dummylanguage"
        result = mod.download_language_pack(lang)

        get_method.assert_called_once_with(get_language_pack_url(lang))
        self.assertIsInstance(result, zipfile.ZipFile)