Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/api/test_api_lookup.py
Show All 31 Lines | def test_generic_lookup_fn_1(criteria0, param0, param1): | ||||
assert criteria0 == 'something' | assert criteria0 == 'something' | ||||
return map(lambda x: x + 1, [1, 2, 3]) | return map(lambda x: x + 1, [1, 2, 3]) | ||||
actual_result = utils.api_lookup( | actual_result = utils.api_lookup( | ||||
test_generic_lookup_fn_1, 'something', 'some param 0', | test_generic_lookup_fn_1, 'something', 'some param 0', | ||||
'some param 1', | 'some param 1', | ||||
notfound_msg=('This is not the error message you are looking for. ' | notfound_msg=('This is not the error message you are looking for. ' | ||||
'Move along.'), | 'Move along.'), | ||||
enrich_fn=lambda x: x * 2) | enrich_fn=lambda x, request: x * 2) | ||||
assert actual_result == [4, 6, 8] | assert actual_result == [4, 6, 8] | ||||
def test_generic_api_list_are_enriched_too(): | def test_generic_api_list_are_enriched_too(): | ||||
def test_generic_lookup_fn_2(crit): | def test_generic_lookup_fn_2(crit): | ||||
assert crit == 'something' | assert crit == 'something' | ||||
return ['a', 'b', 'c'] | return ['a', 'b', 'c'] | ||||
actual_result = utils.api_lookup( | actual_result = utils.api_lookup( | ||||
test_generic_lookup_fn_2, 'something', | test_generic_lookup_fn_2, 'something', | ||||
notfound_msg=('Not the error message you are looking for, it is. ' | notfound_msg=('Not the error message you are looking for, it is. ' | ||||
'Along, you move!'), | 'Along, you move!'), | ||||
enrich_fn=lambda x: ''. join(['=', x, '='])) | enrich_fn=lambda x, request: ''. join(['=', x, '='])) | ||||
assert actual_result == ['=a=', '=b=', '=c='] | assert actual_result == ['=a=', '=b=', '=c='] | ||||
def test_generic_api_generator_are_enriched_and_returned_as_list(): | def test_generic_api_generator_are_enriched_and_returned_as_list(): | ||||
def test_generic_lookup_fn_3(crit): | def test_generic_lookup_fn_3(crit): | ||||
assert crit == 'crit' | assert crit == 'crit' | ||||
return (i for i in [4, 5, 6]) | return (i for i in [4, 5, 6]) | ||||
actual_result = utils.api_lookup( | actual_result = utils.api_lookup( | ||||
test_generic_lookup_fn_3, 'crit', | test_generic_lookup_fn_3, 'crit', | ||||
notfound_msg='Move!', | notfound_msg='Move!', | ||||
enrich_fn=lambda x: x - 1) | enrich_fn=lambda x, request: x - 1) | ||||
assert actual_result == [3, 4, 5] | assert actual_result == [3, 4, 5] | ||||
def test_generic_api_simple_data_are_enriched_and_returned_too(): | def test_generic_api_simple_data_are_enriched_and_returned_too(): | ||||
def test_generic_lookup_fn_4(crit): | def test_generic_lookup_fn_4(crit): | ||||
assert crit == '123' | assert crit == '123' | ||||
return {'a': 10} | return {'a': 10} | ||||
def test_enrich_data(x): | def test_enrich_data(x, request): | ||||
x['a'] = x['a'] * 10 | x['a'] = x['a'] * 10 | ||||
return x | return x | ||||
actual_result = utils.api_lookup( | actual_result = utils.api_lookup( | ||||
test_generic_lookup_fn_4, '123', | test_generic_lookup_fn_4, '123', | ||||
notfound_msg='Nothing to do', | notfound_msg='Nothing to do', | ||||
enrich_fn=test_enrich_data) | enrich_fn=test_enrich_data) | ||||
Show All 27 Lines |