55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
import json
|
|
|
|
import pytest
|
|
|
|
from pyinfra.visitor.strategies.response.aggregation import AggregationStorageStrategy
|
|
|
|
|
|
@pytest.mark.parametrize("client_name", ["mock"], scope="session")
|
|
class TestAggregationStorageStrategy:
|
|
def test_aggregation_strategy_with_no_empty_data_field_causes_two_uploads(self, storage):
|
|
strat = AggregationStorageStrategy(storage=storage)
|
|
|
|
analysis_response = {
|
|
"analysis_payloads": [
|
|
{"data": [1], "metadata": {"id": 1}},
|
|
{"data": [3], "metadata": {"id": 3}},
|
|
],
|
|
"dossierId": "dossier0",
|
|
"fileId": "file0",
|
|
"pages": [0, 2],
|
|
}
|
|
response_message_bodies = [*strat(analysis_response)]
|
|
assert response_message_bodies == [
|
|
{
|
|
"dossierId": "dossier0",
|
|
"fileId": "file0",
|
|
"pages": [0, 2],
|
|
"id": 3,
|
|
"response_files": ["dossier0/file0/id:1.json.gz", "dossier0/file0/id:3.json.gz"],
|
|
}
|
|
]
|
|
|
|
def test_aggregation_strategy_with_empty_data_field_causes_single_uploads(self, storage):
|
|
strat = AggregationStorageStrategy(storage=storage)
|
|
|
|
analysis_response = {
|
|
"analysis_payloads": [
|
|
{"data": None, "metadata": {"id": 1}},
|
|
{"data": [3], "metadata": {"id": 3}},
|
|
],
|
|
"dossierId": "dossier0",
|
|
"fileId": "file0",
|
|
"pages": [0, 2],
|
|
}
|
|
response_message_bodies = [*strat(analysis_response)]
|
|
assert response_message_bodies == [
|
|
{
|
|
"dossierId": "dossier0",
|
|
"fileId": "file0",
|
|
"pages": [0, 2],
|
|
"id": 3,
|
|
"response_files": ["dossier0/file0/id:3.json.gz"],
|
|
}
|
|
]
|