Skip to content

Commit

Permalink
test even more regex
Browse files Browse the repository at this point in the history
  • Loading branch information
kytpbs committed Aug 21, 2024
1 parent 7bfddd6 commit f234439
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 5 deletions.
55 changes: 55 additions & 0 deletions Tests/video_system/regex/test_instagram_regex.py
Original file line number Diff line number Diff line change
@@ -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")
20 changes: 20 additions & 0 deletions Tests/video_system/regex/test_other_regex.py
Original file line number Diff line number Diff line change
@@ -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")
13 changes: 13 additions & 0 deletions Tests/video_system/regex/test_regex_base.py
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 7 additions & 5 deletions Tests/video_system/regex/test_twitter_regex.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
40 changes: 40 additions & 0 deletions Tests/video_system/regex/test_youtube_regex.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit f234439

Please sign in to comment.