def test_dump_url_content(tmpdir): # dump_url_content(url, content, dumpdir) dumpdir = str(tmpdir.mkdir("test_dump_url_content")) url = "http://www.example.com/" content = "http://www.example.com" filepath = dump_url_content(url, content, dumpdir) assert os.path.join(dumpdir, url_to_filename(url)) == filepath assert os.path.isfile(filepath) with file(filepath) as dumped_file: assert content == dumped_file.read()
def test_url_to_filename(): assert url_to_filename("http://example.com/") == "http%3A____example.com__" assert url_to_filename("http://example.com/?q=中文") == \ "http%3A____example.com__%3Fq%3D%E4%B8%AD%E6%96%87"