def test_process_hash_prefix_with_response_json_no_row_count(): endpoint = 'https://abc.com/123' limit = 100 hash_prefix = '00' retries = 3 qp = {'q': 'abc'} response_json = {'abc': '123'} patch_get_response_json = patch.object(si.delayed_requester, 'get_response_json', return_value=response_json) patch_build_qp = patch.object(si, '_build_query_params', return_value=qp) patch_process_response = patch.object(si, '_process_response_json') with\ patch_get_response_json as mock_get_response_json,\ patch_build_qp as mock_build_qp,\ patch_process_response as mock_process_response: si._process_hash_prefix(hash_prefix, endpoint=endpoint, limit=limit, retries=retries) mock_process_response.assert_called_with(response_json) mock_build_qp.assert_called_once_with(0, hash_prefix=hash_prefix) mock_get_response_json.assert_called_once_with(endpoint, retries=retries, query_params=qp)
def test_process_hash_prefix_with_good_response_json(): endpoint = 'https://abc.com/123' limit = 100 hash_prefix = '00' retries = 3 qp = {'q': 'abc'} response_json = {'response': {'abc': '123', 'rowCount': 150}} patch_get_response_json = patch.object(si.delayed_requester, 'get_response_json', return_value=response_json) patch_build_qp = patch.object(si, '_build_query_params', return_value=qp) patch_process_response = patch.object(si, '_process_response_json', return_value=0) with\ patch_build_qp as mock_build_qp,\ patch_get_response_json as mock_get_response_json,\ patch_process_response as mock_process_response: si._process_hash_prefix(hash_prefix, endpoint=endpoint, limit=limit, retries=retries) expect_process_response_calls = [call(response_json), call(response_json)] expect_build_qp_calls = [ call(0, hash_prefix=hash_prefix), call(limit, hash_prefix=hash_prefix) ] expect_get_response_json_calls = [ call(endpoint, retries=retries, query_params=qp), call(endpoint, retries=retries, query_params=qp) ] mock_build_qp.assert_has_calls(expect_build_qp_calls) mock_get_response_json.assert_has_calls(expect_get_response_json_calls) mock_process_response.assert_has_calls(expect_process_response_calls)