示例#1
0
    def test_add_query_param(self):
        #case 1: url already contains vmw-task=true query parameter
        url = '/package/mock-1/{mock}/mock?vmw-task=true'
        param = 'vmw-task=true'
        url_actual = utils.add_query_param(url,param)
        url_expected = '/package/mock-1/{mock}/mock?vmw-task=true'
        self.assertEqual(url_expected, url_actual)

        #case 2: url contains a query parameter, so append vmw-task=true using '&'
        url = '/package/mock-1/{mock}/mock?key=value'
        param = 'vmw-task=true'
        url_actual = utils.add_query_param(url,param)
        url_expected = '/package/mock-1/{mock}/mock?key=value&vmw-task=true'
        self.assertEqual(url_expected, url_actual)

        #case 3: query index not find
        url = '/package/mock-1/{mock}/mock'
        param = 'vmw-task=true'
        url_actual = utils.add_query_param(url,param)
        url_expected = '/package/mock-1/{mock}/mock?vmw-task=true'
        self.assertEqual(url_expected, url_actual)
示例#2
0
    def post_process_path(self, path_obj):
        # Temporary fixes necessary for generated spec files.
        # Hardcoding for now as it is not available from metadata.
        if path_obj['path'] == '/com/vmware/cis/session' and path_obj[
                'method'] == 'post':
            header_parameter = {
                'in':
                'header',
                'required':
                True,
                'type':
                'string',
                'name':
                'vmware-use-header-authn',
                'description':
                'Custom header to protect against CSRF attacks in browser based clients'
            }
            header_parameter['schema'] = {'type': 'string'}
            path_obj['parameters'] = [header_parameter]

        # Allow invoking $task operations from the api-explorer
        if path_obj['operationId'].endswith('$task'):
            path_obj['path'] = utils.add_query_param(path_obj['path'],
                                                     'vmw-task=true')