1111
1212@pytest .fixture
1313def run_fluent_api_notecard_api_mapping_test ():
14- def _run_test (fluent_api , notecard_api_name , req_params , rename_map = None ):
14+ def _run_test (fluent_api , notecard_api_name , req_params , rename_key_map = None , rename_value_map = None ):
1515 card = notecard .Notecard ()
1616 card .Transaction = MagicMock ()
1717
@@ -21,21 +21,31 @@ def _run_test(fluent_api, notecard_api_name, req_params, rename_map=None):
2121 # There are certain fluent APIs that have keyword arguments that don't
2222 # map exactly onto the Notecard API. For example, note.changes takes a
2323 # 'maximum' parameter, but in the JSON request that gets sent to the
24- # Notecard, it's sent as 'max'. The rename_map allows a test to specify
24+ # Notecard, it's sent as 'max'. The rename_key_map allows a test to specify
2525 # how a fluent API's keyword args map to Notecard API args, in cases
2626 # where they differ.
27- if rename_map is not None :
28- for old_key , new_key in rename_map .items ():
27+ if rename_key_map is not None :
28+ for old_key , new_key in rename_key_map .items ():
2929 expected_notecard_api_req [new_key ] = expected_notecard_api_req .pop (old_key )
3030
31+ # Additionally, some Notecard API args have values that are not directly
32+ # mapped, but are instead derived from the value of another arg. For
33+ # example, note.template takes a 'compact' parameter, but the value of
34+ # that parameter is actually derived from the value of the 'format'
35+ # parameter. The rename_value_map allows a test to specify how a fluent
36+ # API's keyword args map to Notecard API args, in cases where the value
37+ if rename_value_map is not None :
38+ for old_key , new_value in rename_value_map .items ():
39+ expected_notecard_api_req [old_key ] = new_value
40+
3141 card .Transaction .assert_called_once_with (expected_notecard_api_req )
3242
3343 return _run_test
3444
3545
3646@pytest .fixture
3747def run_fluent_api_invalid_notecard_test ():
38- def _run_test (fluent_api , req_params ):
48+ def _run_test (fluent_api , req_params , rename_key_map = None , rename_value_map = None ):
3949 with pytest .raises (Exception , match = 'Notecard object required' ):
4050 # Call with None instead of a valid Notecard object.
4151 fluent_api (None , ** req_params )
0 commit comments