This repository has been archived by the owner on Jan 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtests.py
140 lines (115 loc) · 4.53 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import json
import unittest
import app
class DownloaderTestCase(unittest.TestCase):
def setUp(self):
app.app.testing = True
self.app = app.app.test_client()
self.headers = {
"Authorization": "Basic VVNFUk5BTUU6UEFTU1dPUkQ=",
"Content-Type": "application/json"
}
def make_request(self, data):
return self.app.post("/download/", data=json.dumps(data), headers=self.headers)
def get_request(self, endpoint):
return self.app.get(endpoint, headers=self.headers)
def make_wrong_request(self):
data = dict(
url="https://mrose.org/cc/png-test.png"
)
return self.app.post("/download/", data=json.dumps(data), headers={
"Content-Type": "application/json"
})
def test_invalid_url(self):
tmp = self.make_request(dict(
url="https://mrose"
))
assert tmp.status_code == 500
def test_landing_page(self):
code = self.get_request("/").status_code
assert code == 200
def test_downloads_page(self):
code = self.get_request("/downloads/").status_code
assert code == 200
def test_general_download(self):
old = app.conf["local_network_without_login"]
app.conf["local_network_without_login"] = False
tmp = self.make_request(dict(
url="http://theglow666.6f.sk/image_test/",
name="test",
category="test"
))
app.conf["local_network_without_login"] = old
assert tmp.status_code == 200
def test_general_download_without_name(self):
tmp = self.make_request(dict(
url="http://via.placeholder.com/359x150",
category="test2"
))
assert tmp.status_code == 200
def test_download_without_auth_local(self):
tmp = self.make_wrong_request()
assert tmp.status_code == 200
def test_download_without_auth_remote(self):
old = app.conf["local_network_without_login"]
app.conf["local_network_without_login"] = False
tmp = self.make_wrong_request()
app.conf["local_network_without_login"] = old
assert tmp.status_code == 401
def wrong_download(self, headers):
return self.app.post("/download/", data=json.dumps(dict(
url="https://mrose.org/cc/png-test.png"
)), headers=headers)
def test_download_with_wrong_auth(self):
old = app.conf["local_network_without_login"]
app.conf["local_network_without_login"] = False
tmp = self.wrong_download(headers={
"Authorization": "Basic VVNFUk5BTUUyOlBBU1NXT1JEMg==",
"Content-Type": "application/json"
})
app.conf["local_network_without_login"] = old
assert tmp.status_code == 401
def test_download_without_content_type(self):
tmp = self.wrong_download(headers={
"Authorization": "Basic VVNFUk5BTUU6UEFTU1dPUkQ="
})
assert tmp.status_code == 500
def test_youtubedl_crash(self):
app.ydl_installed = False
tmp = self.app.post("/download/", data=json.dumps(dict(
url="https://www.youtube.com/watch?v=NxR51tUcG60"
)), headers=self.headers)
assert tmp.status_code == 500
app.ydl_installed = True
def test_youtubedl(self):
data = {"url": "https://www.youtube.com/watch?v=NxR51tUcG60",
"user": "USERNAME"}
res = app.download_in_background(data)
assert res
def test_youtubedl_with_name(self):
data = {"url": "https://www.youtube.com/watch?v=NxR51tUcG60",
"user": "USERNAME",
"name": "youtube test",
"extension": ".mp4"}
res = app.download_in_background(data)
assert res
def test_youtubedl_only_audio(self):
data = {"url": "https://www.youtube.com/watch?v=NxR51tUcG60",
"user": "USERNAME",
"audioOnly": True}
res = app.download_in_background(data)
assert res
def test_pushbullet_crash(self):
oldKey = app.conf["users"][0]["pushbullet_token"]
app.conf["users"][0]["pushbullet_token"] = "Invalid"
tmp = app.on_complete("USERNAME", "test")
assert tmp is False
app.conf["users"][0]["pushbullet_token"] = oldKey
def test_pushbullet(self):
tmp = app.on_complete("USERNAME", "test")
assert tmp is True
def test_download_without_user(self):
tmp = app.on_complete(None, "test")
assert tmp is None
if __name__ == "__main__":
unittest.main()