diff --git a/test/exploration_tests/partial_response_test.py b/test/exploration_tests/partial_response_test.py index 1e70416..dd4b547 100644 --- a/test/exploration_tests/partial_response_test.py +++ b/test/exploration_tests/partial_response_test.py @@ -1,13 +1,12 @@ import logging from functools import partial -from itertools import chain +from itertools import chain, repeat from operator import methodcaller from typing import Iterable import pytest import requests -from funcy import rcompose, compose, rpartial, identity, lmap -from more_itertools import peekable +from funcy import rcompose, compose, rpartial, identity, lmap, ilen from pyinfra.rest import pack, unpack, bundle from pyinfra.utils.func import lift, starlift, parallel_map, star @@ -16,26 +15,16 @@ logger = logging.getLogger("PIL.PngImagePlugin") logger.setLevel(logging.INFO) +def dispatch_methods(input_data): + return *repeat(requests.patch, ilen(input_data) - 1), requests.post + + def post_partial(url, input_data: Iterable[bytes], metadata): def send(method, data): return method(url, json=data) - def dispatch_method(input_data): - def is_last_item(): - try: - input_data.peek() - return False - except StopIteration: - return True - - input_data = peekable(input_data) - - for _ in input_data: - method = requests.post if is_last_item() else requests.patch - yield method - pack_data_and_metadata_for_rest_transfer = lift(rpartial(pack, metadata)) - dispatch_http_method_left_and_forward_data_right = parallel_map(dispatch_method, lift(identity)) + dispatch_http_method_left_and_forward_data_right = parallel_map(dispatch_methods, lift(identity)) send_data_with_method_to_analyzer = starlift(send) extract_payload_from_responses = lift(methodcaller("json")) flatten_buffered_payloads = chain.from_iterable