changed callback signature to expect a dict with a key 'data'
This commit is contained in:
parent
4c7c4b466e
commit
5ac5fbf50b
@ -94,13 +94,15 @@ def queue_manager(queue_manager_name):
|
|||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def callback():
|
def callback():
|
||||||
return lambda x: x * 2
|
def inner(request):
|
||||||
|
return request["data"].decode() * 2
|
||||||
|
return inner
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def analysis_callback(callback):
|
def analysis_callback(callback):
|
||||||
def inner(data: bytes):
|
def inner(request):
|
||||||
return callback(data.decode())
|
return callback(request)
|
||||||
|
|
||||||
return inner
|
return inner
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import gzip
|
import gzip
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
|
||||||
@ -49,6 +50,13 @@ class TestConsumer:
|
|||||||
def produce_items():
|
def produce_items():
|
||||||
return map(str, range(3))
|
return map(str, range(3))
|
||||||
|
|
||||||
|
def mock_visitor(callback):
|
||||||
|
def inner(data):
|
||||||
|
return callback({"data": data.encode()})
|
||||||
|
return inner
|
||||||
|
|
||||||
|
callback = mock_visitor(callback)
|
||||||
|
|
||||||
queue_manager.clear()
|
queue_manager.clear()
|
||||||
|
|
||||||
for item in produce_items():
|
for item in produce_items():
|
||||||
|
|||||||
@ -75,11 +75,11 @@ class QueueVisitor:
|
|||||||
logging.warning(f"Loading data from storage failed for {object_descriptor}.")
|
logging.warning(f"Loading data from storage failed for {object_descriptor}.")
|
||||||
raise DataLoadingFailure() from err
|
raise DataLoadingFailure() from err
|
||||||
|
|
||||||
def process_data(self, data):
|
def process_data(self, data, body):
|
||||||
return self.callback(data)
|
return self.callback({**body, "data": data})
|
||||||
|
|
||||||
def load_and_process(self, body):
|
def load_and_process(self, body):
|
||||||
data = self.process_data(self.load_data(body))
|
data = self.process_data(self.load_data(body), body)
|
||||||
result_body = {**body, "data": data}
|
result_body = {**body, "data": data}
|
||||||
return result_body
|
return result_body
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user