Newer
Older
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
"""Tests for WebService.py"""
from nose.tools import assert_equals
import sys
from webtest import TestApp
from geomagio.edge import EdgeFactory
from geomagio.WebService import WebService
app = TestApp(WebService(EdgeFactory()))
def test_bad_requests():
"""WebService_test.test_bad_requests()
"""
# Check bad request (values)
bad_values = [
'/',
'/?id=bad',
'/?id=BOU&starttime=2017-50-50',
'/?id=BOU&starttime=2016-06-06&endtime=2017-50-50',
'/?id=BOU&starttime=2016-06-06&endtime=2016-06-05',
'/?id=BOU&elements=H,E,D,Z,F',
'/?id=BOU&type=bad',
'/?id=BOU&format=bad'
]
for bad_val in bad_values:
try:
response = app.get(bad_val, expect_errors=True)
assert_equals(response.status_int, 400)
except Exception:
exception = sys.exc_info()[1]
message = exception.args[0]
print('FAIL: ' + message + '\nrequest = ' + bad_val)
# Check bad request (duplicates)
duplicate_values = [
'/?id=BOU&id=BOU',
'/?id=BOU&starttime=2016-06-06&starttime=2016-06-06',
'/?id=BOU&endtime=2017-50-50&endtime=2017-50-50',
'/?id=BOU&elements=H,E,Z&elements=H,E,Z',
'/?id=BOU&type=variation&type=variation',
'/?id=BOU&format=iaga2002&format=iaga2002'
]
for duplicate in duplicate_values:
try:
response = app.get(duplicate, expect_errors=True)
assert_equals(response.status_int, 400)
except Exception:
exception = sys.exc_info()[1]
message = exception.args[0]
print('FAIL: ' + message + '\nrequest = ' + duplicate)
def test_good_requests():
"""WebService_test.test_good_requests()
"""
# Check for upper and lower case
good_requests = [
'/?id=BOU',
'/?id=bou',
'/?id=bou&starttime=2016-06-06',
'/?id=bou&starttime=2016-06-06&endtime=2016-06-07',
'/?id=bou&elements=H,E,Z,F',
'/?id=bou&elements=h,e,z,f',
'/?id=BOU&type=variation',
'/?id=BOU&type=VARIATION',
'/?id=BOU&format=iaga2002',
'/?id=BOU&format=IAGA2002'
]
for request in good_requests:
try:
response = app.get(request)
assert_equals(response.status_int, 200)
except Exception:
exception = sys.exc_info()[1]
message = exception.args[0]
print('FAIL: ' + message + '\nrequest = ' + request)