Beispiel #1
0
def test_download_file(monkeypatch):
    with requests_mock.Mocker() as m:
        origin_data = b'a' * 1025
        m.get('https://dummy-url.tld/file', content=origin_data)

        with tempfile.NamedTemporaryFile() as temp_file:
            download_file('https://dummy-url.tld/file', temp_file.name)
            temp_file.seek(0)
            data = temp_file.read()
    assert data == origin_data
Beispiel #2
0
    def download(self, version, build, architecture, locale):
        try:
            os.makedirs(self.config.download_directory)
        except OSError:  # XXX: Used for compatibility with Python 2. Use FileExistsError otherwise
            pass

        for api_suffix in self.get_api_suffix(architecture):
            apk_base_url = self.generate_apk_base_url(version, build, locale,
                                                      api_suffix)
            apk, checksums = craft_apk_and_checksums_url_and_download_locations(
                apk_base_url, self.config.download_directory, version, locale,
                architecture)

            download_file(apk['url'], apk['download_location'])
            download_file(checksums['url'], checksums['download_location'])

            check_apk_against_checksum_file(apk['download_location'],
                                            checksums['download_location'])
Beispiel #3
0
    def download(self, version, build, architecture, locale):
        try:
            os.makedirs(self.config.download_directory)
        except FileExistsError:
            pass

        for api_suffix in self.get_api_suffix(version, architecture):
            apk_base_url = self.generate_apk_base_url(version, build, locale,
                                                      api_suffix)
            urls_and_locations = craft_apk_and_checksums_url_and_download_locations(
                apk_base_url, self.config.download_directory, version, build,
                locale, architecture)
            apk = urls_and_locations['apk']
            checksums = urls_and_locations['checksums']

            download_file(apk['url'], apk['download_location'])
            download_file(checksums['url'], checksums['download_location'])

            check_apk_against_checksum_file(apk['download_location'],
                                            checksums['download_location'])
    async def download(self, session, version, build, architecture, locale):
        try:
            os.makedirs(self.download_directory)
        except FileExistsError:
            pass

        for api_suffix in get_api_suffix(version, architecture):
            apk_base_url = generate_apk_base_url(self.latest_nightly, version,
                                                 build, locale, api_suffix)
            urls_and_locations = craft_apk_and_checksums_url_and_download_locations(
                apk_base_url, self.download_directory, version, build, locale,
                architecture, api_suffix, self.latest_nightly)
            apk = urls_and_locations['apk']
            checksums = urls_and_locations['checksums']

            await asyncio.gather(
                download_file(session, apk['url'], apk['download_location']),
                download_file(session, checksums['url'],
                              checksums['download_location']))

            check_apk_against_checksum_file(apk['download_location'],
                                            checksums['download_location'])