-
Notifications
You must be signed in to change notification settings - Fork 421
/
Copy pathtest_paths_ending_with_slash.py
103 lines (79 loc) · 3.21 KB
/
test_paths_ending_with_slash.py
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
91
92
93
94
95
96
97
98
99
100
101
102
103
import pytest
from requests import HTTPError, Request
from tests.e2e.utils import data_fetcher
@pytest.fixture
def alb_basic_listener_endpoint(infrastructure: dict) -> str:
dns_name = infrastructure.get("ALBDnsName")
port = infrastructure.get("ALBBasicListenerPort", "")
return f"http://{dns_name}:{port}"
@pytest.fixture
def alb_multi_value_header_listener_endpoint(infrastructure: dict) -> str:
dns_name = infrastructure.get("ALBDnsName")
port = infrastructure.get("ALBMultiValueHeaderListenerPort", "")
return f"http://{dns_name}:{port}"
@pytest.fixture
def apigw_rest_endpoint(infrastructure: dict) -> str:
return infrastructure.get("APIGatewayRestUrl", "")
@pytest.fixture
def apigw_http_endpoint(infrastructure: dict) -> str:
return infrastructure.get("APIGatewayHTTPUrl", "")
@pytest.fixture
def lambda_function_url_endpoint(infrastructure: dict) -> str:
return infrastructure.get("LambdaFunctionUrl", "")
@pytest.mark.xdist_group(name="event_handler")
def test_api_gateway_rest_trailing_slash(apigw_rest_endpoint):
# GIVEN API URL ends in a trailing slash
url = f"{apigw_rest_endpoint}todos/"
body = "Hello World"
# WHEN
response = data_fetcher.get_http_response(
Request(
method="POST",
url=url,
json={"body": body},
)
)
# THEN expect a HTTP 200 response
assert response.status_code == 200
@pytest.mark.xdist_group(name="event_handler")
def test_api_gateway_http_trailing_slash(apigw_http_endpoint):
# GIVEN the URL for the API ends in a trailing slash API gateway should return a 404
url = f"{apigw_http_endpoint}todos/"
body = "Hello World"
# WHEN calling an invalid URL (with trailing slash) expect HTTPError exception from data_fetcher
with pytest.raises(HTTPError):
data_fetcher.get_http_response(
Request(
method="POST",
url=url,
json={"body": body},
)
)
@pytest.mark.xdist_group(name="event_handler")
def test_lambda_function_url_trailing_slash(lambda_function_url_endpoint):
# GIVEN the URL for the API ends in a trailing slash it should behave as if there was not one
url = f"{lambda_function_url_endpoint}todos/" # the function url endpoint already has the trailing /
body = "Hello World"
# WHEN calling an invalid URL (with trailing slash) expect HTTPError exception from data_fetcher
with pytest.raises(HTTPError):
data_fetcher.get_http_response(
Request(
method="POST",
url=url,
json={"body": body},
)
)
@pytest.mark.xdist_group(name="event_handler")
def test_alb_url_trailing_slash(alb_multi_value_header_listener_endpoint):
# GIVEN url has a trailing slash - it should behave as if there was not one
url = f"{alb_multi_value_header_listener_endpoint}/todos/"
body = "Hello World"
# WHEN calling an invalid URL (with trailing slash) expect HTTPError exception from data_fetcher
with pytest.raises(HTTPError):
data_fetcher.get_http_response(
Request(
method="POST",
url=url,
json={"body": body},
)
)