removed debug prints
This commit is contained in:
parent
16fa992cae
commit
c00973b676
@ -1,14 +1,14 @@
|
||||
from functools import partial
|
||||
from itertools import takewhile, starmap, repeat, chain
|
||||
from itertools import starmap, repeat
|
||||
from itertools import takewhile
|
||||
from operator import itemgetter, methodcaller
|
||||
from typing import Iterable, Tuple
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
from funcy import compose, rpartial, repeatedly, flatten, rcompose, take, curry, first, lmap
|
||||
from funcy import repeatedly, flatten, rcompose, lmap
|
||||
|
||||
from pyinfra.rest import pack, inspect, unpack
|
||||
from pyinfra.rest import pack, unpack
|
||||
from pyinfra.utils.func import lift
|
||||
|
||||
|
||||
@ -22,7 +22,6 @@ def pack_data_and_metadata_for_rest_transfer(data: Iterable, metadata: Iterable)
|
||||
|
||||
def send_data_to_analyzer(url, payloads: Iterable[Tuple]):
|
||||
def post(package):
|
||||
print("sending", package)
|
||||
response = requests.post(f"{url}/submit", json=package)
|
||||
response.raise_for_status()
|
||||
return response
|
||||
@ -38,31 +37,17 @@ def submit_and_pickup(url, data, metadata):
|
||||
def stream_response_payloads(endpoint):
|
||||
def receive():
|
||||
response = requests.get(f"{url}/{endpoint}")
|
||||
print("text", response.status_code)
|
||||
return response
|
||||
|
||||
def more_is_coming(response):
|
||||
return response.status_code == 206
|
||||
|
||||
def load_payload(response):
|
||||
print("received payload", response.json())
|
||||
return response.json()
|
||||
|
||||
response_stream = takewhile(more_is_coming, repeatedly(receive))
|
||||
payloads = map(load_payload, response_stream)
|
||||
for item in payloads:
|
||||
print("item", item)
|
||||
yield item
|
||||
|
||||
# input_data_to_payload_stream = compose(
|
||||
# stream_response_payloads,
|
||||
# itemgetter("pickup_endpoint"),
|
||||
# methodcaller("json"),
|
||||
# post,
|
||||
# rpartial(pack, metadata),
|
||||
# )
|
||||
|
||||
print()
|
||||
yield from payloads
|
||||
|
||||
input_data_to_payload_stream = rcompose(
|
||||
pack_data_and_metadata_for_rest_transfer,
|
||||
@ -77,9 +62,7 @@ def submit_and_pickup(url, data, metadata):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("batched", [True, False])
|
||||
@pytest.mark.parametrize("item_type", ["string"])
|
||||
@pytest.mark.parametrize("item_type", ["string", "image", "pdf"])
|
||||
def test_pickup_endpoint(url, input_data_items, metadata, operation, target_data_items, server_process):
|
||||
output = lmap(unpack, submit_and_pickup(url, input_data_items, metadata))
|
||||
print("exp", lmap(unpack, target_data_items))
|
||||
print("out", output)
|
||||
assert output == lmap(unpack, target_data_items)
|
||||
|
||||
@ -3,7 +3,6 @@ import traceback
|
||||
from itertools import chain
|
||||
|
||||
from flask import Flask, jsonify, request
|
||||
from funcy import flatten
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
@ -41,17 +40,16 @@ def set_up_processing_server(process_fn):
|
||||
def pickup():
|
||||
|
||||
try:
|
||||
response_payload = next(response_payload_iter)
|
||||
print("response_payload", response_payload)
|
||||
resp = jsonify(response_payload)
|
||||
resp = jsonify(next(response_payload_iter))
|
||||
resp.status_code = 206
|
||||
|
||||
except StopIteration:
|
||||
resp = jsonify("No more items left")
|
||||
resp.status_code = 204
|
||||
|
||||
except Exception as err:
|
||||
except:
|
||||
logger.error(traceback.format_exc())
|
||||
raise
|
||||
|
||||
return resp
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user