import pytest from socials_util import SocialLink, SocialSiteId, determine_social_from_url PARSABLE_SOCIAL_IDS_COMBINED: list[tuple[str, object, str]] = [ # Tumblr formats ('https://triviallytrue.tumblr.com/', SocialSiteId.TUMBLR, 'triviallytrue'), ('https://www.triviallytrue.tumblr.com/', SocialSiteId.TUMBLR, 'triviallytrue'), ('https://tumblr.com/triviallytrue', SocialSiteId.TUMBLR, 'triviallytrue'), ('https://tumblr.com/blog/triviallytrue', SocialSiteId.TUMBLR, 'triviallytrue'), ( 'https://tumblr.com/blog/view/triviallytrue', SocialSiteId.TUMBLR, 'triviallytrue', ), ('https://www.tumblr.com/triviallytrue', SocialSiteId.TUMBLR, 'triviallytrue'), ('https://www.tumblr.com/blog/triviallytrue', SocialSiteId.TUMBLR, 'triviallytrue'), ( 'https://www.tumblr.com/blog/view/triviallytrue', SocialSiteId.TUMBLR, 'triviallytrue', ), ('http://worstdril.tumblr.com/', SocialSiteId.TUMBLR, 'worstdril'), ('https://deep-dark-fears.tumblr.com', SocialSiteId.TUMBLR, 'deep-dark-fears'), # Cohost formats ( 'https://cohost.org/andrewelmore?page=0', SocialSiteId.COHOST_PROFILE, 'andrewelmore', ), ( 'https://cohost.org/andrewelmore', SocialSiteId.COHOST_PROFILE, 'andrewelmore', ), # Reddit formats ( 'https://old.reddit.com/user/Harpsibored/submitted/', SocialSiteId.REDDIT_USER, 'Harpsibored', ), ( 'https://old.reddit.com/user/Harpsibored/submitted', SocialSiteId.REDDIT_USER, 'Harpsibored', ), ( 'https://old.reddit.com/user/Harpsibored/', SocialSiteId.REDDIT_USER, 'Harpsibored', ), ( 'https://old.reddit.com/user/Harpsibored', SocialSiteId.REDDIT_USER, 'Harpsibored', ), # Ko-fi formats ('https://ko-fi.com/A627LI1/shop/', SocialSiteId.KO_FI, 'A627LI1'), ('https://ko-fi.com/A627LI1/shop', SocialSiteId.KO_FI, 'A627LI1'), ('https://ko-fi.com/A627LI1/', SocialSiteId.KO_FI, 'A627LI1'), ('https://ko-fi.com/A627LI1', SocialSiteId.KO_FI, 'A627LI1'), # Twitter formats ('http://twitter.com/dril', SocialSiteId.TWITTER, 'dril'), ('http://www.twitter.com/dril', SocialSiteId.TWITTER, 'dril'), ('http://www.x.com/dril', SocialSiteId.TWITTER, 'dril'), ('http://x.com/dril', SocialSiteId.TWITTER, 'dril'), ('http://twitter.com/dril/media', SocialSiteId.TWITTER, 'dril'), ('http://www.twitter.com/dril/media', SocialSiteId.TWITTER, 'dril'), ('http://www.x.com/dril/media', SocialSiteId.TWITTER, 'dril'), ('http://x.com/dril/media', SocialSiteId.TWITTER, 'dril'), # Wikidata formats ('https://wikidata.org/wiki/Q594400', SocialSiteId.WIKIDATA, 'Q594400'), ('https://m.wikidata.org/wiki/Q594400', SocialSiteId.WIKIDATA, 'Q594400'), # YouTube formats ( 'https://youtube.com/@WheelieYellow', SocialSiteId.YOUTUBE_CHANNEL_HANDLE, 'WheelieYellow', ), ( 'https://youtube.com/@WheelieYellow/', SocialSiteId.YOUTUBE_CHANNEL_HANDLE, 'WheelieYellow', ), ( 'https://www.youtube.com/@WheelieYellow', SocialSiteId.YOUTUBE_CHANNEL_HANDLE, 'WheelieYellow', ), ( 'https://www.youtube.com/@WheelieYellow/', SocialSiteId.YOUTUBE_CHANNEL_HANDLE, 'WheelieYellow', ), ( 'https://www.youtube.com/@WheelieYellow/featured', SocialSiteId.YOUTUBE_CHANNEL_HANDLE, 'WheelieYellow', ), # GitHub ('https://github.com/love2d/love', SocialSiteId.GITHUB_REPOSITORY, 'love2d/love'), ('https://github.com/love2d/love/', SocialSiteId.GITHUB_REPOSITORY, 'love2d/love'), ( 'https://github.com/love2d/love/releases', SocialSiteId.GITHUB_REPOSITORY, 'love2d/love', ), # ArtStation ('https://toraji.artstation.com', SocialSiteId.ARTSTATION_PAGE, 'toraji'), ('https://www.artstation.com/toraji', SocialSiteId.ARTSTATION_PAGE, 'toraji'), ( 'https://www.artstation.com/toraji/profile', SocialSiteId.ARTSTATION_PAGE, 'toraji', ), # Tiktok ( 'https://tiktok.com/@depthsofwikipedia', SocialSiteId.TIKTOK_USER, 'depthsofwikipedia', ), ( 'https://www.tiktok.com/@depthsofwikipedia', SocialSiteId.TIKTOK_USER, 'depthsofwikipedia', ), ( 'https://www.tiktok.com/@depthsofwikipedia?lang=en', SocialSiteId.TIKTOK_USER, 'depthsofwikipedia', ), # Instagram ( 'https://instagram.com/_richardparry_', SocialSiteId.INSTAGRAM_PAGE, '_richardparry_', ), ('https://instagram.com/j_kmor/', SocialSiteId.INSTAGRAM_PAGE, 'j_kmor'), ( 'https://instagram.com/cullensartbox/', SocialSiteId.INSTAGRAM_PAGE, 'cullensartbox', ), ( 'https://www.instagram.com/timkongart/', SocialSiteId.INSTAGRAM_PAGE, 'timkongart', ), ('https://www.instagram.com/kcn.wu/', SocialSiteId.INSTAGRAM_PAGE, 'kcn.wu'), ( 'https://www.instagram.com/itsbettyjiang', SocialSiteId.INSTAGRAM_PAGE, 'itsbettyjiang', ), # Facebook ( 'https://www.facebook.com/fredagscafeen.dk/', SocialSiteId.FACEBOOK_PAGE, 'fredagscafeen.dk', ), # Pixiv ('https://www.pixiv.net/users/14866303', SocialSiteId.PIXIV_USER_ID, '14866303'), ( 'https://www.pixiv.net/member.php?id=109710', SocialSiteId.PIXIV_USER_ID, '109710', ), # Etsy ( 'https://www.etsy.com/shop/aleksiremesart', SocialSiteId.ETSY_SHOP, 'aleksiremesart', ), # Deviantart ( 'https://www.deviantart.com/solquiet', SocialSiteId.DEVIANT_ART_ACCOUNT, 'solquiet', ), ('https://solquiet.deviantart.com/', SocialSiteId.DEVIANT_ART_ACCOUNT, 'solquiet'), ] NOT_PARSABLE = [ # Twitter intents are not supported 'twitter.com/intent/user?user_id=123', 'https://twitter.com/intent/user?user_id=123', 'https://twitter.com/intent/user', 'https://twitter.com/intent', ] @pytest.mark.parametrize( 'url,expected_social_site_id,expected_social_id', PARSABLE_SOCIAL_IDS_COMBINED, ) def test_parse_social_ids(url, expected_social_site_id, expected_social_id): social_link: SocialLink | None = determine_social_from_url(url) assert social_link is not None, url assert (social_link.social_id, social_link.social_site_id) == ( expected_social_id, expected_social_site_id, ), url @pytest.mark.parametrize('url', NOT_PARSABLE) def test_not_parsable(url: str): assert determine_social_from_url(url) is None