Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/test_cloudsearchdomain.py
1567 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.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 awscli.testutils import mock, unittest
14
from awscli.testutils import BaseAWSCommandParamsTest
15
from awscli.help import PagingHelpRenderer
16
from awscli.customizations.cloudsearchdomain import validate_endpoint_url
17
18
19
class TestSearchCommand(BaseAWSCommandParamsTest):
20
prefix = 'cloudsearchdomain search '
21
22
def test_search_with_query(self):
23
cmd = self.prefix.split()
24
cmd += [
25
'--endpoint-url', 'http://example.com/',
26
# Note we're also verifying that --query is renamed to
27
# --search-query from argrename.py.
28
'--search-query', 'George Lucas',
29
'--query-options',
30
'{"defaultOperator":"and","fields":["directors^10"]}']
31
32
expected = {
33
'query': u'George Lucas',
34
'queryOptions': u'{"defaultOperator":"and","fields":["directors^10"]}'
35
}
36
self.assert_params_for_cmd(cmd, expected)
37
38
def test_endpoint_is_required(self):
39
cmd = self.prefix.split()
40
cmd += ['--search-query', 'foo']
41
stderr = self.run_cmd(cmd, expected_rc=255)[1]
42
self.assertIn('--endpoint-url is required', stderr)
43
44
def test_endpoint_not_required_for_help(self):
45
cmd = self.prefix + 'help'
46
with mock.patch('awscli.help.get_renderer') as get_renderer:
47
mock_render = mock.Mock(spec=PagingHelpRenderer)
48
get_renderer.return_value = mock_render
49
stdout, stderr, rc = self.run_cmd(cmd, expected_rc=None)
50
# If we get this far we've succeeded, but we can do
51
# a quick sanity check and make sure the service name is
52
# in the stdout help text.
53
self.assertIn(stdout, 'cloudsearchdomain')
54
55
56
class TestCloudsearchDomainHandler(unittest.TestCase):
57
def test_validate_endpoint_url_is_none(self):
58
parsed_globals = mock.Mock()
59
parsed_globals.endpoint_url = None
60
# Method should return instantiated exception.
61
self.assertTrue(isinstance(validate_endpoint_url(parsed_globals),
62
ValueError))
63
64
65
if __name__ == "__main__":
66
unittest.main()
67
68