Core responses: Add missing registered() (#6597)

This commit is contained in:
Sha 2023-09-12 21:16:42 +08:00 committed by GitHub
parent 0b8581ae98
commit c37ddd9c5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -17,6 +17,13 @@ class CustomRegistry(responses.registries.FirstMatchRegistry):
def __init__(self) -> None:
self._registered: Dict[str, List[responses.BaseResponse]] = defaultdict(list)
@property
def registered(self) -> List[responses.BaseResponse]:
res = []
for resps in self._registered.values():
res += resps
return res
def add(self, response: responses.BaseResponse) -> responses.BaseResponse:
if response not in self._registered[response.method]:
self._registered[response.method].append(response)

View File

@ -15,7 +15,8 @@ def test_http_integration():
responses_mock.add(
responses_mock.GET, "http://httpbin.org/robots.txt", body="a fake response"
)
registered = responses_mock.registered()
assert isinstance(registered, list) and len(registered) > 1
region_name = "us-west-2"
client = boto3.client("apigateway", region_name=region_name)
response = client.create_rest_api(name="my_api", description="this is my api")