forked from python-discord/site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_logs.py
74 lines (59 loc) · 1.88 KB
/
test_logs.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
"""Tests the `/api/bot/clean` endpoint."""
import json
from tests import SiteTest, app
class TestCleanLogAPI(SiteTest):
"""
Tests submitting a clean log and
verifies that we get a UUID in return.
Also ensures that we get a 400 if we send in bad data.
"""
def test_returns_400_on_bad_data(self):
bad_data = json.dumps({
"scubfire": "testiclaes"
})
response = self.client.post(
'/bot/logs',
app.config['API_SUBDOMAIN'],
headers=app.config['TEST_HEADER'],
data=bad_data
)
self.assert400(response)
def test_submit_clean_log(self):
good_data = json.dumps({
"log_data": [
{
"author": "something",
"user_id": "12345151",
"role_id": "4818413",
"content": "testy",
"timestamp": "this way comes",
"embeds": [{"fire":"nanny"}],
"attachments": ["<Attachment>"],
}
]
})
response = self.client.post(
'/bot/logs',
app.config['API_SUBDOMAIN'],
headers=app.config['TEST_HEADER'],
data=good_data
)
log_id = response.json.get("log_id")
self.assert200(response)
self.assertIsNotNone(log_id)
self.assertGreater(len(log_id), 2)
self.assertEqual(type(log_id), str)
class TestCleanLogFrontEnd(SiteTest):
"""
Tests the frontend for
viewing the clean logs.
Best I can do with our current
system is check if I'm redirected,
since this is behind OAuth.
"""
def test_clean_log_frontend_returns_302(self):
response = self.client.get(
f'/bot/logs/1',
'http://pytest.local'
)
self.assertEqual(response.status_code, 302)