-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
69 lines (49 loc) · 1.75 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
from unittest import TestCase, defaultTestLoader
from main import app
from auth import AuthManager
from io import BytesIO
def make_orderer():
order = {}
def ordered(f):
order[f.__name__] = len(order)
return f
def compare(a, b):
return [1, -1][order[a] < order[b]]
return ordered, compare
ordered, compare = make_orderer()
defaultTestLoader.sortTestMethodsUsing = compare
class SimpleCDNTests(TestCase):
def setUp(self):
app.testing = True
self.client = app.test_client()
self._ctx = app.test_request_context()
self._ctx.push()
def tearDown(self):
if self._ctx:
self._ctx.pop()
@ordered
def test_user_registration(self):
with self.client:
self.client.post("register", data={"email": "test", "password": "testpass"})
with AuthManager() as auth:
self.assertIn("test", auth.keys())
@ordered
def test_login(self):
with self.client:
self.client.post("login", data={"email": "test", "password": "testpass"})
current_user = self.client.get("user").get_json()
self.assertEqual(current_user["username"], "test")
@ordered
def test_upload(self):
with self.client:
self.client.post("login", data={"email": "test", "password": "testpass"})
response = self.client.post(
"upload", data={"file": (BytesIO(b"Test file"), "test.txt")}
)
self.assertEqual(response.status_code, 302)
@ordered
def test_get_file(self):
with self.client:
response = self.client.get("/file/test/test.txt")
text = response.data.decode("UTF-8")
self.assertEqual(text, "Test file")