Conditions | 1 |
Total Lines | 92 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | # -*- coding: utf-8 -*- |
||
9 | def setUp(self): |
||
10 | self.parameters = [ |
||
11 | ( |
||
12 | # AWS Lambda event payload. Request from AWS Config |
||
13 | { |
||
14 | "invokingEvent": json.dumps({ |
||
15 | "configurationItem": { |
||
16 | "configurationItemCaptureTime": "2016-02-17T01:36:34.043Z", |
||
17 | "awsAccountId": "123456789012", |
||
18 | "configurationItemStatus": "OK", |
||
19 | "resourceId": "i-00000000", |
||
20 | "ARN": "arn:aws:ec2:us-east-1:123456789012:instance/i-00000000", |
||
21 | "awsRegion": "us-east-1", |
||
22 | "availabilityZone": "us-east-1a", |
||
23 | "resourceType": "AWS::EC2::Instance", |
||
24 | "tags": {"Foo": "Bar"}, |
||
25 | "relationships": [{ |
||
26 | "resourceId": "eipalloc-00000000", |
||
27 | "resourceType": "AWS::EC2::EIP", |
||
28 | "name": "Is attached to ElasticIp" |
||
29 | }], |
||
30 | "configuration": { |
||
31 | "foo": "bar" |
||
32 | } |
||
33 | }, |
||
34 | "messageType": "ConfigurationItemChangeNotification" |
||
35 | }), |
||
36 | "ruleParameters": json.dumps({ |
||
37 | "myParameterKey": "myParameterValue" |
||
38 | }), |
||
39 | "resultToken": "myResultToken", |
||
40 | "eventLeftScope": False, |
||
41 | "executionRoleArn": "arn:aws:iam::123456789012:role/config-role", |
||
42 | "configRuleArn": "arn:aws:config:us-east-1:123456789012:config-rule/config-rule-0123456", |
||
43 | "configRuleName": "change-triggered-config-rule", |
||
44 | "configRuleId": "config-rule-0123456", |
||
45 | "accountId": "123456789012", |
||
46 | "version": "1.0" |
||
47 | }, |
||
48 | # Response |
||
49 | { |
||
50 | "Evaluations": [{ |
||
51 | "OrderingTimestamp": "2016-02-17T01:36:34.043Z", |
||
52 | "ComplianceResourceId": "i-00000000", |
||
53 | "ComplianceResourceType": "AWS::EC2::Instance", |
||
54 | "Annotation": "This resource is compliant with the rule.", |
||
55 | "ComplianceType": "COMPLIANT" |
||
56 | }], |
||
57 | "ResultToken": "myResultToken" |
||
58 | } |
||
59 | ), ( |
||
60 | # AWS Lambda event payload. Request from AWS Config |
||
61 | { |
||
62 | "invokingEvent": json.dumps({ |
||
63 | "configurationItem": { |
||
64 | "configurationItemCaptureTime": "2016-02-17T01:36:34.043Z", |
||
65 | "awsAccountId": "123456789012", |
||
66 | "configurationItemStatus": "OK", |
||
67 | "resourceId": "sg-00000000", |
||
68 | "ARN": "arn:aws:ec2:us-east-1:123456789012:security-group/sg-00000000", |
||
69 | "awsRegion": "us-east-1", |
||
70 | "availabilityZone": "us-east-1a", |
||
71 | "resourceType": "AWS::EC2::SecurityGroup", |
||
72 | "tags": {"Foo": "Bar"}, |
||
73 | "configuration": { |
||
74 | "foo": "bar" |
||
75 | } |
||
76 | }, |
||
77 | "messageType": "ConfigurationItemChangeNotification" |
||
78 | }), |
||
79 | "ruleParameters": json.dumps({ |
||
80 | "myParameterKey": "myParameterValue" |
||
81 | }), |
||
82 | "resultToken": "myResultToken", |
||
83 | "eventLeftScope": False, |
||
84 | "executionRoleArn": "arn:aws:iam::123456789012:role/config-role", |
||
85 | "configRuleArn": "arn:aws:config:us-east-1:123456789012:config-rule/config-rule-0123456", |
||
86 | "configRuleName": "change-triggered-config-rule", |
||
87 | "configRuleId": "config-rule-0123456", |
||
88 | "accountId": "123456789012", |
||
89 | "version": "1.0" |
||
90 | }, |
||
91 | # Response |
||
92 | { |
||
93 | "Evaluations": [{ |
||
94 | "OrderingTimestamp": "2016-02-17T01:36:34.043Z", |
||
95 | "ComplianceResourceId": "sg-00000000", |
||
96 | "ComplianceResourceType": "AWS::EC2::SecurityGroup", |
||
97 | "Annotation": "The rule doesn't apply to resources of type AWS::EC2::SecurityGroup.", |
||
98 | "ComplianceType": "NOT_APPLICABLE" |
||
99 | }], |
||
100 | "ResultToken": "myResultToken" |
||
101 | } |
||
123 |