How to use service_operation method in localstack

Best Python code snippet using localstack_python

test_generatecliskeleton.py

Source:test_generatecliskeleton.py Github

copy

Full Screen

1# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License"). You4# may not use this file except in compliance with the License. A copy of5# the License is located at6#7# http://aws.amazon.com/apache2.0/8#9# or in the "license" file accompanying this file. This file is10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF11# ANY KIND, either express or implied. See the License for the specific12# language governing permissions and limitations under the License.13from awscli.compat import six14from botocore.model import DenormalizedStructureBuilder15from awscli.testutils import mock, unittest16from awscli.customizations.generatecliskeleton import \17 GenerateCliSkeletonArgument18class TestGenerateCliSkeleton(unittest.TestCase):19 def setUp(self):20 self.session = mock.Mock()21 # Create a mock service operation object22 self.service_operation = mock.Mock()23 # Make an arbitrary input model shape.24 self.input_shape = {25 'A': {26 'type': 'structure',27 'members': {28 'B': {'type': 'string'},29 }30 }31 }32 shape = DenormalizedStructureBuilder().with_members(33 self.input_shape).build_model()34 self.operation_model = mock.Mock(input_shape=shape)35 self.argument = GenerateCliSkeletonArgument(self.session, self.operation_model)36 # This is what the json should should look like after being37 # generated to standard output.38 self.ref_json_output = \39 '{\n "A": {\n "B": ""\n }\n}\n'40 def test_register_argument_action(self):41 register_args = self.session.register.call_args_list42 self.assertEqual(register_args[0][0][0], 'calling-command.*')43 self.assertEqual(register_args[0][0][1],44 self.argument.generate_json_skeleton)45 def test_no_override_required_args_when_output(self):46 argument_table = {}47 mock_arg = mock.Mock()48 mock_arg.required = True49 argument_table['required-arg'] = mock_arg50 args = ['--generate-cli-skeleton', 'output']51 self.argument.override_required_args(argument_table, args)52 self.assertTrue(argument_table['required-arg'].required)53 def test_override_required_args_when_input(self):54 argument_table = {}55 mock_arg = mock.Mock()56 mock_arg.required = True57 argument_table['required-arg'] = mock_arg58 args = ['--generate-cli-skeleton']59 self.argument.override_required_args(argument_table, args)60 self.assertFalse(argument_table['required-arg'].required)61 def test_override_required_args_when_output_present_but_not_value(self):62 argument_table = {}63 mock_arg = mock.Mock()64 mock_arg.required = True65 argument_table['required-arg'] = mock_arg66 args = ['--generate-cli-skeleton', '--some-other-param', 'output']67 self.argument.override_required_args(argument_table, args)68 self.assertFalse(argument_table['required-arg'].required)69 def test_generate_json_skeleton(self):70 parsed_args = mock.Mock()71 parsed_args.generate_cli_skeleton = 'input'72 with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:73 rc = self.argument.generate_json_skeleton(74 service_operation=self.service_operation, call_parameters=None,75 parsed_args=parsed_args, parsed_globals=None76 )77 # Ensure the contents printed to standard output are correct.78 self.assertEqual(self.ref_json_output, mock_stdout.getvalue())79 # Ensure it is the correct return code of zero.80 self.assertEqual(rc, 0)81 def test_no_generate_json_skeleton(self):82 parsed_args = mock.Mock()83 parsed_args.generate_cli_skeleton = None84 with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:85 rc = self.argument.generate_json_skeleton(86 service_operation=self.service_operation, call_parameters=None,87 parsed_args=parsed_args, parsed_globals=None88 )89 # Ensure nothing is printed to standard output90 self.assertEqual('', mock_stdout.getvalue())91 # Ensure nothing is returned because it was never called.92 self.assertEqual(rc, None)93 def test_generate_json_skeleton_no_input_shape(self):94 parsed_args = mock.Mock()95 parsed_args.generate_cli_skeleton = 'input'96 # Set the input shape to ``None``.97 self.argument = GenerateCliSkeletonArgument(98 self.session, mock.Mock(input_shape=None))99 with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:100 rc = self.argument.generate_json_skeleton(101 service_operation=self.service_operation, call_parameters=None,102 parsed_args=parsed_args, parsed_globals=None103 )104 # Ensure the contents printed to standard output are correct,105 # which should be an empty dictionary.106 self.assertEqual('{}\n', mock_stdout.getvalue())107 # Ensure it is the correct return code of zero.108 self.assertEqual(rc, 0)109 def test_generate_json_skeleton_with_timestamp(self):110 parsed_args = mock.Mock()111 parsed_args.generate_cli_skeleton = 'input'112 input_shape = {113 'A': {114 'type': 'structure',115 'members': {116 'B': {'type': 'timestamp'},117 }118 }119 }120 shape = DenormalizedStructureBuilder().with_members(121 input_shape).build_model()122 operation_model = mock.Mock(input_shape=shape)123 argument = GenerateCliSkeletonArgument(124 self.session, operation_model)125 with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:126 rc = argument.generate_json_skeleton(127 call_parameters=None, parsed_args=parsed_args,128 parsed_globals=None129 )130 self.assertEqual(131 '{\n'132 ' "A": {\n'133 ' "B": "1970-01-01T00:00:00"\n'134 ' }\n'135 '}\n', mock_stdout.getvalue())...

