Skip to content

Commit

Permalink
Update paramfile test
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgtaylor committed Mar 13, 2015
1 parent 47b285e commit 34fd660
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions tests/unit/customizations/test_cloudtrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
# language governing permissions and limitations under the License.
import json

from mock import ANY, Mock, call
from mock import ANY, Mock, call, patch
from botocore.client import ClientError
from botocore.session import Session

from tests.unit.test_clidriver import FakeSession
from awscli.compat import six
Expand Down Expand Up @@ -46,14 +47,32 @@ def test_create_subscription_has_zero_rc(self):
# sure it says log delivery is happening.
self.assertIn('Logs will be delivered to foo', stdout)

def test_policy_from_paramfile(self):
@patch.object(Session, 'create_client')
def test_policy_from_paramfile(self, create_client_mock):
client = Mock()
# S3 mock calls
client.get_user.return_value = {'User': {'Arn': ':::::'}}
client.head_bucket.side_effect = ClientError(
{'Error': {'Code': 404, 'Message': ''}}, 'HeadBucket')
# CloudTrail mock call
client.describe_trails.return_value = {}
create_client_mock.return_value = client

policy = '{"Statement": []}'

with temporary_file('w') as f:
f.write('{"Statement": []}')
f.write(policy)
f.flush()
command = (
'cloudtrail create-subscription --s3-use-bucket foo '
'cloudtrail create-subscription --s3-new-bucket foo '
'--name bar --s3-custom-policy file://{0}'.format(f.name))
self.run_cmd(command, expected_rc=0)

# Ensure that the *contents* of the file are sent as the policy
# parameter to S3.
client.put_bucket_policy.assert_called_with(
Bucket='foo', Policy=policy)


class TestCloudTrailCommand(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit 34fd660

Please sign in to comment.