Repository navigation
Expand file tree
/
Copy pathtest_link_detection.py
More file actions
59 lines (45 loc) · 2.41 KB
/
Copy pathtest_link_detection.py
File metadata and controls
59 lines (45 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from services.links.detection import detect_supported_service, extract_supported_link, extract_supported_links
def test_detect_supported_service_covers_all_supported_group_guard_links():
assert detect_supported_service("https://www.instagram.com/p/demo") == "instagram"
assert detect_supported_service("https://www.threads.com/@demo/post/Abc_123") == "threads"
assert detect_supported_service("https://www.tiktok.com/@demo/video/1") == "tiktok"
assert detect_supported_service("https://soundcloud.com/artist/track") == "soundcloud"
assert detect_supported_service("https://open.spotify.com/track/abc123?si=demo") == "spotify"
assert detect_supported_service("https://pin.it/demo123") == "pinterest"
assert detect_supported_service("https://youtu.be/demo") == "youtube"
assert detect_supported_service("https://music.youtube.com/watch?v=abc123") == "youtube"
assert detect_supported_service("https://x.com/demo/status/1") == "twitter"
def test_extract_supported_links_preserves_order_and_deduplicates():
text = (
"first https://youtu.be/demo "
"then https://www.instagram.com/reel/abc/ "
"again https://youtu.be/demo"
)
assert extract_supported_links(text) == [
("youtube", "https://youtu.be/demo"),
("instagram", "https://www.instagram.com/reel/abc/"),
]
def test_extract_supported_links_canonicalizes_threads_domain_and_tracking():
assert extract_supported_link("https://threads.net/@demo/post/Abc_123?utm_source=share") == (
"threads",
"https://threads.net/@demo/post/Abc_123",
)
def test_extract_supported_link_strips_trailing_sentence_punctuation():
assert extract_supported_link("watch this https://youtu.be/demo.") == (
"youtube",
"https://youtu.be/demo",
)
def test_extract_spotify_link_strips_tracking_query():
assert extract_supported_link("https://open.spotify.com/track/abc123?si=tracking") == (
"spotify",
"https://open.spotify.com/track/abc123",
)
def test_extract_supported_links_canonicalizes_tracking_query_params():
text = (
"https://www.instagram.com/reel/abc/?utm_source=ig_web_copy_link "
"https://www.youtube.com/watch?v=abc123&si=noise&utm_source=test&t=30"
)
assert extract_supported_links(text) == [
("instagram", "https://www.instagram.com/reel/abc/"),
("youtube", "https://www.youtube.com/watch?v=abc123&t=30"),
]