Skip to content

Commit 0201ffa

Browse files
Make pycfmodel available for Python3.10 (#100)
* make pycfmodel available for Python3.10 * update version and changelog * update changelog * update changelog * update version * update cloudformation_actions.py Co-authored-by: Ramon <[email protected]> Co-authored-by: Jordi Soucheiron <[email protected]>
1 parent c24d2e9 commit 0201ffa

14 files changed

+68
-287
lines changed

.github/workflows/lint-and-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
python-version: ['3.7', '3.8', '3.9']
12+
python-version: ['3.7', '3.8', '3.9', '3.10']
1313

1414
name: Python ${{ matrix.python-version }}
1515

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ All notable changes to this project will be documented in this file.
33

44
## 0.20.0
55
### Additions
6-
- New `RDSDBSecurityGroup` and `RDSDBSecurityGroupIngress` resources
6+
- New `RDSDBSecurityGroup` and `RDSDBSecurityGroupIngress` resources [#103]
77
### Improvements
88
- IAM Role is able to return its `AssumeRolePolicyDocument` as a list of `OptionallyNamedPolicyDocument`. [#102](https://github.com/Skyscanner/pycfmodel/pull/102)
99
### Updates
10+
- Compatible with Python3.10 [#100](https://github.com/Skyscanner/pycfmodel/pull/100)
1011
- Update `CLOUDFORMATION_ACTIONS`.
1112

1213
## 0.19.1

tests/resources/properties/test_policy_document.py

+8-15
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,13 @@ def policy_document_not_principal():
7373
**{
7474
"Statement": [
7575
{
76-
"Action": [
77-
"iam:Delete*",
78-
"s3:GetObject*",
79-
],
76+
"Action": ["iam:Delete*", "s3:GetObject*"],
8077
"Effect": "Allow",
8178
"Resource": "arn:aws:s3:::fakebucketfakebucket/*",
8279
"NotPrincipal": {"AWS": ["156460612806"]},
8380
},
8481
{
85-
"Action": [
86-
"s3:List*",
87-
],
82+
"Action": ["s3:List*"],
8883
"Effect": "Deny",
8984
"Resource": "arn:aws:s3:::fakebucketfakebucket/*",
9085
"NotPrincipal": {"AWS": ["156460612806"]},
@@ -287,13 +282,11 @@ def policy_document_not_action():
287282
**{
288283
"Statement": [
289284
{
290-
"NotAction": [
291-
"rds:*",
292-
],
285+
"NotAction": ["rds:*"],
293286
"Effect": "Allow",
294287
"Resource": "arn:aws:s3:::fakebucketfakebucket/*",
295288
"NotPrincipal": {"AWS": ["156460612806"]},
296-
},
289+
}
297290
]
298291
}
299292
)
@@ -315,8 +308,8 @@ def policy_document_condition_with_source_ip():
315308
"Effect": "Allow",
316309
"Principal": {"AWS": "*"},
317310
"Resource": "arn:aws:s3:::fakebucketfakebucket/*",
318-
},
319-
],
311+
}
312+
]
320313
}
321314
)
322315

@@ -332,8 +325,8 @@ def policy_document_condition_with_source_vpce():
332325
"Effect": "Allow",
333326
"Principal": {"AWS": "*"},
334327
"Resource": "arn:aws:s3:::fakebucketfakebucket/*",
335-
},
336-
],
328+
}
329+
]
337330
}
338331
)
339332

