This repository has been archived by the owner on Jan 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtests.py
85 lines (73 loc) · 3.4 KB
/
tests.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os
import sys
import unittest
from scrapper import *
class ScrapperTest(unittest.TestCase):
def setUp(self):
super().setUp()
self.downloader = Scrapper()
def tearDown(self) -> None:
super().tearDown()
# remove all .mp4 files here
for file in os.listdir():
if file.endswith(".mp4"):
os.remove(file)
def testThatAllRequirementsSatisfied(self):
if sys.modules.get('wget') is None or sys.modules.get('selenium') is None \
or sys.modules.get('webdriver_manager') is None or sys.modules.get('time') is None:
self.fail("requirements are not satisfied")
def testThatUrlValidationWorks(self):
validUrls = [
"https://www.aparat.com/v/4Z9Zb",
"www.aparat.com/v/4Z9Zb/",
]
invalidUrls = [
"https://www.google.com/",
"aparat.co/v/4Z9Zb",
# "edrisranjbar.ir/www.aparat.com/",
# "https://www.edrisranjbar.ir/index.php?www.aparat.com/",
]
for url in validUrls:
self.assertTrue(self.downloader.isUrlValid(url))
for url in invalidUrls:
self.assertIsNot(self.downloader.isUrlValid(url), True)
def testThatWeCanGetDownloadLinkOfASingleVideo(self):
url = "https://www.aparat.com/v/6hSwx"
downloadLink = self.downloader.getASingleVideoDownloadLink(url, '720')
self.assertTrue(
"https://" in downloadLink
)
def testThatWeGetPropperErrorMessages(self):
# expect to get "Download link was not found"
with self.assertRaisesRegex(Exception, "Download link was not found"):
self.downloader.getASingleVideoDownloadLink(
"https://www.aparat.com/v/6hSws2dsdsd")
# expect to get "URL is invalid"
with self.assertRaisesRegex(Exception, "URL is invalid"):
self.downloader.getASingleVideoDownloadLink(
"aparat.co/v/4Z9Zb")
def testThatWeCanDownloadAFile(self):
self.downloader.title = "test video"
dl_link = "https://aspb26.cdn.asset.aparat.com/aparat-video/56b2e43e9d89dbf760db3a1f672696e332127095-144p.mp4?wmsAuthSign=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbiI6ImI1NGJiZWQ0ZWYwNTk0NTRkODRiZmMyZjIwMTk3YmQyIiwiZXhwIjoxNjYxMzAxNTkxLCJpc3MiOiJTYWJhIElkZWEgR1NJRyJ9.jW-pu7yXyIoETHIfkqp9882noLmt8oM9OqTcIDuEiMs"
try:
self.downloader.downloadSingleVideo(
dl_link)
except Exception as errorMessage:
self.fail(errorMessage)
def testThatWeCanGetAllOfTheVideosLinksInAPlaylist(self):
# returned links list's length should be more that 0
count = len(self.downloader.getPlaylistVideoLinks(
"https://www.aparat.com/v/GojkW"))
self.assertGreater(count, 0)
def testThatWeCanDetectPlaylistURL(self):
isAPlayList = self.downloader.isAPlayList(
"https://www.aparat.com/v/GojkW")
self.assertTrue(isAPlayList)
def testThatWeCanGetDifferentQualitiesLink(self):
# we expect to get all 6 video qualities for this video
url = "https://www.aparat.com/v/6hSwx"
fetched_qualities = self.downloader.getVideoQualitiesLink(url)
original_qualities = ["1080", "720", "480", "360", "240", "144"]
for quality in original_qualities:
if quality not in fetched_qualities:
self.fail(f"{quality} not found!")