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
|
import pytest
from common import * # pylint: disable=W0614
@pytest.mark.parametrize(('req_method', 'url', 'req_params'), [
(getattr(requests, 'get'), URI_GET_STRING, {"auth": INVALID_AUTH_STRING}),
(getattr(requests, 'put'), URI_PUT_STRING, {"auth": INVALID_AUTH_STRING,
"json": MOI_DATA_TMPL}),
(getattr(requests, 'patch'), URI_PATCH_STRING, {"auth": INVALID_AUTH_STRING,
"json": MOI_DATA_PATCH}),
(getattr(requests, 'delete'), URI_DELETE_STRING, {"auth": INVALID_AUTH_STRING})
])
def test_unauthorized(req_method, url, req_params):
'''Check service denies access if
invalid credentials provided'''
req = req_method(url, **req_params)
assert req.status_code == requests.codes.unauthorized
assert UNAUTHORIZED_MSG in req.text
def test_bad_moi_class():
'''Check service returns proper
http code and error msg if MOI class
is invalid'''
req = requests.get('{0}'.format(BAD_CLASS_URI_BASE_STRING),
auth=AUTH_STRING)
assert req.status_code == requests.codes.not_acceptable
assert INVALID_CLASS_MSG in req.text
req = requests.put('{0}'.format(BAD_CLASS_URI_BASE_STRING),
auth=AUTH_STRING, json=MOI_DATA_TMPL)
assert req.status_code == requests.codes.not_acceptable
assert INVALID_CLASS_MSG in req.text
req = requests.patch('{0}'.format(BAD_CLASS_URI_BASE_STRING),
auth=AUTH_STRING, json=MOI_DATA_PATCH)
assert req.status_code == requests.codes.not_acceptable
assert INVALID_CLASS_MSG in req.text
req = requests.delete('{0}'.format(BAD_CLASS_URI_BASE_STRING),
auth=AUTH_STRING)
assert req.status_code == requests.codes.not_acceptable
assert INVALID_CLASS_MSG in req.text
def test_bad_prefix():
'''Check service returns proper
http code and error msg if URI prefix
is invalid'''
for url in BAD_PREFIX_URI_BASE_STRING, BAD_PREFIX1_URI_BASE_STRING:
req = requests.get('{0}'.format(url),
auth=AUTH_STRING)
assert req.status_code == requests.codes.not_found
assert INVALID_PREFIX_MSG in req.text
req = requests.put('{0}'.format(url),
auth=AUTH_STRING, json=MOI_DATA_TMPL)
assert req.status_code == requests.codes.not_found
assert INVALID_PREFIX_MSG in req.text
req = requests.patch('{0}'.format(url),
auth=AUTH_STRING, json=MOI_DATA_PATCH)
assert req.status_code == requests.codes.not_found
assert INVALID_PREFIX_MSG in req.text
req = requests.delete('{0}'.format(url),
auth=AUTH_STRING)
assert req.status_code == requests.codes.not_found
assert INVALID_PREFIX_MSG in req.text
|