Skip to content

Commit 738f356

Browse files
author
Michael Brewer
committed
refactor: build to asdict to be consistent
1 parent 6f1aa92 commit 738f356

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

aws_lambda_powertools/utilities/data_classes/api_gateway_authorizer_event.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def deny_method_with_conditions(self, verb: str, resource: str, conditions: List
467467
conditions here: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html#Condition"""
468468
self._add_method("Deny", verb, resource, conditions)
469469

470-
def build(self) -> Dict[str, Any]:
470+
def asdict(self) -> Dict[str, Any]:
471471
"""Generates the policy document based on the internal lists of allowed and denied
472472
conditions. This will generate a policy with two main statements for the effect:
473473
one statement for Allow and one statement for Deny.

tests/functional/data_classes/test_api_gateway_authorizer.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_authorizer_response_no_statement(builder: APIGatewayAuthorizerResponse)
1515
# GIVEN a builder with no statements
1616
with pytest.raises(NameError) as ex:
1717
# WHEN calling build
18-
builder.build()
18+
builder.asdict()
1919

2020
# THEN raise a name error for not statements
2121
assert str(ex.value) == "No statements defined for the policy"
@@ -44,7 +44,7 @@ def test_authorizer_response_invalid_resource(builder: APIGatewayAuthorizerRespo
4444
def test_authorizer_response_allow_all_methods_with_context():
4545
builder = APIGatewayAuthorizerResponse("foo", "us-west-1", "123456789", "fantom", "dev", {"name": "Foo"})
4646
builder.allow_all_methods()
47-
assert builder.build() == {
47+
assert builder.asdict() == {
4848
"principalId": "foo",
4949
"policyDocument": {
5050
"Version": "2012-10-17",
@@ -62,7 +62,7 @@ def test_authorizer_response_allow_all_methods_with_context():
6262

6363
def test_authorizer_response_deny_all_methods(builder: APIGatewayAuthorizerResponse):
6464
builder.deny_all_methods()
65-
assert builder.build() == {
65+
assert builder.asdict() == {
6666
"principalId": "foo",
6767
"policyDocument": {
6868
"Version": "2012-10-17",
@@ -79,7 +79,7 @@ def test_authorizer_response_deny_all_methods(builder: APIGatewayAuthorizerRespo
7979

8080
def test_authorizer_response_allow_method(builder: APIGatewayAuthorizerResponse):
8181
builder.allow_method(HttpVerb.GET, "/foo")
82-
assert builder.build() == {
82+
assert builder.asdict() == {
8383
"policyDocument": {
8484
"Version": "2012-10-17",
8585
"Statement": [
@@ -96,7 +96,7 @@ def test_authorizer_response_allow_method(builder: APIGatewayAuthorizerResponse)
9696

9797
def test_authorizer_response_deny_method(builder: APIGatewayAuthorizerResponse):
9898
builder.deny_method(HttpVerb.PUT, "foo")
99-
assert builder.build() == {
99+
assert builder.asdict() == {
100100
"principalId": "foo",
101101
"policyDocument": {
102102
"Version": "2012-10-17",
@@ -119,7 +119,7 @@ def test_authorizer_response_allow_method_with_conditions(builder: APIGatewayAut
119119
{"StringEquals": {"method.request.header.Content-Type": "text/html"}},
120120
],
121121
)
122-
assert builder.build() == {
122+
assert builder.asdict() == {
123123
"principalId": "foo",
124124
"policyDocument": {
125125
"Version": "2012-10-17",
@@ -143,7 +143,7 @@ def test_authorizer_response_deny_method_with_conditions(builder: APIGatewayAuth
143143
{"StringEquals": {"method.request.header.Content-Type": "application/json"}},
144144
],
145145
)
146-
assert builder.build() == {
146+
assert builder.asdict() == {
147147
"principalId": "foo",
148148
"policyDocument": {
149149
"Version": "2012-10-17",

0 commit comments

Comments
 (0)