-
Notifications
You must be signed in to change notification settings - Fork 0
/
iaecal_tests.py
66 lines (50 loc) · 1.87 KB
/
iaecal_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
#!/usr/bin/env python2
import json
import unittest
from iaecal import create_app, db
class IAECalTestCase(unittest.TestCase):
def setUp(self):
self.app = create_app('config.TestingConfig')
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
self.client = self.app.test_client()
def tearDown(self):
db.session.remove()
db.drop_all()
self.app_context.pop()
def test_index(self):
rv = self.client.get('/')
assert rv.status_code == 200
def test_get_url(self):
url = '/get-url'
# Test invalid method (only POST is allowed for this view)
rv = self.client.get(url)
assert rv.status_code == 405
# Test invalid data content_type
data = {'username': 'foo', 'password': 'bar'}
rv = self.client.post(url, data=data)
assert rv.status_code == 400
# Test invalid data
data = {'username': 'foo', 'password1': 'bar'}
rv = self.client.post(url, data=data,
content_type='application/json')
assert rv.status_code == 400
# Test invalid credentials
data = {'username': 'foo', 'password': 'bar'}
rv = self.client.post(url, data=json.dumps(data),
content_type='application/json')
assert rv.status_code == 400
def test_events(self):
# Test missing parameters
rv = self.client.get('/events/')
assert rv.status_code == 404
rv = self.client.get('/events/?session_id=toto')
assert rv.status_code == 404
rv = self.client.get('/events/?key=toto')
assert rv.status_code == 404
# Test invalid parameters
rv = self.client.get('/events/?session_id=foo&key=bar')
assert rv.status_code == 404
if __name__ == '__main__':
unittest.main()