Path: blob/develop/tests/unit/customizations/test_scalarparse.py
2624 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, mock.Mock(v2_debug=False))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, mock.Mock(v2_debug=False))48factory.set_parser_defaults.assert_called_with(49timestamp_parser=scalarparse.identity)5051def test_choose_wire_timestamp_formatter(self):52session = mock.Mock(spec=Session)53session.get_scoped_config.return_value = {'cli_timestamp_format':54'wire'}55factory = session.get_component.return_value56scalarparse.add_scalar_parsers(session, mock.Mock(v2_debug=False))57factory.set_parser_defaults.assert_called_with(58timestamp_parser=scalarparse.identity)5960def test_choose_iso_timestamp_formatter(self):61session = mock.Mock(spec=Session)62session.get_scoped_config.return_value = {'cli_timestamp_format':63'iso8601'}64factory = session.get_component.return_value65scalarparse.add_scalar_parsers(session, mock.Mock(v2_debug=False))66factory.set_parser_defaults.assert_called_with(67timestamp_parser=scalarparse.iso_format)6869def test_choose_invalid_timestamp_formatter(self):70session = mock.Mock(spec=Session)71session.get_scoped_config.return_value = {'cli_timestamp_format':72'foobar'}73session.get_component.return_value74with self.assertRaises(ValueError):75scalarparse.add_scalar_parsers(session, mock.Mock(v2_debug=False))7677def test_choose_timestamp_parser_profile_not_found(self):78session = mock.Mock(spec=Session)79session.get_scoped_config.side_effect = ProfileNotFound(profile='foo')80factory = session.get_component.return_value81scalarparse.add_scalar_parsers(session, mock.Mock(v2_debug=False))82factory.set_parser_defaults.assert_called_with(83timestamp_parser=scalarparse.identity)848586