Example #1
0
 def test_substitute_variables(self):
     content = {
         'request': {
             'url': '/api/users/$uid',
             'headers': {'token': '$token'}
         }
     }
     variables_mapping = {"$uid": 1000}
     substituted_data = parser.substitute_variables(content, variables_mapping)
     self.assertEqual(substituted_data["request"]["url"], "/api/users/1000")
     self.assertEqual(substituted_data["request"]["headers"], {'token': '$token'})
Example #2
0
 def test_substitute_variables(self):
     content = {
         'request': {
             'url': '/api/users/$uid',
             'headers': {
                 'token': '$token'
             }
         }
     }
     variables_mapping = {'$uid': 1000}
     subsitituted_data = parser.substitute_variables(
         content, variables_mapping)
     assert subsitituted_data['request']['url'] == '/api/users/1000'
     assert subsitituted_data['request']['headers']['token'] == '$token'
Example #3
0
def _get_block_by_name(ref_call, ref_type, project_mapping):
    """ get test content by reference name.

    Args:
        ref_call (str): call function.
            e.g. api_v1_Account_Login_POST($UserName, $Password)
        ref_type (enum): "def-api" or "def-testcase"
        project_mapping (dict): project_mapping

    Returns:
        dict: api/testcase definition.

    Raises:
        exceptions.ParamsError: call args number is not equal to defined args number.

    """
    function_meta = parser.parse_function(ref_call)
    func_name = function_meta["func_name"]
    call_args = function_meta["args"]
    block = _get_test_definition(func_name, ref_type, project_mapping)
    def_args = block.get("function_meta", {}).get("args", [])

    if len(call_args) != len(def_args):
        err_msg = "{}: call args number is not equal to defined args number!\n".format(
            func_name)
        err_msg += "defined args: {}\n".format(def_args)
        err_msg += "reference args: {}".format(call_args)
        logger.log_error(err_msg)
        raise exceptions.ParamsError(err_msg)

    args_mapping = {}
    for index, item in enumerate(def_args):
        if call_args[index] == item:
            continue

        args_mapping[item] = call_args[index]

    if args_mapping:
        block = parser.substitute_variables(block, args_mapping)

    return block
Example #4
0
def _get_block_by_name(ref_call, ref_type):
    '''
    get test content by reference name.
    Args:
        ref_call (str): call function.
            e.g. api_v1_Account_Login_POST($UserName,$Password)
        ref_type (enum): "def-api" or "def-testcase"
    Returns:
        dict: api/testcase definition
    Raises:
        exceptions.ParamsError: call args number is not equal to defined args number
    '''

    function_meta = parser.parse_function(ref_call)
    func_name = function_meta['func_name']
    call_args = function_meta['args']
    block = _get_test_definition(func_name, ref_type)
    def_args = block.get('function_meta', {}).get('args', [])

    if len(call_args) != len(def_args):
        err_msg = f'{func_name}: call args number is not equal to defined args number!\n'
        err_msg += f'defined args: {def_args}\n'
        err_msg += f'refererce args: {call_args}'
        logger.log_error(err_msg)
        raise exceptions.ParamError(err_msg)

    args_mapping = {}
    for index, item in enumerate(def_args):
        if call_args[index] == item:
            continue
        args_mapping[item] = call_args[index]

    if args_mapping:
        block = parser.substitute_variables(block, args_mapping)

    return block