How to use the awscli.testutils.BaseAWSCommandParamsTest function in awscli

To help you get started, we’ve selected a few awscli examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-cli / tests / functional / ses / test_send_email.py View on Github external
# the License is located at
#
#     http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from awscli.testutils import BaseAWSCommandParamsTest

from awscli.compat import six
from six.moves import cStringIO
import mock


class TestSendEmail(BaseAWSCommandParamsTest):

    prefix = 'ses send-email'

    def test_plain_text(self):
        args = (' --subject This_is_a_test --from foo@bar.com'
                ' --to fie@baz.com --text This_is_the_message')
        args_list = (self.prefix + args).split()
        result = {
            'Source': 'foo@bar.com',
            'Destination': {'ToAddresses': ['fie@baz.com']},
            'Message': {'Body': {'Text': {'Data': 'This_is_the_message'}},
                        'Subject': {'Data': 'This_is_a_test'}}}
        self.assert_params_for_cmd(args_list, result)

    def test_plain_text_multiple_to(self):
        args = (' --subject This_is_a_test --from foo@bar.com'
github aws / aws-cli / tests / functional / test_output.py View on Github external
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import json

import ruamel.yaml as yaml


from awscli.testutils import skip_if_windows, if_windows
from awscli.testutils import mock, create_clidriver, FileCreator
from awscli.testutils import BaseAWSCommandParamsTest


class TestOutput(BaseAWSCommandParamsTest):
    def setUp(self):
        super(TestOutput, self).setUp()
        self.files = FileCreator()

        self.patch_popen = mock.patch('awscli.utils.Popen')
        self.mock_popen = self.patch_popen.start()

        self.patch_tty = mock.patch('awscli.utils.is_a_tty')
        self.mock_is_a_tty = self.patch_tty.start()
        self.mock_is_a_tty.return_value = True

        self.cmdline = 'ec2 describe-regions'
        self.parsed_response = {
            "Regions": [
                {
                        "Endpoint": "ec2.ap-south-1.amazonaws.com",
github aws / aws-cli / tests / functional / elb / test_configure_health_check.py View on Github external
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
#     http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from awscli.testutils import BaseAWSCommandParamsTest


class TestConfigureHealthCheck(BaseAWSCommandParamsTest):

    prefix = 'elb configure-health-check'

    def test_shorthand_basic(self):
        cmdline = self.prefix
        cmdline += ' --load-balancer-name my-lb'
        cmdline += (' --health-check Target=HTTP:80/weather/us/wa/seattle,'
                    'Interval=300,Timeout=60,UnhealthyThreshold=5,'
                    'HealthyThreshold=9')
        result = {
            'HealthCheck': {
                'HealthyThreshold': 9,
                'Interval': 300,
                'Target': 'HTTP:80/weather/us/wa/seattle',
                'Timeout': 60,
                'UnhealthyThreshold': 5},
github aws / aws-cli / tests / functional / ddb / test_select.py View on Github external
# the License is located at
#
#     http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import json

import ruamel.yaml as yaml

from awscli.testutils import BaseAWSCommandParamsTest


class BaseSelectTest(BaseAWSCommandParamsTest):
    def assert_yaml_response_equal(self, response, expected):
        with self.assertRaises(ValueError):
            json.loads(response)
        loaded = yaml.safe_load(response)
        self.assertEqual(loaded, expected)


class TestSelect(BaseSelectTest):
    def setUp(self):
        super(TestSelect, self).setUp()
        self.parsed_response = {
            "Count": 1,
            "Items": [{"foo": {"S": "spam"}}],
            "ScannedCount": 1,
        }
github aws / aws-cli / tests / functional / ec2 / test_create_network_acl_entry.py View on Github external
# Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
#     http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from awscli.testutils import BaseAWSCommandParamsTest


class TestCreateNetworkACLEntry(BaseAWSCommandParamsTest):

    prefix = 'ec2 create-network-acl-entry'

    def test_tcp(self):
        cmdline = self.prefix
        cmdline += ' --network-acl-id acl-12345678'
        cmdline += ' --rule-number 100'
        cmdline += ' --protocol tcp'
        cmdline += ' --rule-action allow'
        cmdline += ' --ingress'
        cmdline += ' --port-range From=22,To=22'
        cmdline += ' --cidr-block 0.0.0.0/0'
        result = {'NetworkAclId': 'acl-12345678',
                  'RuleNumber': 100,
                  'Protocol': '6',
                  'RuleAction': 'allow',
github aws / aws-cli / tests / unit / output / test_json_output.py View on Github external
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from botocore.compat import json
import platform
import mock
from awscli.compat import six
from awscli.formatter import JSONFormatter

from awscli.testutils import BaseAWSCommandParamsTest, unittest
from awscli.compat import get_stdout_text_writer


class TestGetPasswordData(BaseAWSCommandParamsTest):

    prefix = 'iam add-user-to-group '

    def test_empty_response_prints_nothing(self):
        # This is the default response, but we want to be explicit
        # that we're returning an empty dict.
        self.parsed_response = {}
        args = ' --group-name foo --user-name bar'
        cmdline = self.prefix + args
        result = {'GroupName': 'foo', 'UserName': 'bar'}
        stdout = self.assert_params_for_cmd(cmdline, result, expected_rc=0)[0]
        # We should have printed nothing because the parsed response
        # is an empty dict: {}.
        self.assertEqual(stdout, '')
github aws / aws-cli / tests / functional / cloudtrail / test_validation.py View on Github external
digest_provider, validator):
    def mock_create(trail_arn, cloudtrail_client, s3_client_provider,
                    organization_client, trail_source_region,
                    bucket, prefix, on_missing, on_invalid, on_gap,
                    account_id):
        bucket = bucket or '1'
        return DigestTraverser(
            digest_provider=digest_provider, starting_bucket=bucket,
            starting_prefix=prefix, public_key_provider=key_provider,
            digest_validator=validator, on_invalid=on_invalid, on_gap=on_gap,
            on_missing=on_missing)

    mock_create_digest_traverser.side_effect = mock_create


class BaseCloudTrailCommandTest(BaseAWSCommandParamsTest):
    def setUp(self):
        super(BaseCloudTrailCommandTest, self).setUp()
        # We need to remove this handler to ensure that we can mock out the
        # get_bucket_location operation.
        self.driver.session.unregister('after-call.s3.GetBucketLocation',
                                       parse_get_bucket_location)
        self._logs = [
            {'hashValue': '44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a',
             'oldestEventTime': '2015-08-16T22:36:54Z',
             's3Object': 'key1',
             'hashAlgorithm': 'SHA-256',
             's3Bucket': '1',
             'newestEventTime': '2015-08-16T22:36:54Z',
             '_raw_value': '{}'},
            {'hashValue': '7a38bf81f383f69433ad6e900d35b3e2385593f76a7b7ab5d4355b8ba41ee24b',
             'oldestEventTime': '2015-08-16T22:54:56Z',
github aws / aws-cli / tests / functional / apigateway / test_put_integration.py View on Github external
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
#     http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from awscli.testutils import BaseAWSCommandParamsTest


class TestPutIntegration(BaseAWSCommandParamsTest):

    prefix = 'apigateway put-integration '

    def test_put_integration(self):
        cmdline = self.prefix
        cmdline += '--rest-api-id api-id '
        cmdline += '--resource-id resource-id '
        cmdline += '--http-method GET '
        cmdline += '--type HTTP '
        cmdline += '--integration-http-method GET '
        cmdline += '--uri https://api.endpoint.com'
        result = {
            'restApiId': 'api-id', 'resourceId': 'resource-id',
            'httpMethod': 'GET', 'type': 'HTTP',
            'integrationHttpMethod': 'GET',
            'uri': 'https://api.endpoint.com'
github aws / aws-cli / tests / unit / customizations / cloudtrail / test_validation.py View on Github external
public_keys = {'a': {'Fingerprint': 'a', 'Value': 'a'}}
        key_provider.get_public_keys.return_value = public_keys
        digest_validator = Sha256RSADigestValidator()
        on_invalid, calls = collecting_callback()
        traverser = DigestTraverser(
            digest_provider=digest_provider, starting_bucket='1',
            starting_prefix='baz', public_key_provider=key_provider,
            digest_validator=digest_validator, on_invalid=on_invalid)
        digest_iter = traverser.traverse(start_date, end_date)
        next(digest_iter, None)
        self.assertIn(
            'Digest file\ts3://1/%s\tINVALID: ' % end_timestamp,
            calls[0]['message'])


class TestCloudTrailCommand(BaseAWSCommandParamsTest):
    def test_s3_client_created_lazily(self):
        session = Mock()
        command = CloudTrailValidateLogs(session)
        parsed_globals = Mock(region=None, verify_ssl=None, endpoint_url=None)
        command.setup_services(parsed_globals)
        create_client_calls = session.create_client.call_args_list
        self.assertEqual(
            create_client_calls,
            [
                call('organizations', verify=None, region_name=None),
                call('cloudtrail', verify=None, region_name=None)
            ]
        )

    def test_endpoint_url_is_used_for_cloudtrail(self):
        endpoint_url = 'https://mycloudtrail.aws.amazon.com/'
github aws / aws-cli / tests / functional / ec2 / test_get_password_data.py View on Github external
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from awscli.testutils import BaseAWSCommandParamsTest
import os


PASSWORD_DATA = ("GWDnuoj/7pbMQkg125E8oGMUVCI+r98sGbFFl8SX+dEYxMZzz+byYwwjvyg8i"
                 "SGKaLuLTIWatWopVu5cMWDKH65U4YFL2g3LqyajBrCFnuSE1piTeS/rPQpoSv"
                 "BN5FGj9HWqNrglWAJgh9OZNSGgpEojBenL/0rwSpDWL7f/f52M5doYA6q+v0y"
                 "gEoi1Wq6hcmrBfyA4seW1RlKgnUru5Y9oc1hFHi53E3b1EkjGqCsCemVUwumB"
                 "j8uwCLJRaMcqrCxK1smtAsiSqk0Jk9jpN2vcQgnMPypEdmEEXyWHwq55fjy6c"
                 "h+sqYcwumIL5QcFW2JQ5+XBEoFhC66gOsAXow==")


class TestGetPasswordData(BaseAWSCommandParamsTest):

    prefix = 'ec2 get-password-data'

    def setUp(self):
        super(TestGetPasswordData, self).setUp()
        self.parsed_response = {'InstanceId': 'i-12345678',
                                'Timestamp': '2013-07-27T18:29:23.000Z',
                                'PasswordData': PASSWORD_DATA}

    def test_no_priv_launch_key(self):
        args = ' --instance-id i-12345678'
        cmdline = self.prefix + args
        result = {'InstanceId': 'i-12345678'}
        output = self.assert_params_for_cmd(cmdline, result, expected_rc=0)[0]
        self.assertIn('"InstanceId": "i-12345678"', output)
        self.assertIn('"Timestamp": "2013-07-27T18:29:23.000Z"', output)