Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/s3/test_s3.py
1569 views
1
# Copyright 2014 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.0e
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 awscli.testutils import mock, unittest, BaseAWSCommandParamsTest
14
from awscli.customizations.s3.s3 import awscli_initialize, add_s3
15
16
17
class AWSInitializeTest(unittest.TestCase):
18
"""
19
This test ensures that all events are correctly registered such that
20
all of the commands can be run.
21
"""
22
def setUp(self):
23
self.cli = mock.Mock()
24
25
def test_initialize(self):
26
awscli_initialize(self.cli)
27
reference = []
28
reference.append("building-command-table.main")
29
reference.append("building-command-table.sync")
30
for arg in self.cli.register.call_args_list:
31
self.assertIn(arg[0][0], reference)
32
33
34
class CreateTablesTest(unittest.TestCase):
35
def test_s3(self):
36
"""
37
Ensures that the table for the service was created properly.
38
Also ensures the original s3 service is renamed to ``s3api``.
39
"""
40
s3_service = mock.Mock()
41
s3_service.name = 's3'
42
self.services = {'s3': s3_service}
43
add_s3(self.services, True)
44
orig_service = self.services.pop('s3api')
45
self.assertEqual(orig_service, s3_service)
46
for service in self.services.keys():
47
self.assertIn(service, ['s3'])
48
49
50
class TestS3(BaseAWSCommandParamsTest):
51
def test_too_few_args(self):
52
stderr = self.run_cmd('s3', expected_rc=255)[1]
53
self.assertIn(("usage: aws [options] <command> "
54
"<subcommand> [parameters]"), stderr)
55
self.assertIn('too few arguments', stderr)
56
57
58
if __name__ == "__main__":
59
unittest.main()
60
61