File size: 2,403 Bytes
d8ad0fd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | import json
import pytest
from tests.e2e.utils import data_fetcher
@pytest.fixture
def handler_with_basic_model_arn(infrastructure: dict) -> str:
return infrastructure.get("HandlerWithBasicModelArn", "")
@pytest.fixture
def handler_with_union_tag_arn(infrastructure: dict) -> str:
return infrastructure.get("HandlerWithUnionTagArn", "")
@pytest.fixture
def handler_with_dataclass_arn(infrastructure: dict) -> str:
return infrastructure.get("HandlerWithDataclass", "")
@pytest.fixture
def handler_with_type_model_class(infrastructure: dict) -> str:
return infrastructure.get("HandlerWithModelTypeClass", "")
@pytest.mark.xdist_group(name="parser")
def test_parser_with_basic_model(handler_with_basic_model_arn):
# GIVEN
payload = json.dumps({"product": "powertools", "version": "v3"})
# WHEN
parser_execution, _ = data_fetcher.get_lambda_response(
lambda_arn=handler_with_basic_model_arn,
payload=payload,
)
ret = parser_execution["Payload"].read().decode("utf-8")
assert "powertools" in ret
@pytest.mark.xdist_group(name="parser")
def test_parser_with_union_tag(handler_with_union_tag_arn):
# GIVEN
payload = json.dumps({"status": "partial", "error_msg": "partial failure"})
# WHEN
parser_execution, _ = data_fetcher.get_lambda_response(
lambda_arn=handler_with_union_tag_arn,
payload=payload,
)
ret = parser_execution["Payload"].read().decode("utf-8")
assert "partial failure" in ret
@pytest.mark.xdist_group(name="parser")
def test_parser_with_dataclass(handler_with_dataclass_arn):
# GIVEN
payload = json.dumps({"product": "powertools", "version": "v3"})
# WHEN
parser_execution, _ = data_fetcher.get_lambda_response(
lambda_arn=handler_with_dataclass_arn,
payload=payload,
)
ret = parser_execution["Payload"].read().decode("utf-8")
assert "powertools" in ret
@pytest.mark.xdist_group(name="parser")
def test_parser_with_type_model(handler_with_type_model_class):
# GIVEN
payload = json.dumps({"name": "powertools", "profile": {"description": "python", "size": "XXL"}})
# WHEN
parser_execution, _ = data_fetcher.get_lambda_response(
lambda_arn=handler_with_type_model_class,
payload=payload,
)
ret = parser_execution["Payload"].read().decode("utf-8")
assert "powertools" in ret
|