Add test to verify bad MOI handling by the service
[integration.git] / test / mocks / prov-mns-provider / src / tests / test_invalid_requests.py
1 from common import * # pylint: disable=W0614
2
3 def test_unauthorized():
4     '''Check service denies access if
5     invalid credentials provided'''
6
7     req = requests.get('{0}'.format(URI_GET_STRING), auth=INVALID_AUTH_STRING)
8     assert req.status_code == requests.codes.unauthorized
9     assert UNAUTHORIZED_MSG in req.text
10
11     req = requests.put('{0}'.format(URI_PUT_STRING), auth=INVALID_AUTH_STRING,
12                        json=MOI_DATA_TMPL)
13     assert req.status_code == requests.codes.unauthorized
14     assert UNAUTHORIZED_MSG in req.text
15
16     req = requests.patch('{0}'.format(URI_PATCH_STRING),
17                          auth=INVALID_AUTH_STRING, json=MOI_DATA_PATCH)
18     assert req.status_code == requests.codes.unauthorized
19     assert UNAUTHORIZED_MSG in req.text
20
21     req = requests.delete('{0}'.format(URI_DELETE_STRING),
22                           auth=INVALID_AUTH_STRING)
23     assert req.status_code == requests.codes.unauthorized
24     assert UNAUTHORIZED_MSG in req.text
25
26 def test_bad_moi_class():
27     '''Check service returns proper
28     http code and error msg if MOI class
29     is invalid'''
30
31     req = requests.get('{0}'.format(BAD_CLASS_URI_BASE_STRING),
32                        auth=AUTH_STRING)
33     assert req.status_code == requests.codes.not_acceptable
34     assert INVALID_CLASS_MSG in req.text
35
36     req = requests.put('{0}'.format(BAD_CLASS_URI_BASE_STRING),
37                        auth=AUTH_STRING, json=MOI_DATA_TMPL)
38     assert req.status_code == requests.codes.not_acceptable
39     assert INVALID_CLASS_MSG in req.text
40
41     req = requests.patch('{0}'.format(BAD_CLASS_URI_BASE_STRING),
42                          auth=AUTH_STRING, json=MOI_DATA_PATCH)
43     assert req.status_code == requests.codes.not_acceptable
44     assert INVALID_CLASS_MSG in req.text
45
46     req = requests.delete('{0}'.format(BAD_CLASS_URI_BASE_STRING),
47                           auth=AUTH_STRING)
48     assert req.status_code == requests.codes.not_acceptable
49     assert INVALID_CLASS_MSG in req.text