def test_fill_function_call(): """Test filling the function call. """ def test_function(activity, arg_one, key, kwarg_one=None, kwarg_two=None): pass requirements = dict( arg_one=param.Param('context.arg'), kwarg_one=param.Param('context.kwarg')) activity = None context = { 'context.arg': 'arg.value', 'context.kwarg': 'kwarg.value'} data = task.fill_function_call( test_function, requirements, activity, context) assert not data.get('activity') assert not data.get('context') assert not data.get('key') assert not data.get('kwarg_two') assert data.get('arg_one') == 'arg.value' assert data.get('kwarg_one') == 'kwarg.value' test_function(**data)
def test_default_param(): """Test the behavior of the default param class. """ key = 'context.key' message = 'Hello World' current_param = param.Param(key) requirements = list(current_param.requirements) assert current_param.get_data({key: message}) is message assert requirements[0] is key
def test_parametrize(): """Test parametrize. Parametrize only allows objects that inherits BaseParam or string. """ keys = ['context.key1', 'context.key2', 'context.key3'] manual_keys = ['context.manual_key1', 'context.manual_key2'] params = [param.Param(key) for key in keys] params += manual_keys params += [param.StaticParam('Value')] params = [param.parametrize(current_param) for current_param in params] for current_param in params: assert isinstance(current_param, param.BaseParam) with pytest.raises(param.UnknownParamException): param.parametrize(list('Unknown'))
def test_all_requirements(): """Test getting all the requirements. """ keys = ['context.key1', 'context.key2', 'context.key3'] manual_keys = ['context.manual_key1', 'context.manual_key2'] params = [param.Param(key) for key in keys] params += manual_keys params += [param.StaticParam('Value')] params = [param.parametrize(current_param) for current_param in params] resp = param.get_all_requirements(params) for key in keys: assert key in resp for manual_key in manual_keys: assert manual_key in resp assert 'Value' not in resp