from aqt import helper def test_helper_altlink(monkeypatch): class Message: headers = {"content-type": "text/plain", "length": 300} text = """ MirrorBrain/2.17.0 http://download.example.io/boo.7z.meta4 2020-03-04T01:11:48Z Example Project https://download.example.io 651 d49eba3937fb063caa48769e8f28377c 25d3a33d00c1e5880679a17fd4b8b831134cfa6f 37e50248cf061109e2cb92105cd2c36a6e271701d6d4a72c4e73c6d82aad790a bec628a149ed24a3a9b83747776ecca5a1fad11c 98b1dee3f741de51167a9428b0560cd2d1f4d945 8717a0cb3d14c1958de5981635c9b90b146da165 78cd2ae3ae37ca7c080a56a2b34eb33ec44a9ef1 http://mirrors.geekpie.club/boo.7z http://ftp.jaist.ac.jp/pub/boo.7z http://ftp.yz.yamagata-u.ac.jp/pub/boo.7z """ def mock_return(url): return Message() monkeypatch.setattr(helper, "_get_meta", mock_return) url = "http://foo.baz/qtproject/boo.7z" alt = "http://mirrors.geekpie.club/boo.7z" newurl = helper.altlink(url, alt) assert newurl.startswith("http://ftp.jaist.ac.jp/") def test_settings(tmp_path): config_path = tmp_path.joinpath("settings.ini") with open(config_path, "w") as f: f.write( """\ [DEFAULTS] [aqt] concurrency: 3 [mirrors] blacklist: ['http://mirrors.ustc.edu.cn', 'http://mirrors.tuna.tsinghua.edu.cn', 'http://mirrors.geekpie.club']""" ) config = helper.Settings(config_path) assert config.concurrency == 3 assert "http://mirrors.ustc.edu.cn" in config.blacklist