Path: blob/develop/tests/unit/customizations/test_scalarparse.py
1567 views
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License"). You3# may not use this file except in compliance with the License. A copy of4# the License is located at5#6# http://aws.amazon.com/apache2.0/7#8# or in the "license" file accompanying this file. This file is9# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF10# ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License.12from botocore.exceptions import ProfileNotFound13from botocore.session import Session1415from awscli.customizations import scalarparse16from awscli.testutils import mock, unittest171819class TestScalarParse(unittest.TestCase):20def test_register_scalar_parser(self):21event_handers = mock.Mock()22scalarparse.register_scalar_parser(event_handers)23event_handers.register_first.assert_called_with(24'session-initialized', scalarparse.add_scalar_parsers)2526def test_identity(self):27self.assertEqual(scalarparse.identity('foo'), 'foo')28self.assertEqual(scalarparse.identity(10), 10)2930def test_scalar_parsers_set(self):31session = mock.Mock()32session.get_scoped_config.return_value = {'cli_timestamp_format':33'none'}34scalarparse.add_scalar_parsers(session)35session.get_component.assert_called_with('response_parser_factory')36factory = session.get_component.return_value37expected = [mock.call(blob_parser=scalarparse.identity),38mock.call(timestamp_parser=scalarparse.identity)]39self.assertEqual(factory.set_parser_defaults.mock_calls,40expected)4142def test_choose_none_timestamp_formatter(self):43session = mock.Mock(spec=Session)44session.get_scoped_config.return_value = {'cli_timestamp_format':45'none'}46factory = session.get_component.return_value47scalarparse.add_scalar_parsers(session)48factory.set_parser_defaults.assert_called_with(49timestamp_parser=scalarparse.identity)5051def test_choose_iso_timestamp_formatter(self):52session = mock.Mock(spec=Session)53session.get_scoped_config.return_value = {'cli_timestamp_format':54'iso8601'}55factory = session.get_component.return_value56scalarparse.add_scalar_parsers(session)57factory.set_parser_defaults.assert_called_with(58timestamp_parser=scalarparse.iso_format)5960def test_choose_invalid_timestamp_formatter(self):61session = mock.Mock(spec=Session)62session.get_scoped_config.return_value = {'cli_timestamp_format':63'foobar'}64session.get_component.return_value65with self.assertRaises(ValueError):66scalarparse.add_scalar_parsers(session)6768def test_choose_timestamp_parser_profile_not_found(self):69session = mock.Mock(spec=Session)70session.get_scoped_config.side_effect = ProfileNotFound(profile='foo')71factory = session.get_component.return_value72scalarparse.add_scalar_parsers(session)73factory.set_parser_defaults.assert_called_with(74timestamp_parser=scalarparse.identity)757677