Full Screen

Full Screen

aws_cli_helper.py

Source:aws_cli_helper.py Github

copy

Full Screen

...27 return self.__aws_service_help_catalog[service_name]28 def list_service_operations(self, service_name):29 """ Returns list of service operations """30 return list(self.get_service(service_name).command_table.keys())31 def get_service_operation(self, service_name, service_operation):32 """ Returns service operation """33 return self.get_service(service_name).command_table[service_operation]34 def list_service_operation_arguments(self, service_name, service_operation):35 """ Returns list of service operation arguments """36 return list(self.get_service(service_name).command_table[service_operation].arg_table.keys())37 def get_service_operation_argument(self, service_name, service_operation, argument_name):38 """ Returns service operation argument """39 return self.get_service_operation(service_name, service_operation).arg_table[argument_name]40 def get_service_operation_details(self, service_name, service_operation):41 """ Returns help object for service operation """42 return self.get_service_operation(service_name, service_operation).create_help_command()43 # def get_detail_service_command_arguments(self, service_name, service_command):44 # """ Returns list of service operation arguments """45 # ops_arg_details = OrderedDict({ 'service' : OrderedDict({}),46 # 'operation' : OrderedDict({}),47 # 'arguments' : OrderedDict({}) })48 49 # service_help = self.get_service(service_name)50 # if service_help:51 # ops_arg_details['service']['name'] = service_help.name52 # ops_arg_details['service']['description'] = service_help.obj.documentation53 54 # operation = service_help.command_table.get(service_operation) 55 # if operation:56 # detail_operation = operation.create_help_command() ...

Full Screen

Full Screen

test_cliinputjson.py

Source:test_cliinputjson.py Github

copy

Full Screen

1# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License"). You4# may not use this file except in compliance with the License. A copy of5# the License is located at6#7# http://aws.amazon.com/apache2.0/8#9# or in the "license" file accompanying this file. This file is10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF11# ANY KIND, either express or implied. See the License for the specific12# language governing permissions and limitations under the License.13import os14import shutil15import tempfile16from awscli.testutils import mock, unittest17from awscli.argprocess import ParamError18from awscli.customizations.cliinputjson import CliInputJSONArgument19class TestCliInputJSONArgument(unittest.TestCase):20 def setUp(self):21 self.session = mock.Mock()22 self.argument = CliInputJSONArgument(self.session)23 # Create the various forms the data could come in. The two main forms24 # are as a string and or as a path to a file.25 self.input_json = '{"A": "foo", "B": "bar"}'26 # Make a temporary file27 self.temp_dir = tempfile.mkdtemp()28 self.temp_file = os.path.join(self.temp_dir, 'foo.json')29 with open(self.temp_file, 'w') as f:30 f.write(self.input_json)31 def tearDown(self):32 shutil.rmtree(self.temp_dir)33 def test_register_argument_action(self):34 register_args = self.session.register.call_args_list35 self.assertEqual(register_args[0][0][0], 'calling-command.*')36 self.assertEqual(register_args[0][0][1],37 self.argument.add_to_call_parameters)38 def test_add_to_call_parameters_no_file(self):39 parsed_args = mock.Mock()40 # Make the value a JSON string41 parsed_args.cli_input_json = self.input_json42 call_parameters = {}43 self.argument.add_to_call_parameters(44 service_operation=None, call_parameters=call_parameters,45 parsed_args=parsed_args, parsed_globals=None46 )47 self.assertEqual(call_parameters, {'A': 'foo', 'B': 'bar'})48 def test_add_to_call_parameters_with_file(self):49 parsed_args = mock.Mock()50 # Make the value a file with JSON located inside.51 parsed_args.cli_input_json = 'file://' + self.temp_file52 call_parameters = {}53 self.argument.add_to_call_parameters(54 service_operation=None, call_parameters=call_parameters,55 parsed_args=parsed_args, parsed_globals=None56 )57 self.assertEqual(call_parameters, {'A': 'foo', 'B': 'bar'})58 def test_add_to_call_parameters_bad_json(self):59 parsed_args = mock.Mock()60 # Create a bad JSON input61 parsed_args.cli_input_json = self.input_json + ','62 call_parameters = {}63 with self.assertRaises(ParamError):64 self.argument.add_to_call_parameters(65 service_operation=None, call_parameters=call_parameters,66 parsed_args=parsed_args, parsed_globals=None67 )68 def test_add_to_call_parameters_no_clobber(self):69 parsed_args = mock.Mock()70 parsed_args.cli_input_json = self.input_json71 # The value for ``A`` should not be clobbered by the input JSON72 call_parameters = {'A': 'baz'}73 self.argument.add_to_call_parameters(74 service_operation=None, call_parameters=call_parameters,75 parsed_args=parsed_args, parsed_globals=None76 )77 self.assertEqual(call_parameters, {'A': 'baz', 'B': 'bar'})78 def test_no_add_to_call_parameters(self):79 parsed_args = mock.Mock()80 parsed_args.cli_input_json = None81 call_parameters = {'A': 'baz'}82 self.argument.add_to_call_parameters(83 service_operation=None, call_parameters=call_parameters,84 parsed_args=parsed_args, parsed_globals=None85 )86 # Nothing should have been added to the call parameters because87 # ``cli_input_json`` is not in the ``parsed_args``...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful