45 lines · 1.2 KB
python
| 1 | from __future__ import annotations |
| 2 | |
| 3 | import sys |
| 4 | from pathlib import Path |
| 5 | |
| 6 | sys.path.insert(0, str(Path(__file__).resolve().parents[1])) |
| 7 | |
| 8 | from space_tape.download import DownloadError, parse_url |
| 9 | |
| 10 | |
| 11 | def test_spaces_link() -> None: |
| 12 | info = parse_url("https://x.com/i/spaces/1pKdRDlVbRrJW") |
| 13 | assert info["kind"] == "space" |
| 14 | assert info["space_id"] == "1pKdRDlVbRrJW" |
| 15 | assert info["host"] is None |
| 16 | assert info["url"] == "https://x.com/i/spaces/1pKdRDlVbRrJW" |
| 17 | |
| 18 | |
| 19 | def test_status_bakes_host() -> None: |
| 20 | info = parse_url("https://x.com/notpierce69/status/2100117423017906497") |
| 21 | assert info["kind"] == "status" |
| 22 | assert info["host"] == "notpierce69" |
| 23 | assert info["status_id"] == "2100117423017906497" |
| 24 | |
| 25 | |
| 26 | def test_twitter_dot_com() -> None: |
| 27 | info = parse_url("https://twitter.com/i/spaces/1pKdRDlVbRrJW") |
| 28 | assert info["space_id"] == "1pKdRDlVbRrJW" |
| 29 | |
| 30 | |
| 31 | def test_rejects_garbage() -> None: |
| 32 | try: |
| 33 | parse_url("https://example.com/not-a-space") |
| 34 | except DownloadError: |
| 35 | return |
| 36 | raise AssertionError("expected DownloadError") |
| 37 | |
| 38 | |
| 39 | if __name__ == "__main__": |
| 40 | test_spaces_link() |
| 41 | test_status_bakes_host() |
| 42 | test_twitter_dot_com() |
| 43 | test_rejects_garbage() |
| 44 | print("ok") |