tests/resources/properties/test_statement_condition.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,7 @@ def test_build_evaluator_null(function: str, arg_a: Any, arg_b: Any, params: Dic
155155

156156
@pytest.mark.parametrize(
157157
"function, arg_a, arg_b, params, expected_output",
158-
[
159-
("NumericEquals", "patata", 1, {"patata": 1}, True),
160-
("NumericEquals", "patata", 1, {"patata": 2}, False),
161-
],
158+
[("NumericEquals", "patata", 1, {"patata": 1}, True), ("NumericEquals", "patata", 1, {"patata": 2}, False)],
162159
)
163160
def test_build_evaluator_numeric_equals(function: str, arg_a: Any, arg_b: Any, params: Dict, expected_output: bool):
164161
node = build_evaluator(function, arg_a, arg_b)
@@ -167,10 +164,7 @@ def test_build_evaluator_numeric_equals(function: str, arg_a: Any, arg_b: Any, p
167164

168165
@pytest.mark.parametrize(
169166
"function, arg_a, arg_b, params, expected_output",
170-
[
171-
("NumericNotEquals", "patata", 1, {"patata": 1}, False),
172-
("NumericNotEquals", "patata", 1, {"patata": 2}, True),
173-
],
167+
[("NumericNotEquals", "patata", 1, {"patata": 1}, False), ("NumericNotEquals", "patata", 1, {"patata": 2}, True)],
174168
)
175169
def test_build_evaluator_numeric_not_equals(function: str, arg_a: Any, arg_b: Any, params: Dict, expected_output: bool):
176170
node = build_evaluator(function, arg_a, arg_b)

tests/resources/test_ec2_vpc_endpoint_policy.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ def ec2_vpc_endpoint_policy():
1212
"Properties": {
1313
"PolicyDocument": {
1414
"Version": "2012-10-17",
15-
"Statement": [
16-
{
17-
"Effect": "Allow",
18-
"Principal": "*",
19-
"Action": ["s3:GetObject"],
20-
"Resource": "*",
21-
}
22-
],
15+
"Statement": [{"Effect": "Allow", "Principal": "*", "Action": ["s3:GetObject"], "Resource": "*"}],
2316
},
2417
"RouteTableIds": [{"Ref": "routetableA"}, {"Ref": "routetableB"}],
2518
"ServiceName": "com.amazonaws.eu-west-1.s3",

tests/resources/test_es_domain.py

+2-14
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66

77
@pytest.fixture()
88
def valid_empty_es_domain():
9-
return ESDomain(
10-
**{
11-
"Type": "AWS::Elasticsearch::Domain",
12-
"Properties": {},
13-
}
14-
)
9+
return ESDomain(**{"Type": "AWS::Elasticsearch::Domain", "Properties": {}})
1510

1611

1712
@pytest.fixture()
@@ -168,14 +163,7 @@ def test_valid_es_domain_from_aws_documentation_examples_resource_can_be_built(
168163

169164
def test_raise_error_if_invalid_fields_in_resource():
170165
with pytest.raises(ValidationError) as exc_info:
171-
ESDomain(
172-
**{
173-
"Type": "AWS::Elasticsearch::Domain",
174-
"Properties": {
175-
"DomainName": [],
176-
},
177-
}
178-
)
166+
ESDomain(**{"Type": "AWS::Elasticsearch::Domain", "Properties": {"DomainName": []}})
179167

180168
assert exc_info.value.errors() == [
181169
{"loc": ("Properties", "DomainName"), "msg": "str type expected", "type": "type_error.str"},

tests/resources/test_generic_resoure.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ def test_generic_resource_with_bad_json_as_string_is_converted_to_a_string_prope
8282

8383

8484
def test_parse_generic_resource_without_properties():
85-
resource = GenericResource.parse_obj(
86-
{
87-
"Type": "AWS::SNS::Topic",
88-
}
89-
)
85+
resource = GenericResource.parse_obj({"Type": "AWS::SNS::Topic"})
9086
assert isinstance(resource, GenericResource)
9187
assert resource.Properties is None
9288
assert resource.Type == "AWS::SNS::Topic"

tests/resources/test_iam_role.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ def iam_role():
1818
"Action": ["sts:AssumeRole"],
1919
"Condition": {
2020
"StringLike": {
21-
"iam:AssociatedResourceARN": [
22-
"arn:aws:ec2:us-east-1:999999999999:instance/*",
23-
]
24-
},
21+
"iam:AssociatedResourceARN": ["arn:aws:ec2:us-east-1:999999999999:instance/*"]
22+
}
2523
},
2624
},
2725
},
@@ -69,9 +67,7 @@ def test_all_conditions(iam_role):
6967
}
7068

7169
assert iam_role.assume_role_statement_conditions[0].StringLike == {
72-
"iam:AssociatedResourceARN": [
73-
"arn:aws:ec2:us-east-1:999999999999:instance/*",
74-
]
70+
"iam:AssociatedResourceARN": ["arn:aws:ec2:us-east-1:999999999999:instance/*"]
7571
}
7672

7773

tests/resources/test_opensearch_domain.py

+5-17
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@
99

1010
@pytest.fixture()
1111
def valid_empty_opensearch_domain():
12-
return OpenSearchDomain(
13-
**{
14-
"Type": "AWS::OpenSearchService::Domain",
15-
"Properties": {},
16-
}
17-
)
12+
return OpenSearchDomain(**{"Type": "AWS::OpenSearchService::Domain", "Properties": {}})
1813

1914

2015
@pytest.fixture()
@@ -82,8 +77,8 @@ def valid_opensearch_domain_with_access_policies():
8277
"Action": "es:*",
8378
"Resource": "arn:aws:es:us-east-1:123456789012:domain/test/*",
8479
}
85-
],
86-
},
80+
]
81+
}
8782
},
8883
}
8984
)
@@ -201,14 +196,7 @@ def test_valid_opensearch_domain_from_aws_documentation_examples_resource_can_be
201196

202197
def test_raise_error_if_invalid_fields_in_resource():
203198
with pytest.raises(ValidationError) as exc_info:
204-
OpenSearchDomain(
205-
**{
206-
"Type": "AWS::OpenSearchService::Domain",
207-
"Properties": {
208-
"DomainName": [],
209-
},
210-
}
211-
)
199+
OpenSearchDomain(**{"Type": "AWS::OpenSearchService::Domain", "Properties": {"DomainName": []}})
212200

