"""Download attempt ordering: cheapest bandwidth first. Direct (server IP) -> flat-rate static ISP proxies (uncapped 1080p, free bytes) -> per-GB paid proxy (720p cost cap) -> conservative fallback. The ``capped`` flag marks the attempts whose bytes are billed per GB (drives the 720p format cap and the PROXY_BYTES monthly counter). """ import pytest main = pytest.importorskip("main") plan = main.plan_download_attempts STATICS = ["http://s1", "http://s2", "http://s3"] PAID = "http://paid" class TestOrdering: def test_full_chain(self): got = plan(True, STATICS, PAID, True) assert got == [ ('HD-direct', False, None), ('HD-static1', False, "http://s1"), ('HD-static2', False, "http://s2"), ('HD-static3', False, "http://s3"), ('HD', True, PAID), ('fallback', True, PAID), ] def test_statics_only_fallback_uses_a_static(self): got = plan(False, STATICS, None, True) assert got[-1] == ('fallback', False, "http://s1") assert ('HD', False, None) in got # direct HD still tried, uncapped def test_selfhost_no_proxies_matches_legacy_chain(self): assert plan(False, [], None, True) == [ ('HD', False, None), ('fallback', False, None), ] def test_no_hd_args_still_has_fallback(self): assert plan(False, [], PAID, False) == [('fallback', True, PAID)] def test_paid_attempts_are_the_only_capped_ones(self): got = plan(True, STATICS, PAID, True) for _label, capped, proxy in got: assert capped == (proxy == PAID)