diff --git a/Tests/video_system/regex/test_instagram_regex.py b/Tests/video_system/regex/test_instagram_regex.py new file mode 100644 index 0000000..99f81c9 --- /dev/null +++ b/Tests/video_system/regex/test_instagram_regex.py @@ -0,0 +1,55 @@ +import pytest + +from src.instagram import InstagramDownloader +from Tests.video_system.regex.test_regex_base import TestDownloaderRegex + + +class TestInstagramRegex(TestDownloaderRegex): + @pytest.fixture(autouse=True) + def setup_class(self): + super().setup(InstagramDownloader) + + def test_direct_reel_link(self): + assert self.check_link("https://www.instagram.com/reel/C2-vIqjsosW") + + def test_direct_post_link(self): + assert self.check_link("https://www.instagram.com/p/C2-vIqjsosW") + + def test_direct_link_with_params(self): + assert self.check_link( + "https://www.instagram.com/p/C2-vIqjsosW/?igsh=eGFma20zbWY0bDJs" + ) + assert self.check_link( + "https://www.instagram.com/reel/C2-vIqjsosW/?igsh=eGFma20zbWY0bDJs" + ) + + def test_shortened_link(self): + assert self.check_link("https://instagr.am/p/C2-vIqjsosW") + assert self.check_link("https://instagr.am/reel/C2-vIqjsosW") + + def test_extra_text_link(self): + assert self.check_link( + "Check this out: https://www.instagram.com/p/C2-vIqjsosW" + ) + assert self.check_link( + "Check this out: https://www.instagram.com/reel/C2-vIqjsosW" + ) + assert self.check_link( + "Dude look at this video fr fr https://www.instagram.com/reel/C2-vIqjsosW" + ) + + def test_invalid_link(self): + assert not self.check_link("https://www.instagram.com") + + def test_invalid_link_with_extra(self): + assert not self.check_link("Look at this: https://www.instagram.com") + + def test_invalid_shortened_link(self): + assert not self.check_link("https://instagr.am") + + def test_different_type_links(self): + assert not self.check_link("https://www.youtube.com/watch?v=dQw4w9WgXcQ") + assert not self.check_link("https://x.com/MIT_CSAIL/status/1363172815315214336") + + def test_non_link(self): + assert not self.check_link("This is not a link") diff --git a/Tests/video_system/regex/test_other_regex.py b/Tests/video_system/regex/test_other_regex.py new file mode 100644 index 0000000..636cc2b --- /dev/null +++ b/Tests/video_system/regex/test_other_regex.py @@ -0,0 +1,20 @@ +from src.downloading_system import get_downloader + + +class TestOtherDownloaderRegex: + def check_link(self, link: str): + return get_downloader(link) is not None + + def test_not_supported_links(self): + assert not self.check_link("https://facebook.com/1234") + assert not self.check_link( + "https://www.linkedin.com/posts/microsoft_microsoftlife-microsoftcareersemea-softwareengineerjobs-activity-7231661283509460992-3NLl" + ) + assert not self.check_link("https://twitch.tv/1234") + + def test_link_like_non_links(self): + assert not self.check_link("This is not a link") + assert not self.check_link("alink://link/link") + assert not self.check_link("https://") + assert not self.check_link("https://youtube./com/123") + assert not self.check_link("https://x./com/123") diff --git a/Tests/video_system/regex/test_regex_base.py b/Tests/video_system/regex/test_regex_base.py new file mode 100644 index 0000000..95ff9e3 --- /dev/null +++ b/Tests/video_system/regex/test_regex_base.py @@ -0,0 +1,13 @@ +from typing import Type + +from src.downloader import VideoDownloader +from src.downloading_system import get_downloader + + +class TestDownloaderRegex: + def setup(self, downloader_type_to_check: Type[VideoDownloader]) -> None: + self.downloader_type = downloader_type_to_check + + def check_link(self, link: str): + downloader = get_downloader(link) + return downloader is not None and isinstance(downloader(), self.downloader_type) diff --git a/Tests/video_system/regex/test_twitter_regex.py b/Tests/video_system/regex/test_twitter_regex.py index a27726f..5932411 100644 --- a/Tests/video_system/regex/test_twitter_regex.py +++ b/Tests/video_system/regex/test_twitter_regex.py @@ -1,11 +1,13 @@ -from src.downloading_system import get_downloader +import pytest + from src.twitter import TwitterDownloader +from Tests.video_system.regex.test_regex_base import TestDownloaderRegex -class TestTwitterRegex: - def check_link(self, link: str): - downloader = get_downloader(link) - return downloader is not None and isinstance(downloader(), TwitterDownloader) +class TestTwitterRegex(TestDownloaderRegex): + @pytest.fixture(autouse=True) + def setup_class(self): + super().setup(TwitterDownloader) def test_direct_link(self): assert self.check_link("https://x.com/MIT_CSAIL/status/1363172815315214336") diff --git a/Tests/video_system/regex/test_youtube_regex.py b/Tests/video_system/regex/test_youtube_regex.py new file mode 100644 index 0000000..e36d5bc --- /dev/null +++ b/Tests/video_system/regex/test_youtube_regex.py @@ -0,0 +1,40 @@ +import pytest + +from src.Youtube import YoutubeDownloader +from Tests.video_system.regex.test_regex_base import TestDownloaderRegex + + +class TestYoutubeRegex(TestDownloaderRegex): + @pytest.fixture(autouse=True) + def setup_class(self): + super().setup(YoutubeDownloader) + + def test_direct_link(self): + assert self.check_link("https://www.youtube.com/watch?v=dQw4w9WgXcQ") + + def test_direct_link_with_timestamp(self): + assert self.check_link("https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=10s") + + def test_shortened_link(self): + assert self.check_link("https://youtu.be/dQw4w9WgXcQ") + + def test_shortened_link_with_timestamp(self): + assert self.check_link("https://youtu.be/dQw4w9WgXcQ?t=10") + + def test_share_parameter_link(self): + assert self.check_link("https://youtu.be/dQw4w9WgXcQ?si=T3vbuTjMmskB3x3d") + + def test_extra_text_link(self): + assert self.check_link( + "Check this out: https://www.youtube.com/watch?v=dQw4w9WgXcQ" + ) + + def test_invalid_link(self): + assert not self.check_link("https://www.youtube.com") + + def test_invalid_shortened_link(self): + assert not self.check_link("https://youtu.be") + + def test_different_type_links(self): + assert not self.check_link("https://www.instagram.com/p/CMJ1J1JjJjJ/") + assert not self.check_link("https://x.com/MIT_CSAIL/status/1363172815315214336")