예제 #1
0
def downloader_can_download_files_over_http():
    downloader = Downloader(NoCachingStrategy())
    
    with create_temporary_dir() as server_root:
        files.write_file(os.path.join(server_root, "hello"), "Hello there!")
        with httpserver.start_static_http_server(server_root) as http_server:
            with create_temporary_dir() as download_dir:
                download_path = os.path.join(download_dir, "file")
                url = http_server.static_url("hello")
                downloader.download(url, download_path)
                assert_equal("Hello there!", files.read_file(download_path))
예제 #2
0
def download_fails_if_http_request_returns_404():
    downloader = Downloader(NoCachingStrategy())
    
    with create_temporary_dir() as server_root:
        with httpserver.start_static_http_server(server_root) as http_server:
            with create_temporary_dir() as download_dir:
                download_path = os.path.join(download_dir, "file")
                url = http_server.static_url("hello")
                try:
                    downloader.download(url, download_path)
                    assert False
                except DownloadError:
                    pass