Rewriting some tests and also rewriting the MockAWS module to automatically map …
…all responses in responses.py to mocks in the client.
Showing
7 changed files
with
165 additions
and
70 deletions
tests/unit/data/BazPolicy.json
0 → 100644
1 | +{ | ||
2 | + "Statement":[ | ||
3 | + {"Condition": | ||
4 | + {"ArnLike":{"AWS:SourceArn":"arn:aws:sns:us-east-1:123456789012:lambda_topic"}}, | ||
5 | + "Resource":"arn:aws:lambda:us-east-1:123456789023:function:messageStore", | ||
6 | + "Action":"lambda:invokeFunction", | ||
7 | + "Principal":{"Service":"sns.amazonaws.com"}, | ||
8 | + "Sid":"sns invoke","Effect":"Allow" | ||
9 | + }], | ||
10 | + "Id":"default", | ||
11 | + "Version":"2012-10-17" | ||
12 | +} |
tests/unit/data/roles.cf
deleted
100644 → 0
File mode changed
1 | +import inspect | ||
2 | + | ||
1 | import mock | 3 | import mock |
2 | 4 | ||
3 | import tests.unit.responses as responses | 5 | import tests.unit.responses as responses |
... | @@ -6,40 +8,23 @@ import tests.unit.responses as responses | ... | @@ -6,40 +8,23 @@ import tests.unit.responses as responses |
6 | class MockAWS(object): | 8 | class MockAWS(object): |
7 | 9 | ||
8 | def __init__(self, profile=None, region=None): | 10 | def __init__(self, profile=None, region=None): |
9 | - pass | 11 | + self.response_map = {} |
12 | + for name, value in inspect.getmembers(responses): | ||
13 | + if name.startswith('__'): | ||
14 | + continue | ||
15 | + if '_' in name: | ||
16 | + service_name, request_name = name.split('_', 1) | ||
17 | + if service_name not in self.response_map: | ||
18 | + self.response_map[service_name] = {} | ||
19 | + self.response_map[service_name][request_name] = value | ||
10 | 20 | ||
11 | def create_client(self, client_name): | 21 | def create_client(self, client_name): |
12 | client = None | 22 | client = None |
13 | - if client_name == 'logs': | 23 | + if client_name in self.response_map: |
14 | - client = mock.Mock() | ||
15 | - choices = responses.logs_describe_log_groups | ||
16 | - client.describe_log_groups = mock.Mock( | ||
17 | - side_effect=choices) | ||
18 | - choices = responses.logs_describe_log_streams | ||
19 | - client.describe_log_streams = mock.Mock( | ||
20 | - side_effect=choices) | ||
21 | - choices = responses.logs_get_log_events | ||
22 | - client.get_log_events = mock.Mock( | ||
23 | - side_effect=choices) | ||
24 | - if client_name == 'cloudformation': | ||
25 | - client = mock.Mock() | ||
26 | - choices = responses.cfn_list_stack_resources | ||
27 | - client.list_stack_resources = mock.Mock( | ||
28 | - side_effect=choices) | ||
29 | - choices = responses.cfn_describe_stacks | ||
30 | - client.describe_stacks = mock.Mock( | ||
31 | - side_effect=choices) | ||
32 | - choices = responses.cfn_create_stack | ||
33 | - client.create_stack = mock.Mock( | ||
34 | - side_effect=choices) | ||
35 | - choices = responses.cfn_delete_stack | ||
36 | - client.delete_stack = mock.Mock( | ||
37 | - side_effect=choices) | ||
38 | - if client_name == 'iam': | ||
39 | client = mock.Mock() | 24 | client = mock.Mock() |
40 | - choices = responses.iam_get_role | 25 | + for request in self.response_map[client_name]: |
41 | - client.get_role = mock.Mock( | 26 | + response = self.response_map[client_name][request] |
42 | - side_effect=choices) | 27 | + setattr(client, request, mock.Mock(side_effect=response)) |
43 | return client | 28 | return client |
44 | 29 | ||
45 | 30 | ... | ... |
1 | import datetime | 1 | import datetime |
2 | from dateutil.tz import tzutc | 2 | from dateutil.tz import tzutc |
3 | 3 | ||
4 | -cfn_list_stack_resources = [{'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': 'dd35f0ef-9699-11e4-ba38-c355c9515dbc'}, u'StackResourceSummaries': [{u'ResourceStatus': 'CREATE_COMPLETE', u'ResourceType': 'AWS::IAM::Role', u'ResourceStatusReason': None, u'LastUpdatedTimestamp': datetime.datetime(2015, 1, 6, 17, 37, 54, 861000, tzinfo=tzutc()), u'PhysicalResourceId': 'TestKinesis-InvokeRole-IF6VUXY9MBJN', u'LogicalResourceId': 'InvokeRole'}, {u'ResourceStatus': 'CREATE_COMPLETE', u'ResourceType': 'AWS::IAM::Role', u'ResourceStatusReason': None, u'LastUpdatedTimestamp': datetime.datetime(2015, 1, 6, 17, 37, 55, 18000, tzinfo=tzutc()), u'PhysicalResourceId': 'TestKinesis-ExecRole-567SAV6TZOET', u'LogicalResourceId': 'ExecRole'}, {u'ResourceStatus': 'CREATE_COMPLETE', u'ResourceType': 'AWS::IAM::Policy', u'ResourceStatusReason': None, u'LastUpdatedTimestamp': datetime.datetime(2015, 1, 6, 17, 37, 58, 120000, tzinfo=tzutc()), u'PhysicalResourceId': 'TestK-Invo-OMW5SDLQM8FM', u'LogicalResourceId': 'InvokeRolePolicies'}, {u'ResourceStatus': 'CREATE_COMPLETE', u'ResourceType': 'AWS::IAM::Policy', u'ResourceStatusReason': None, u'LastUpdatedTimestamp': datetime.datetime(2015, 1, 6, 17, 37, 58, 454000, tzinfo=tzutc()), u'PhysicalResourceId': 'TestK-Exec-APWRVKTBPPPT', u'LogicalResourceId': 'ExecRolePolicies'}]}] | 4 | +iam_list_policies = [{u'IsTruncated': True, |
5 | + u'Marker': 'ABcyoYmSlphARcitCJruhVIxKW3Hg1LJD3Fm4LAW8iGKykrSNrApiUoz2rjIuNiLJpT6JtUgP5M7wTuPZcHu1KsvMarvgFBFQObTPSa4WF22Zg==', | ||
6 | + u'Policies': [{u'Arn': 'arn:aws:iam::123456789012:policy/FooPolicy', | ||
7 | + u'AttachmentCount': 0, | ||
8 | + u'CreateDate': datetime.datetime(2015, 2, 24, 3, 16, 24, tzinfo=tzutc()), | ||
9 | + u'DefaultVersionId': 'v2', | ||
10 | + u'IsAttachable': True, | ||
11 | + u'Path': '/', | ||
12 | + u'PolicyId': 'ANPAJHWE6R7YT7PLAH3KG', | ||
13 | + u'PolicyName': 'FooPolicy', | ||
14 | + u'UpdateDate': datetime.datetime(2015, 2, 25, 0, 19, 12, tzinfo=tzutc())}, | ||
15 | + {u'Arn': 'arn:aws:iam::123456789012:policy/BarPolicy', | ||
16 | + u'AttachmentCount': 1, | ||
17 | + u'CreateDate': datetime.datetime(2015, 2, 25, 0, 11, 57, tzinfo=tzutc()), | ||
18 | + u'DefaultVersionId': 'v2', | ||
19 | + u'IsAttachable': True, | ||
20 | + u'Path': '/', | ||
21 | + u'PolicyId': 'ANPAJU7MVBQXOQTVQN3VM', | ||
22 | + u'PolicyName': 'BarPolicy', | ||
23 | + u'UpdateDate': datetime.datetime(2015, 2, 25, 0, 13, 8, tzinfo=tzutc())}, | ||
24 | + {u'Arn': 'arn:aws:iam::123456789012:policy/FiePolicy', | ||
25 | + u'AttachmentCount': 1, | ||
26 | + u'CreateDate': datetime.datetime(2015, 3, 21, 19, 18, 21, tzinfo=tzutc()), | ||
27 | + u'DefaultVersionId': 'v4', | ||
28 | + u'IsAttachable': True, | ||
29 | + u'Path': '/', | ||
30 | + u'PolicyId': 'ANPAIXQ72B2OH2RZPYQ4Y', | ||
31 | + u'PolicyName': 'FiePolicy', | ||
32 | + u'UpdateDate': datetime.datetime(2015, 3, 26, 23, 26, 52, tzinfo=tzutc())}], | ||
33 | +'ResponseMetadata': {'HTTPStatusCode': 200, | ||
34 | + 'RequestId': '4e87c995-ecf2-11e4-bb10-51f1499b3162'}}] | ||
35 | + | ||
36 | +iam_create_policy = [{u'Policy': {u'PolicyName': 'LambdaChatDynamoDBPolicy', u'CreateDate': datetime.datetime(2015, 4, 27, 12, 13, 35, 240000, tzinfo=tzutc()), u'AttachmentCount': 0, u'IsAttachable': True, u'PolicyId': 'ANPAISQNU4EPZZDVZUOKU', u'DefaultVersionId': 'v1', u'Path': '/kappa/', u'Arn': 'arn:aws:iam::658794617753:policy/kappa/LambdaChatDynamoDBPolicy', u'UpdateDate': datetime.datetime(2015, 4, 27, 12, 13, 35, 240000, tzinfo=tzutc())}, 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': 'd403e95f-ecd6-11e4-9ee0-15e8b71db930'}}] | ||
37 | + | ||
38 | +iam_list_roles = [{'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': 'd41415ff-ecd6-11e4-bb10-51f1499b3162'}, u'IsTruncated': False, u'Roles': [{u'AssumeRolePolicyDocument': {u'Version': u'2012-10-17', u'Statement': [{u'Action': u'sts:AssumeRole', u'Principal': {u'Service': u'lambda.amazonaws.com'}, u'Effect': u'Allow', u'Sid': u''}]}, u'RoleId': 'AROAJ4JSNL3M4UYI6GDYS', u'CreateDate': datetime.datetime(2015, 4, 27, 11, 59, 19, tzinfo=tzutc()), u'RoleName': 'FooRole', u'Path': '/kappa/', u'Arn': 'arn:aws:iam::123456789012:role/kappa/FooRole'}]}] | ||
39 | + | ||
40 | +iam_create_role = [{u'Role': {u'AssumeRolePolicyDocument': {u'Version': u'2012-10-17', u'Statement': [{u'Action': [u'sts:AssumeRole'], u'Effect': u'Allow', u'Principal': {u'Service': [u'lambda.amazonaws.com']}}]}, u'RoleId': 'AROAIT2ZRRPQBOIBBHPZU', u'CreateDate': datetime.datetime(2015, 4, 27, 12, 13, 35, 426000, tzinfo=tzutc()), u'RoleName': 'BazRole', u'Path': '/kappa/', u'Arn': 'arn:aws:iam::123456789012:role/kappa/BazRole'}, 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': 'd41fd55c-ecd6-11e4-9fd8-03ee0021e940'}}] | ||
5 | 41 | ||
6 | iam_get_role = [{u'Role': {u'AssumeRolePolicyDocument': {u'Version': u'2012-10-17', u'Statement': [{u'Action': u'sts:AssumeRole', u'Principal': {u'Service': u's3.amazonaws.com'}, u'Effect': u'Allow', u'Condition': {u'ArnLike': {u'sts:ExternalId': u'arn:aws:s3:::*'}}, u'Sid': u''}, {u'Action': u'sts:AssumeRole', u'Principal': {u'Service': u'lambda.amazonaws.com'}, u'Effect': u'Allow', u'Sid': u''}]}, u'RoleId': 'AROAIEVJHUJG2I4MG5PSC', u'CreateDate': datetime.datetime(2015, 1, 6, 17, 37, 44, tzinfo=tzutc()), u'RoleName': 'TestKinesis-InvokeRole-IF6VUXY9MBJN', u'Path': '/', u'Arn': 'arn:aws:iam::0123456789012:role/TestKinesis-InvokeRole-FOO'}, 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': 'dd6e8d42-9699-11e4-afe6-d3625e8b365b'}}] | 42 | iam_get_role = [{u'Role': {u'AssumeRolePolicyDocument': {u'Version': u'2012-10-17', u'Statement': [{u'Action': u'sts:AssumeRole', u'Principal': {u'Service': u's3.amazonaws.com'}, u'Effect': u'Allow', u'Condition': {u'ArnLike': {u'sts:ExternalId': u'arn:aws:s3:::*'}}, u'Sid': u''}, {u'Action': u'sts:AssumeRole', u'Principal': {u'Service': u'lambda.amazonaws.com'}, u'Effect': u'Allow', u'Sid': u''}]}, u'RoleId': 'AROAIEVJHUJG2I4MG5PSC', u'CreateDate': datetime.datetime(2015, 1, 6, 17, 37, 44, tzinfo=tzutc()), u'RoleName': 'TestKinesis-InvokeRole-IF6VUXY9MBJN', u'Path': '/', u'Arn': 'arn:aws:iam::0123456789012:role/TestKinesis-InvokeRole-FOO'}, 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': 'dd6e8d42-9699-11e4-afe6-d3625e8b365b'}}] |
7 | 43 | ||
44 | +iam_attach_role_policy = [{'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': 'd43e32dc-ecd6-11e4-9fd8-03ee0021e940'}}] | ||
45 | + | ||
46 | +iam_detach_role_policy = [{'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': 'a7d30b51-ecd6-11e4-bbe4-d996b8ad5d9e'}}] | ||
47 | + | ||
48 | +iam_delete_role = [{'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': 'a7e5a97e-ecd6-11e4-ae9e-6dee7bf37e66'}}] | ||
49 | + | ||
50 | +lambda_create_function = [{u'FunctionName': u'LambdaChatDynamoDB', 'ResponseMetadata': {'HTTPStatusCode': 201, 'RequestId': 'd7840efb-ecd6-11e4-b8b0-f7f3177894e9'}, u'CodeSize': 22024, u'MemorySize': 128, u'FunctionArn': u'arn:aws:lambda:us-east-1:123456789012:function:FooBarFunction', u'Handler': u'FooBarFunction.handler', u'Role': u'arn:aws:iam::123456789012:role/kappa/BazRole', u'Timeout': 3, u'LastModified': u'2015-04-27T12:13:41.147+0000', u'Runtime': u'nodejs', u'Description': u'A FooBar function'}] | ||
51 | + | ||
52 | +lambda_delete_function = [{'ResponseMetadata': {'HTTPStatusCode': 204, 'RequestId': 'a499b2c2-ecd6-11e4-8d2a-77b7e55836e7'}}] | ||
53 | + | ||
8 | logs_describe_log_groups = [{'ResponseMetadata': {'HTTPStatusCode': 200, | 54 | logs_describe_log_groups = [{'ResponseMetadata': {'HTTPStatusCode': 200, |
9 | 'RequestId': 'da962431-afed-11e4-8c17-1776597471e6'}, | 55 | 'RequestId': 'da962431-afed-11e4-8c17-1776597471e6'}, |
10 | u'logGroups': [{u'arn': u'arn:aws:logs:us-east-1:0123456789012:log-group:/aws/lambda/KinesisSample*', | 56 | u'logGroups': [{u'arn': u'arn:aws:logs:us-east-1:0123456789012:log-group:/aws/lambda/KinesisSample*', |
... | @@ -23,13 +69,3 @@ logs_describe_log_groups = [{'ResponseMetadata': {'HTTPStatusCode': 200, | ... | @@ -23,13 +69,3 @@ logs_describe_log_groups = [{'ResponseMetadata': {'HTTPStatusCode': 200, |
23 | logs_describe_log_streams = [{u'logStreams': [{u'firstEventTimestamp': 1417042749449, u'lastEventTimestamp': 1417042749547, u'creationTime': 1417042748263, u'uploadSequenceToken': u'49540114640150833041490484409222729829873988799393975922', u'logStreamName': u'1cc48e4e613246b7974094323259d600', u'lastIngestionTime': 1417042750483, u'arn': u'arn:aws:logs:us-east-1:0123456789012:log-group:/aws/lambda/KinesisSample:log-stream:1cc48e4e613246b7974094323259d600', u'storedBytes': 712}, {u'firstEventTimestamp': 1417272406988, u'lastEventTimestamp': 1417272407088, u'creationTime': 1417272405690, u'uploadSequenceToken': u'49540113907504451034164105858363493278561872472363261986', u'logStreamName': u'2782a5ff88824c85a9639480d1ed7bbe', u'lastIngestionTime': 1417272408043, u'arn': u'arn:aws:logs:us-east-1:0123456789012:log-group:/aws/lambda/KinesisSample:log-stream:2782a5ff88824c85a9639480d1ed7bbe', u'storedBytes': 712}, {u'firstEventTimestamp': 1420569035842, u'lastEventTimestamp': 1420569035941, u'creationTime': 1420569034614, u'uploadSequenceToken': u'49540113907883563702539166025438885323514410026454245426', u'logStreamName': u'2d62991a479b4ebf9486176122b72a55', u'lastIngestionTime': 1420569036909, u'arn': u'arn:aws:logs:us-east-1:0123456789012:log-group:/aws/lambda/KinesisSample:log-stream:2d62991a479b4ebf9486176122b72a55', u'storedBytes': 709}, {u'firstEventTimestamp': 1418244027421, u'lastEventTimestamp': 1418244027541, u'creationTime': 1418244026907, u'uploadSequenceToken': u'49540113964795065449189116778452984186276757901477438642', u'logStreamName': u'4f44ffa128d6405591ca83b2b0f9dd2d', u'lastIngestionTime': 1418244028484, u'arn': u'arn:aws:logs:us-east-1:0123456789012:log-group:/aws/lambda/KinesisSample:log-stream:4f44ffa128d6405591ca83b2b0f9dd2d', u'storedBytes': 1010}, {u'firstEventTimestamp': 1418242565524, u'lastEventTimestamp': 1418242565641, u'creationTime': 1418242564196, u'uploadSequenceToken': u'49540113095132904942090446312687285178819573422397343074', u'logStreamName': u'69c5ac87e7e6415985116e8cb44e538e', u'lastIngestionTime': 1418242566558, u'arn': u'arn:aws:logs:us-east-1:0123456789012:log-group:/aws/lambda/KinesisSample:log-stream:69c5ac87e7e6415985116e8cb44e538e', u'storedBytes': 713}, {u'firstEventTimestamp': 1417213193378, u'lastEventTimestamp': 1417213193478, u'creationTime': 1417213192095, u'uploadSequenceToken': u'49540113336360065754596187770479764234792559857643841394', u'logStreamName': u'f68e3d87b8a14cdba338f6926f7cf50a', u'lastIngestionTime': 1417213194421, u'arn': u'arn:aws:logs:us-east-1:0123456789012:log-group:/aws/lambda/KinesisSample:log-stream:f68e3d87b8a14cdba338f6926f7cf50a', u'storedBytes': 711}], 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2a6d4941-969b-11e4-947f-19d1c72ede7e'}}] | 69 | logs_describe_log_streams = [{u'logStreams': [{u'firstEventTimestamp': 1417042749449, u'lastEventTimestamp': 1417042749547, u'creationTime': 1417042748263, u'uploadSequenceToken': u'49540114640150833041490484409222729829873988799393975922', u'logStreamName': u'1cc48e4e613246b7974094323259d600', u'lastIngestionTime': 1417042750483, u'arn': u'arn:aws:logs:us-east-1:0123456789012:log-group:/aws/lambda/KinesisSample:log-stream:1cc48e4e613246b7974094323259d600', u'storedBytes': 712}, {u'firstEventTimestamp': 1417272406988, u'lastEventTimestamp': 1417272407088, u'creationTime': 1417272405690, u'uploadSequenceToken': u'49540113907504451034164105858363493278561872472363261986', u'logStreamName': u'2782a5ff88824c85a9639480d1ed7bbe', u'lastIngestionTime': 1417272408043, u'arn': u'arn:aws:logs:us-east-1:0123456789012:log-group:/aws/lambda/KinesisSample:log-stream:2782a5ff88824c85a9639480d1ed7bbe', u'storedBytes': 712}, {u'firstEventTimestamp': 1420569035842, u'lastEventTimestamp': 1420569035941, u'creationTime': 1420569034614, u'uploadSequenceToken': u'49540113907883563702539166025438885323514410026454245426', u'logStreamName': u'2d62991a479b4ebf9486176122b72a55', u'lastIngestionTime': 1420569036909, u'arn': u'arn:aws:logs:us-east-1:0123456789012:log-group:/aws/lambda/KinesisSample:log-stream:2d62991a479b4ebf9486176122b72a55', u'storedBytes': 709}, {u'firstEventTimestamp': 1418244027421, u'lastEventTimestamp': 1418244027541, u'creationTime': 1418244026907, u'uploadSequenceToken': u'49540113964795065449189116778452984186276757901477438642', u'logStreamName': u'4f44ffa128d6405591ca83b2b0f9dd2d', u'lastIngestionTime': 1418244028484, u'arn': u'arn:aws:logs:us-east-1:0123456789012:log-group:/aws/lambda/KinesisSample:log-stream:4f44ffa128d6405591ca83b2b0f9dd2d', u'storedBytes': 1010}, {u'firstEventTimestamp': 1418242565524, u'lastEventTimestamp': 1418242565641, u'creationTime': 1418242564196, u'uploadSequenceToken': u'49540113095132904942090446312687285178819573422397343074', u'logStreamName': u'69c5ac87e7e6415985116e8cb44e538e', u'lastIngestionTime': 1418242566558, u'arn': u'arn:aws:logs:us-east-1:0123456789012:log-group:/aws/lambda/KinesisSample:log-stream:69c5ac87e7e6415985116e8cb44e538e', u'storedBytes': 713}, {u'firstEventTimestamp': 1417213193378, u'lastEventTimestamp': 1417213193478, u'creationTime': 1417213192095, u'uploadSequenceToken': u'49540113336360065754596187770479764234792559857643841394', u'logStreamName': u'f68e3d87b8a14cdba338f6926f7cf50a', u'lastIngestionTime': 1417213194421, u'arn': u'arn:aws:logs:us-east-1:0123456789012:log-group:/aws/lambda/KinesisSample:log-stream:f68e3d87b8a14cdba338f6926f7cf50a', u'storedBytes': 711}], 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2a6d4941-969b-11e4-947f-19d1c72ede7e'}}] |
24 | 70 | ||
25 | logs_get_log_events = [{'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2a7deb71-969b-11e4-914b-8f1f3d7b023d'}, u'nextForwardToken': u'f/31679748107442531967654742688057700554200447759088287749', u'events': [{u'ingestionTime': 1420569036909, u'timestamp': 1420569035842, u'message': u'2015-01-06T18:30:35.841Z\tko2sss03iq7l2pdk\tLoading event\n'}, {u'ingestionTime': 1420569036909, u'timestamp': 1420569035899, u'message': u'START RequestId: 23007242-95d2-11e4-a10e-7b2ab60a7770\n'}, {u'ingestionTime': 1420569036909, u'timestamp': 1420569035940, u'message': u'2015-01-06T18:30:35.940Z\t23007242-95d2-11e4-a10e-7b2ab60a7770\t{\n "Records": [\n {\n "kinesis": {\n "partitionKey": "partitionKey-3",\n "kinesisSchemaVersion": "1.0",\n "data": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=",\n "sequenceNumber": "49545115243490985018280067714973144582180062593244200961"\n },\n "eventSource": "aws:kinesis",\n "eventID": "shardId-000000000000:49545115243490985018280067714973144582180062593244200961",\n "invokeIdentityArn": "arn:aws:iam::0123456789012:role/testLEBRole",\n "eventVersion": "1.0",\n "eventName": "aws:kinesis:record",\n "eventSourceARN": "arn:aws:kinesis:us-east-1:35667example:stream/examplestream",\n "awsRegion": "us-east-1"\n }\n ]\n}\n'}, {u'ingestionTime': 1420569036909, u'timestamp': 1420569035940, u'message': u'2015-01-06T18:30:35.940Z\t23007242-95d2-11e4-a10e-7b2ab60a7770\tDecoded payload: Hello, this is a test 123.\n'}, {u'ingestionTime': 1420569036909, u'timestamp': 1420569035941, u'message': u'END RequestId: 23007242-95d2-11e4-a10e-7b2ab60a7770\n'}, {u'ingestionTime': 1420569036909, u'timestamp': 1420569035941, u'message': u'REPORT RequestId: 23007242-95d2-11e4-a10e-7b2ab60a7770\tDuration: 98.51 ms\tBilled Duration: 100 ms \tMemory Size: 128 MB\tMax Memory Used: 26 MB\t\n'}], u'nextBackwardToken': u'b/31679748105234758193000210997045664445208259969996226560'}] | 71 | logs_get_log_events = [{'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2a7deb71-969b-11e4-914b-8f1f3d7b023d'}, u'nextForwardToken': u'f/31679748107442531967654742688057700554200447759088287749', u'events': [{u'ingestionTime': 1420569036909, u'timestamp': 1420569035842, u'message': u'2015-01-06T18:30:35.841Z\tko2sss03iq7l2pdk\tLoading event\n'}, {u'ingestionTime': 1420569036909, u'timestamp': 1420569035899, u'message': u'START RequestId: 23007242-95d2-11e4-a10e-7b2ab60a7770\n'}, {u'ingestionTime': 1420569036909, u'timestamp': 1420569035940, u'message': u'2015-01-06T18:30:35.940Z\t23007242-95d2-11e4-a10e-7b2ab60a7770\t{\n "Records": [\n {\n "kinesis": {\n "partitionKey": "partitionKey-3",\n "kinesisSchemaVersion": "1.0",\n "data": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=",\n "sequenceNumber": "49545115243490985018280067714973144582180062593244200961"\n },\n "eventSource": "aws:kinesis",\n "eventID": "shardId-000000000000:49545115243490985018280067714973144582180062593244200961",\n "invokeIdentityArn": "arn:aws:iam::0123456789012:role/testLEBRole",\n "eventVersion": "1.0",\n "eventName": "aws:kinesis:record",\n "eventSourceARN": "arn:aws:kinesis:us-east-1:35667example:stream/examplestream",\n "awsRegion": "us-east-1"\n }\n ]\n}\n'}, {u'ingestionTime': 1420569036909, u'timestamp': 1420569035940, u'message': u'2015-01-06T18:30:35.940Z\t23007242-95d2-11e4-a10e-7b2ab60a7770\tDecoded payload: Hello, this is a test 123.\n'}, {u'ingestionTime': 1420569036909, u'timestamp': 1420569035941, u'message': u'END RequestId: 23007242-95d2-11e4-a10e-7b2ab60a7770\n'}, {u'ingestionTime': 1420569036909, u'timestamp': 1420569035941, u'message': u'REPORT RequestId: 23007242-95d2-11e4-a10e-7b2ab60a7770\tDuration: 98.51 ms\tBilled Duration: 100 ms \tMemory Size: 128 MB\tMax Memory Used: 26 MB\t\n'}], u'nextBackwardToken': u'b/31679748105234758193000210997045664445208259969996226560'}] |
26 | - | ||
27 | -cfn_describe_stacks = [ | ||
28 | - {u'Stacks': [{u'StackId': 'arn:aws:cloudformation:us-east-1:084307701560:stack/TestKinesis/7c4ae730-96b8-11e4-94cc-5001dc3ed8d2', u'Description': None, u'Tags': [], u'StackStatusReason': 'User Initiated', u'CreationTime': datetime.datetime(2015, 1, 7, 21, 59, 43, 208000, tzinfo=tzutc()), u'Capabilities': ['CAPABILITY_IAM'], u'StackName': 'TestKinesis', u'NotificationARNs': [], u'StackStatus': 'CREATE_IN_PROGRESS', u'DisableRollback': False}], 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '7d66debd-96b8-11e4-a647-4f4741ffff69'}}, | ||
29 | - {u'Stacks': [{u'StackId': 'arn:aws:cloudformation:us-east-1:084307701560:stack/TestKinesis/7c4ae730-96b8-11e4-94cc-5001dc3ed8d2', u'Description': None, u'Tags': [], u'StackStatusReason': 'User Initiated', u'CreationTime': datetime.datetime(2015, 1, 7, 21, 59, 43, 208000, tzinfo=tzutc()), u'Capabilities': ['CAPABILITY_IAM'], u'StackName': 'TestKinesis', u'NotificationARNs': [], u'StackStatus': 'CREATE_IN_PROGRESS', u'DisableRollback': False}], 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '7e36fff7-96b8-11e4-af44-6350f4f8c2ae'}}, | ||
30 | - {u'Stacks': [{u'StackId': 'arn:aws:cloudformation:us-east-1:084307701560:stack/TestKinesis/7c4ae730-96b8-11e4-94cc-5001dc3ed8d2', u'Description': None, u'Tags': [], u'StackStatusReason': 'User Initiated', u'CreationTime': datetime.datetime(2015, 1, 7, 21, 59, 43, 208000, tzinfo=tzutc()), u'Capabilities': ['CAPABILITY_IAM'], u'StackName': 'TestKinesis', u'NotificationARNs': [], u'StackStatus': 'CREATE_IN_PROGRESS', u'DisableRollback': False}], 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '7ef03e10-96b8-11e4-bc86-7f67e11abcfa'}}, | ||
31 | - {u'Stacks': [{u'StackId': 'arn:aws:cloudformation:us-east-1:084307701560:stack/TestKinesis/7c4ae730-96b8-11e4-94cc-5001dc3ed8d2', u'Description': None, u'Tags': [], u'StackStatusReason': None, u'CreationTime': datetime.datetime(2015, 1, 7, 21, 59, 43, 208000, tzinfo=tzutc()), u'Capabilities': ['CAPABILITY_IAM'], u'StackName': 'TestKinesis', u'NotificationARNs': [], u'StackStatus': 'CREATE_COMPLETE', u'DisableRollback': False}], 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '8c2bff8e-96b8-11e4-be70-c5ad82c32f2d'}}] | ||
32 | - | ||
33 | -cfn_create_stack = [{u'StackId': 'arn:aws:cloudformation:us-east-1:084307701560:stack/TestKinesis/7c4ae730-96b8-11e4-94cc-5001dc3ed8d2', 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '7c2f2260-96b8-11e4-be70-c5ad82c32f2d'}}] | ||
34 | - | ||
35 | -cfn_delete_stack = [{'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': 'f19af5b8-96bc-11e4-860e-11ba752b58a9'}}] | ... | ... |
tests/unit/test_policy.py
0 → 100644
1 | +# Copyright (c) 2015 Mitch Garnaat http://garnaat.org/ | ||
2 | +# | ||
3 | +# Licensed under the Apache License, Version 2.0 (the "License"). You | ||
4 | +# may not use this file except in compliance with the License. A copy of | ||
5 | +# the License is located at | ||
6 | +# | ||
7 | +# http://aws.amazon.com/apache2.0/ | ||
8 | +# | ||
9 | +# or in the "license" file accompanying this file. This file is | ||
10 | +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
11 | +# ANY KIND, either express or implied. See the License for the specific | ||
12 | +# language governing permissions and limitations under the License. | ||
13 | + | ||
14 | +import unittest | ||
15 | +import os | ||
16 | + | ||
17 | +import mock | ||
18 | + | ||
19 | +from kappa.policy import Policy | ||
20 | +from tests.unit.mock_aws import get_aws | ||
21 | + | ||
22 | +Config1 = { | ||
23 | + 'name': 'FooPolicy', | ||
24 | + 'description': 'This is the Foo policy', | ||
25 | + 'document': 'FooPolicy.json'} | ||
26 | + | ||
27 | +Config2 = { | ||
28 | + 'name': 'BazPolicy', | ||
29 | + 'description': 'This is the Baz policy', | ||
30 | + 'document': 'BazPolicy.json'} | ||
31 | + | ||
32 | + | ||
33 | +def path(filename): | ||
34 | + return os.path.join(os.path.dirname(__file__), 'data', filename) | ||
35 | + | ||
36 | + | ||
37 | +class TestPolicy(unittest.TestCase): | ||
38 | + | ||
39 | + def setUp(self): | ||
40 | + self.aws_patch = mock.patch('kappa.aws.get_aws', get_aws) | ||
41 | + self.mock_aws = self.aws_patch.start() | ||
42 | + Config1['document'] = path(Config1['document']) | ||
43 | + Config2['document'] = path(Config2['document']) | ||
44 | + | ||
45 | + def tearDown(self): | ||
46 | + self.aws_patch.stop() | ||
47 | + | ||
48 | + def test_properties(self): | ||
49 | + mock_context = mock.Mock() | ||
50 | + policy = Policy(mock_context, Config1) | ||
51 | + self.assertEqual(policy.name, Config1['name']) | ||
52 | + self.assertEqual(policy.document, Config1['document']) | ||
53 | + self.assertEqual(policy.description, Config1['description']) | ||
54 | + | ||
55 | + def test_exists(self): | ||
56 | + mock_context = mock.Mock() | ||
57 | + policy = Policy(mock_context, Config1) | ||
58 | + self.assertTrue(policy.exists()) | ||
59 | + | ||
60 | + def test_not_exists(self): | ||
61 | + mock_context = mock.Mock() | ||
62 | + policy = Policy(mock_context, Config2) | ||
63 | + self.assertFalse(policy.exists()) | ||
64 | + | ||
65 | + def test_create(self): | ||
66 | + mock_context = mock.Mock() | ||
67 | + policy = Policy(mock_context, Config2) | ||
68 | + policy.create() | ||
69 | + | ||
70 | + def test_delete(self): | ||
71 | + mock_context = mock.Mock() | ||
72 | + policy = Policy(mock_context, Config1) | ||
73 | + policy.delete() |
... | @@ -12,56 +12,47 @@ | ... | @@ -12,56 +12,47 @@ |
12 | # language governing permissions and limitations under the License. | 12 | # language governing permissions and limitations under the License. |
13 | 13 | ||
14 | import unittest | 14 | import unittest |
15 | -import os | ||
16 | 15 | ||
17 | import mock | 16 | import mock |
18 | 17 | ||
19 | -from kappa.stack import Stack | 18 | +from kappa.role import Role |
20 | from tests.unit.mock_aws import get_aws | 19 | from tests.unit.mock_aws import get_aws |
21 | 20 | ||
22 | -Config = { | 21 | +Config1 = {'name': 'FooRole'} |
23 | - 'template': 'roles.cf', | ||
24 | - 'stack_name': 'FooBar', | ||
25 | - 'exec_role': 'ExecRole', | ||
26 | - 'invoke_role': 'InvokeRole'} | ||
27 | 22 | ||
23 | +Config2 = {'name': 'BazRole'} | ||
28 | 24 | ||
29 | -def path(filename): | ||
30 | - return os.path.join(os.path.dirname(__file__), 'data', filename) | ||
31 | 25 | ||
32 | - | 26 | +class TestRole(unittest.TestCase): |
33 | -class TestStack(unittest.TestCase): | ||
34 | 27 | ||
35 | def setUp(self): | 28 | def setUp(self): |
36 | self.aws_patch = mock.patch('kappa.aws.get_aws', get_aws) | 29 | self.aws_patch = mock.patch('kappa.aws.get_aws', get_aws) |
37 | self.mock_aws = self.aws_patch.start() | 30 | self.mock_aws = self.aws_patch.start() |
38 | - Config['template'] = path(Config['template']) | ||
39 | 31 | ||
40 | def tearDown(self): | 32 | def tearDown(self): |
41 | self.aws_patch.stop() | 33 | self.aws_patch.stop() |
42 | 34 | ||
43 | def test_properties(self): | 35 | def test_properties(self): |
44 | mock_context = mock.Mock() | 36 | mock_context = mock.Mock() |
45 | - stack = Stack(mock_context, Config) | 37 | + role = Role(mock_context, Config1) |
46 | - self.assertEqual(stack.name, Config['stack_name']) | 38 | + self.assertEqual(role.name, Config1['name']) |
47 | - self.assertEqual(stack.template_path, Config['template']) | ||
48 | - self.assertEqual(stack.exec_role, Config['exec_role']) | ||
49 | - self.assertEqual(stack.invoke_role, Config['invoke_role']) | ||
50 | - self.assertEqual( | ||
51 | - stack.invoke_role_arn, | ||
52 | - 'arn:aws:iam::0123456789012:role/TestKinesis-InvokeRole-FOO') | ||
53 | 39 | ||
54 | def test_exists(self): | 40 | def test_exists(self): |
55 | mock_context = mock.Mock() | 41 | mock_context = mock.Mock() |
56 | - stack = Stack(mock_context, Config) | 42 | + role = Role(mock_context, Config1) |
57 | - self.assertTrue(stack.exists()) | 43 | + self.assertTrue(role.exists()) |
44 | + | ||
45 | + def test_not_exists(self): | ||
46 | + mock_context = mock.Mock() | ||
47 | + role = Role(mock_context, Config2) | ||
48 | + self.assertFalse(role.exists()) | ||
58 | 49 | ||
59 | - def test_update(self): | 50 | + def test_create(self): |
60 | mock_context = mock.Mock() | 51 | mock_context = mock.Mock() |
61 | - stack = Stack(mock_context, Config) | 52 | + role = Role(mock_context, Config2) |
62 | - stack.update() | 53 | + role.create() |
63 | 54 | ||
64 | def test_delete(self): | 55 | def test_delete(self): |
65 | mock_context = mock.Mock() | 56 | mock_context = mock.Mock() |
66 | - stack = Stack(mock_context, Config) | 57 | + role = Role(mock_context, Config1) |
67 | - stack.delete() | 58 | + role.delete() | ... | ... |
-
Please register or login to post a comment