Path: blob/develop/tests/unit/customizations/test_cloudsearchdomain.py
1567 views
# Copyright 2014 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 awscli.testutils import mock, unittest13from awscli.testutils import BaseAWSCommandParamsTest14from awscli.help import PagingHelpRenderer15from awscli.customizations.cloudsearchdomain import validate_endpoint_url161718class TestSearchCommand(BaseAWSCommandParamsTest):19prefix = 'cloudsearchdomain search '2021def test_search_with_query(self):22cmd = self.prefix.split()23cmd += [24'--endpoint-url', 'http://example.com/',25# Note we're also verifying that --query is renamed to26# --search-query from argrename.py.27'--search-query', 'George Lucas',28'--query-options',29'{"defaultOperator":"and","fields":["directors^10"]}']3031expected = {32'query': u'George Lucas',33'queryOptions': u'{"defaultOperator":"and","fields":["directors^10"]}'34}35self.assert_params_for_cmd(cmd, expected)3637def test_endpoint_is_required(self):38cmd = self.prefix.split()39cmd += ['--search-query', 'foo']40stderr = self.run_cmd(cmd, expected_rc=255)[1]41self.assertIn('--endpoint-url is required', stderr)4243def test_endpoint_not_required_for_help(self):44cmd = self.prefix + 'help'45with mock.patch('awscli.help.get_renderer') as get_renderer:46mock_render = mock.Mock(spec=PagingHelpRenderer)47get_renderer.return_value = mock_render48stdout, stderr, rc = self.run_cmd(cmd, expected_rc=None)49# If we get this far we've succeeded, but we can do50# a quick sanity check and make sure the service name is51# in the stdout help text.52self.assertIn(stdout, 'cloudsearchdomain')535455class TestCloudsearchDomainHandler(unittest.TestCase):56def test_validate_endpoint_url_is_none(self):57parsed_globals = mock.Mock()58parsed_globals.endpoint_url = None59# Method should return instantiated exception.60self.assertTrue(isinstance(validate_endpoint_url(parsed_globals),61ValueError))626364if __name__ == "__main__":65unittest.main()666768