213201
assert exc_info.value.errors() == [
214202
{"loc": ("Properties", "DomainName"), "msg": "str type expected", "type": "type_error.str"},
@@ -240,5 +228,5 @@ def test_can_obtain_policy_documents_from_inherited_method(valid_opensearch_doma
240228
]
241229
),
242230
name=None,
243-
),
231+
)
244232
]

tests/resources/test_s3_bucket.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ def valid_s3_bucket():
2020
"Id": "MyRule1",
2121
"Status": "Enabled",
2222
"Prefix": "MyPrefix",
23-
"Destination": {
24-
"Bucket": "arn:aws:s3:::my-replication-bucket",
25-
"StorageClass": "STANDARD",
26-
},
23+
"Destination": {"Bucket": "arn:aws:s3:::my-replication-bucket", "StorageClass": "STANDARD"},
2724
},
2825
{
2926
"Status": "Enabled",

tests/resources/test_sns_topic_policy.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ def sns_topic_policy():
1515
"Id": "MyTopicPolicy",
1616
"Version": "2012-10-17",
1717
"Statement": [
18-
{
19-
"Sid": "Stmt1",
20-
"Effect": "Allow",
21-
"Principal": "*",
22-
"Action": "sns:Publish",
23-
"Resource": "*",
24-
},
18+
{"Sid": "Stmt1", "Effect": "Allow", "Principal": "*", "Action": "sns:Publish", "Resource": "*"},
2519
{
2620
"Sid": "Stmt2",
2721
"Effect": "Allow",

tests/test_resolver.py

+8-44
Original file line numberDiff line numberDiff line change
@@ -317,30 +317,10 @@ def test_template_conditions():
317317
@pytest.mark.parametrize(
318318
"conditions, expected",
319319
[
320-
(
321-
{
322-
"testCondition": {"Fn::Equals": [True, False]},
323-
},
324-
[],
325-
),
326-
(
327-
{
328-
"testCondition": {"Fn::Equals": [True, True]},
329-
},
330-
["test_resource_id"],
331-
),
332-
(
333-
{
334-
"whatever": {"Fn::Equals": [True, False]},
335-
},
336-
["test_resource_id"],
337-
),
338-
(
339-
{
340-
"whatever": {"Fn::Equals": [True, True]},
341-
},
342-
["test_resource_id"],
343-
),
320+
({"testCondition": {"Fn::Equals": [True, False]}}, []),
321+
({"testCondition": {"Fn::Equals": [True, True]}}, ["test_resource_id"]),
322+
({"whatever": {"Fn::Equals": [True, False]}}, ["test_resource_id"]),
323+
({"whatever": {"Fn::Equals": [True, True]}}, ["test_resource_id"]),
344324
],
345325
)
346326
def test_resolve_include_resource_when_condition_is_true_or_doesnt_exist(conditions: Dict, expected: List):
@@ -352,10 +332,7 @@ def test_resolve_include_resource_when_condition_is_true_or_doesnt_exist(conditi
352332
"Type": "AWS::IAM::Role",
353333
"Condition": "testCondition",
354334
"Properties": {
355-
"AssumeRolePolicyDocument": {
356-
"Version": "2012-10-17",
357-
"Statement": [],
358-
},
335+
"AssumeRolePolicyDocument": {"Version": "2012-10-17", "Statement": []},
359336
"Path": "/",
360337
"Policies": [],
361338
},
@@ -382,10 +359,7 @@ def test_resolve_include_resource_when_condition_is_not_present():
382359
"test_resource_id": {
383360
"Type": "AWS::IAM::Role",
384361
"Properties": {
385-
"AssumeRolePolicyDocument": {
386-
"Version": "2012-10-17",
387-
"Statement": [],
388-
},
362+
"AssumeRolePolicyDocument": {"Version": "2012-10-17", "Statement": []},
389363
"Path": "/",
390364
"Policies": [],
391365
},
@@ -591,10 +565,7 @@ def test_resolve_booleans():
591565
"Properties": {
592566
"Enabled": True,
593567
"EnableKeyRotation": True,
594-
"KeyPolicy": {
595-
"Version": "2012-10-17",
596-
"Statement": [],
597-
},
568+
"KeyPolicy": {"Version": "2012-10-17", "Statement": []},
598569
},
599570
}
600571
},
@@ -679,14 +650,7 @@ def test_resolve_booleans_different_properties_for_generic_resource():
679650

680651

681652
def test_resolve_template_with_a_valid_resource_without_properties():
682-
template = {
683-
"AWSTemplateFormatVersion": "2010-09-09",
684-
"Resources": {
685-
"MySNSTopic": {
686-
"Type": "AWS::SNS::Topic",
687-
}
688-
},
689-
}
653+
template = {"AWSTemplateFormatVersion": "2010-09-09", "Resources": {"MySNSTopic": {"Type": "AWS::SNS::Topic"}}}
690654

691655
model = parse(template).resolve()
692656
resource = model.Resources["MySNSTopic"]

0 commit comments

Comments
 (0)