aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/prov-mns-provider/src/tests/test_rest_api_endpoints.py
blob: 155ed9dd5ecffa44536b75ff0650782e323a6473 (plain)
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
import pytest
from common import * # pylint: disable=W0614

def test_put():
    '''Validate PUT request'''

    MOI_DATA = MOI_DATA_TMPL
    MOI_DATA['data']['id'] = MOI_ID
    MOI_DATA['data']['href'] = '/' + MOI_CLASS + '/' + MOI_ID
    req_put = requests.put('{0}'.format(URI_PUT_STRING), auth=AUTH_STRING,
                          json=MOI_DATA)

    if req_put.status_code != requests.codes.created:
        logger.error('PUT request to {0} failed'.format(URI_PUT_STRING))
        logger.debug('MOI data payload: {0}'.format(dumps(MOI_DATA,indent=2)))
        logger.debug('Response content: {0}'.format(req_put.text))

    assert req_put.status_code == requests.codes.created

@pytest.mark.parametrize(('url', 'req_method', 'req_params'),[
    (URI_GET_STRING, getattr(requests, 'get'), { "auth": AUTH_STRING }),
    (URI_PATCH_STRING, getattr(requests, 'patch'), { "auth": AUTH_STRING,
                                                     "json": MOI_DATA_PATCH}),
    (URI_DELETE_STRING, getattr(requests, 'delete'), { "auth": AUTH_STRING })
    ])
def test_api_methods(url, req_method, req_params):
    '''Valide request'''
    req = req_method(url, **req_params)

    if req.status_code != requests.codes.ok:
        logger.error('{0} request to {1} failed'.format(
                      req_method.__name__.upper(), url))
        logger.debug('Response content: {0}'.format(req.text))

    assert req.status_code == requests.codes.ok