-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
98 lines (75 loc) · 3.61 KB
/
test.py
File metadata and controls
98 lines (75 loc) · 3.61 KB
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
import unittest
import json
import requests
# NOTE: Make sure you run 'pip install requests' in your virtualenv
# URL pointing to your local dev host
LOCAL_URL = 'http://localhost:5000'
BODY = {'text': 'Hello, World!', 'username': 'Megan'}
USER1 = {'username':'gkr9'}
EVENT1 = {'title':'fake!'}
class TestRoutes(unittest.TestCase):
def test_get_initial_groups(self):
res = requests.get(LOCAL_URL + '/api/groups/')
assert res.json()['success']
def test_create_group(self):
res = requests.post(LOCAL_URL + '/api/groups/', data=json.dumps(BODY))
group = res.json()['data']
assert res.json()['success']
assert group['text'] == 'Hello, World!'
assert group['username'] == 'Megan'
assert group['score'] == 0
def test_get__group(self):
res = requests.post(LOCAL_URL + '/api/groups/', data=json.dumps(BODY))
group = res.json()['data']
res = requests.get(LOCAL_URL + '/api/group/' + str(group['id']) + '/')
assert res.json()['data'] == group
def test_edit_group(self):
res = requests.post(LOCAL_URL + '/api/groups/', data=json.dumps(BODY))
group_id = res.json()['data']['id']
res = requests.post(LOCAL_URL + '/api/group/' + str(group_id) + '/',
data=json.dumps({'text': 'New text'}))
assert res.json()['success']
res = requests.get(LOCAL_URL + '/api/group/' + str(group_id) + '/')
assert res.json()['data']['text'] == 'New text'
def test_delete_group(self):
res = requests.post(LOCAL_URL + '/api/groups/', data=json.dumps(BODY))
group_id = res.json()['data']['id']
res = requests.delete(LOCAL_URL + '/api/group/' + str(group_id) + '/')
assert res.json()['success']
def test_group_comment(self):
res = requests.post(LOCAL_URL + '/api/groups/', data=json.dumps(BODY))
group_id = res.json()['data']['id']
comment = {'text': 'First comment', 'username': 'Megan'}
res = requests.post(LOCAL_URL + '/api/group/' + str(group_id) + '/comment/',
data=json.dumps(comment))
assert res.json()['success']
res = requests.get(LOCAL_URL + '/api/group/' + str(group_id) + '/comments/')
assert res.json()['success']
comments = res.json()['data']
assert len(comments) == 1
assert comments[0]['text'] == 'First comment'
assert comments[0]['username'] == 'Megan'
def test_get_invalid_group(self):
res = requests.get(LOCAL_URL + '/api/group/1000/')
assert not res.json()['success']
def test_edit_invalid_group(self):
res = requests.post(LOCAL_URL + '/api/group/1000/',
data=json.dumps({'text': 'New text'}))
assert not res.json()['success']
def test_delete_invalid_group(self):
res = requests.delete(LOCAL_URL + '/api/group/1000/')
assert not res.json()['success']
def test_get_comments_invalid_group(self):
res = requests.get(LOCAL_URL + '/api/group/1000/comments/')
assert not res.json()['success']
def test_group_invalid_comment(self):
res = requests.post(LOCAL_URL + '/api/group/1000/comment/', data=json.dumps(BODY))
assert not res.json()['success']
def test_group_id_increments(self):
res = requests.post(LOCAL_URL + '/api/groups/', data=json.dumps(BODY))
group_id = res.json()['data']['id']
res2 = requests.post(LOCAL_URL + '/api/groups/', data=json.dumps(BODY))
group_id2 = res2.json()['data']['id']
assert group_id + 1 == group_id2
if __name__ == '__main__':
unittest.main()