Skip to content

Commit

Permalink
Fix test failures from mock 1.3.0 upgrade
Browse files Browse the repository at this point in the history
This upgrades mock to version 1.3.0 which is what's used
in botocore and boto3.

This was causing subtle test falures depending on if you installed
CLI->botocore vs. botocore->CLI.

The latest version of mock, 1.3.0, is more strict in error validation.
Specifically, any mock method that starts with "assert" will now
raise AttributeErrors if they don't exist on the mock object.

Our code was using a couple of non-existent assertion methods that were
inadvertently passing (because they just return a new mock object).
  • Loading branch information
jamesls committed Feb 4, 2016
1 parent 7916444 commit c6b1000
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ docutils>=0.10
-e git://github.com/boto/jmespath.git@develop#egg=jmespath
nose==1.3.0
colorama>=0.2.5,<=0.3.3
mock==1.0.1
mock==1.3.0
rsa>=3.1.2,<=3.3.0
wheel==0.24.0
38 changes: 22 additions & 16 deletions tests/unit/customizations/cloudtrail/test_subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,18 @@ def test_s3_create(self):

self.subscribe.setup_new_bucket('test', 'logs')

iam.get_user.assert_called()
iam.get_user.assert_called_with()

s3.get_object.assert_called()
s3.create_bucket.assert_called()
s3.put_bucket_policy.assert_called()
s3.get_object.assert_called_with(
Bucket='awscloudtrail-policy-us-east-1',
Key='policy/S3/AWSCloudTrail-S3BucketPolicy-2014-12-17.json',
)
s3.create_bucket.assert_called_with(Bucket='test')
s3.put_bucket_policy.assert_called_with(
Bucket='test', Policy=u'{"Statement": []}'
)

s3.delete_bucket.assert_not_called()
self.assertFalse(s3.delete_bucket.called)

args, kwargs = s3.create_bucket.call_args
self.assertNotIn('create_bucket_configuration', kwargs)
Expand Down Expand Up @@ -192,12 +197,6 @@ def test_s3_create_set_policy_fail(self):
with self.assertRaises(Exception):
self.subscribe.setup_new_bucket('test', 'logs')

s3.create_bucket.assert_called()
s3.put_bucket_policy.assert_called()
s3.DeleteBucket.assert_called()

s3.put_bucket_policy = orig

def test_s3_get_policy_fail(self):
self.subscribe.s3.get_object = Mock(side_effect=Exception('Foo!'))

Expand Down Expand Up @@ -231,12 +230,19 @@ def test_sns_create(self):

self.subscribe.setup_new_topic('test')

s3.get_object.assert_called()
sns.list_topics.assert_called()
sns.create_topic.assert_called()
sns.set_topic_attributes.assert_called()
s3.get_object.assert_called_with(
Bucket='awscloudtrail-policy-us-east-1',
Key='policy/SNS/AWSCloudTrail-SnsTopicPolicy-2014-12-17.json',
)
sns.list_topics.assert_called_with()
sns.create_topic.assert_called_with(Name='test')
sns.set_topic_attributes.assert_called_with(
AttributeName='Policy',
AttributeValue='{"Statement": []}',
TopicArn='foo',
)

sns.delete_topic.assert_not_called()
self.assertFalse(sns.delete_topic.called)

def test_sns_uses_regionalized_policy(self):
s3 = self.subscribe.s3
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/customizations/cloudtrail/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def test_returns_public_key_in_range(self):
'c': {'Fingerprint': 'c', 'OtherData': 'c', 'Value': 'c'},
}, keys)
cloudtrail_client.list_public_keys.assert_has_calls(
call(EndTime=end_date, StartTime=start_date))
[call(EndTime=end_date, StartTime=start_date)])


class TestSha256RSADigestValidator(unittest.TestCase):
Expand Down
16 changes: 14 additions & 2 deletions tests/unit/test_clidriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,13 @@ def test_custom_arg_paramfile(self):
self.assertEqual(rc, 0)

# Make sure uri_param was called
uri_param_mock.assert_called()
uri_param_mock.assert_any_call(
event_name='load-cli-arg.ec2.describe-instances.unknown-arg',
operation_name='describe-instances',
param=mock.ANY,
service_name='ec2',
value='file:///foo',
)
# Make sure it was called with our passed-in URI
self.assertEqual('file:///foo',
uri_param_mock.call_args_list[-1][1]['value'])
Expand All @@ -496,7 +502,13 @@ def test_custom_command_paramfile(self):

self.assertEqual(rc, 0)

uri_param_mock.assert_called()
uri_param_mock.assert_any_call(
event_name='load-cli-arg.custom.foo.bar',
operation_name='foo',
param=mock.ANY,
service_name='custom',
value='file:///foo',
)

@unittest.skip
def test_custom_arg_no_paramfile(self):
Expand Down

0 comments on commit c6b1000

Please sign in to comment.