Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/test_scalarparse.py
1567 views
1
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
from botocore.exceptions import ProfileNotFound
14
from botocore.session import Session
15
16
from awscli.customizations import scalarparse
17
from awscli.testutils import mock, unittest
18
19
20
class TestScalarParse(unittest.TestCase):
21
def test_register_scalar_parser(self):
22
event_handers = mock.Mock()
23
scalarparse.register_scalar_parser(event_handers)
24
event_handers.register_first.assert_called_with(
25
'session-initialized', scalarparse.add_scalar_parsers)
26
27
def test_identity(self):
28
self.assertEqual(scalarparse.identity('foo'), 'foo')
29
self.assertEqual(scalarparse.identity(10), 10)
30
31
def test_scalar_parsers_set(self):
32
session = mock.Mock()
33
session.get_scoped_config.return_value = {'cli_timestamp_format':
34
'none'}
35
scalarparse.add_scalar_parsers(session)
36
session.get_component.assert_called_with('response_parser_factory')
37
factory = session.get_component.return_value
38
expected = [mock.call(blob_parser=scalarparse.identity),
39
mock.call(timestamp_parser=scalarparse.identity)]
40
self.assertEqual(factory.set_parser_defaults.mock_calls,
41
expected)
42
43
def test_choose_none_timestamp_formatter(self):
44
session = mock.Mock(spec=Session)
45
session.get_scoped_config.return_value = {'cli_timestamp_format':
46
'none'}
47
factory = session.get_component.return_value
48
scalarparse.add_scalar_parsers(session)
49
factory.set_parser_defaults.assert_called_with(
50
timestamp_parser=scalarparse.identity)
51
52
def test_choose_iso_timestamp_formatter(self):
53
session = mock.Mock(spec=Session)
54
session.get_scoped_config.return_value = {'cli_timestamp_format':
55
'iso8601'}
56
factory = session.get_component.return_value
57
scalarparse.add_scalar_parsers(session)
58
factory.set_parser_defaults.assert_called_with(
59
timestamp_parser=scalarparse.iso_format)
60
61
def test_choose_invalid_timestamp_formatter(self):
62
session = mock.Mock(spec=Session)
63
session.get_scoped_config.return_value = {'cli_timestamp_format':
64
'foobar'}
65
session.get_component.return_value
66
with self.assertRaises(ValueError):
67
scalarparse.add_scalar_parsers(session)
68
69
def test_choose_timestamp_parser_profile_not_found(self):
70
session = mock.Mock(spec=Session)
71
session.get_scoped_config.side_effect = ProfileNotFound(profile='foo')
72
factory = session.get_component.return_value
73
scalarparse.add_scalar_parsers(session)
74
factory.set_parser_defaults.assert_called_with(
75
timestamp_parser=scalarparse.identity)
76
77