1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
# Copyright 2017 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 botocore.exceptions import ProfileNotFound
from botocore.session import Session
from awscli.customizations import timestampformat
from awscli.customizations.exceptions import ConfigurationError
from awscli.testutils import mock, unittest
class TestScalarParse(unittest.TestCase):
def test_register_timestamp_format(self):
event_handers = mock.Mock()
timestampformat.register_timestamp_format(event_handers)
event_handers.register_first.assert_called_with(
'session-initialized', timestampformat.add_timestamp_parser
)
def test_identity(self):
self.assertEqual(timestampformat.identity('foo'), 'foo')
self.assertEqual(timestampformat.identity(10), 10)
def test_scalar_parsers_set(self):
session = mock.Mock()
session.get_scoped_config.return_value = {
'cli_timestamp_format': 'wire'
}
timestampformat.add_timestamp_parser(session)
session.get_component.assert_called_with('response_parser_factory')
factory = session.get_component.return_value
expected = [mock.call(timestamp_parser=timestampformat.identity)]
self.assertEqual(factory.set_parser_defaults.mock_calls, expected)
def test_choose_none_timestamp_formatter(self):
session = mock.Mock(spec=Session)
session.get_scoped_config.return_value = {
'cli_timestamp_format': 'wire'
}
factory = session.get_component.return_value
timestampformat.add_timestamp_parser(session)
factory.set_parser_defaults.assert_called_with(
timestamp_parser=timestampformat.identity
)
def test_choose_iso_timestamp_formatter(self):
session = mock.Mock(spec=Session)
session.get_scoped_config.return_value = {
'cli_timestamp_format': 'iso8601'
}
factory = session.get_component.return_value
timestampformat.add_timestamp_parser(session)
factory.set_parser_defaults.assert_called_with(
timestamp_parser=timestampformat.iso_format
)
def test_choose_invalid_timestamp_formatter(self):
session = mock.Mock(spec=Session)
session.get_scoped_config.return_value = {
'cli_timestamp_format': 'foobar'
}
session.get_component.return_value
with self.assertRaises(ConfigurationError):
timestampformat.add_timestamp_parser(session)
def test_choose_timestamp_parser_profile_not_found(self):
session = mock.Mock(spec=Session)
session.get_scoped_config.side_effect = ProfileNotFound(profile='foo')
factory = session.get_component.return_value
timestampformat.add_timestamp_parser(session)
factory.set_parser_defaults.assert_called_with(
timestamp_parser=timestampformat.iso_format
)
|