Best Python code snippet using localstack_python
compute.py
Source:compute.py  
...26        :rtype: json27        .. note:: http://boto3.readthedocs.io/en/latest/reference/services/ec2.html28    """29    30    return glob.get_inventory(31        ownerId = oId,32        aws_service = "ec2", 33        aws_region = "all", 34        function_name = "describe_instances", 35        key_get = "Reservations",36        pagination = True37    )38def get_interfaces_inventory(oId):39    """40        Returns network interfaces detailed inventory41        :param oId: ownerId (AWS account)42        :type oId: string43        :return: network interfaces inventory44        :rtype: json45    """46    return glob.get_inventory(47        ownerId = oId,48        aws_service = "ec2", 49        aws_region = "all", 50        function_name = "describe_network_interfaces", 51        key_get = "NetworkInterfaces"52    )53def get_vpc_inventory(oId):54    """55        Returns VPC detailed inventory56        :param oId: ownerId (AWS account)57        :type oId: string58        :return: VPC inventory59        :rtype: json60    """61    return glob.get_inventory(62        ownerId = oId,63        aws_service = "ec2", 64        aws_region = "all", 65        function_name = "describe_vpcs", 66        key_get = "Vpcs"67    )68def get_subnet_inventory(oId):69    """70        Returns VPC subnets inventory71        :param oId: ownerId (AWS account)72        :type oId: string73        :return: VPC subnets inventory74        :rtype: json75    """76    return glob.get_inventory(77        ownerId = oId,78        aws_service = "ec2", 79        aws_region = "all", 80        function_name = "describe_subnets", 81        key_get = "Subnets"82    )83def get_ebs_inventory(oId):84    """85        Returns EBS detailed inventory86        :param oId: ownerId (AWS account)87        :type oId: string88        :return: EBS inventory89        :rtype: json90    """91    return glob.get_inventory(92        ownerId = oId,93        aws_service = "ec2", 94        aws_region = "all", 95        function_name = "describe_volumes", 96        key_get = "Volumes",97        pagination = True98    )99def get_eips_inventory(oId):100    """101        Returns Elastic IPs inventory102        :param oId: ownerId (AWS account)103        :type oId: string104        :return: Elastic IPs inventory105        :rtype: json106    """107    return glob.get_inventory(108        ownerId = oId,109        aws_service = "ec2", 110        aws_region = "all", 111        function_name = "describe_addresses", 112        key_get = "Addresses"113    )114def get_egpus_inventory(oId):115    """116        Returns Elastic GPUs inventory117        :param oId: ownerId (AWS account)118        :type oId: string119        :return: Elastic GPUs inventory120        :rtype: json121    """122    return glob.get_inventory(123        ownerId = oId,124        aws_service = "ec2", 125        aws_region = "all", 126        function_name = "describe_elastic_gpus", 127        key_get = "ElasticGpuSet"128    )129def get_sg_inventory(oId):130    """131        Returns Security Groups inventory132        :param oId: ownerId (AWS account)133        :type oId: string134        :return: Security Groups inventory135        :rtype: json136    """137    return glob.get_inventory(138        ownerId = oId,139        aws_service = "ec2", 140        aws_region = "all", 141        function_name = "describe_security_groups", 142        key_get = "SecurityGroups",143        pagination = True144    )145def get_igw_inventory(oId):146    """147        Returns Internet Gateways inventory148        :param oId: ownerId (AWS account)149        :type oId: string150        :return: Internet Gateways inventory151        :rtype: json152    """153    return glob.get_inventory(154        ownerId = oId,155        aws_service = "ec2", 156        aws_region = "all", 157        function_name = "describe_internet_gateways", 158        key_get = "InternetGateways"159    )160def get_ngw_inventory(oId):161    """162        Returns Nat Gateways inventory163        :param oId: ownerId (AWS account)164        :type oId: string165        :return: Nat Gateways inventory166        :rtype: json167    """168    return glob.get_inventory(169        ownerId = oId,170        aws_service = "ec2", 171        aws_region = "all", 172        function_name = "describe_nat_gateways", 173        key_get = "NatGateways"174    )175#  ------------------------------------------------------------------------176#177#    Elastic Beanstalk 178#179#  ------------------------------------------------------------------------180def get_elasticbeanstalk_environments_inventory(oId):181    """182        Returns Elastic Beanstalk detailed inventory183        :param oId: ownerId (AWS account)184        :type oId: string185        :return: Elastic Beanstalk inventory (environments)186        :rtype: json187        .. note:: http://boto3.readthedocs.io/en/latest/reference/services/elasticbeanstalk.html188    """189    return glob.get_inventory(190        ownerId = oId,191        aws_service = "elasticbeanstalk", 192        aws_region = "all", 193        function_name = "describe_environments", 194        key_get = "Environments"195    )196def get_elasticbeanstalk_applications_inventory(oId):197    """198        Returns Elastic Beanstalk detailed inventory199        :param oId: ownerId (AWS account)200        :type oId: string201        :return: Elastic Beanstalk inventory (applications)202        :rtype: json203    """204    return glob.get_inventory(205        ownerId = oId,206        aws_service = "elasticbeanstalk", 207        aws_region = "all", 208        function_name = "describe_applications", 209        key_get = "Applications"210    )211#  ------------------------------------------------------------------------212#213#    EC2 Container Service (ECS)214#215#  ------------------------------------------------------------------------216def get_ecs_inventory(oId):217    """218        Returns ECS detailed inventory219        :param oId: ownerId (AWS account)220        :type oId: string221        :return: ECS inventory222        :rtype: json223        .. note:: http://boto3.readthedocs.io/en/latest/reference/services/ecs.html224    """225    return glob.get_inventory(226        ownerId = oId,227        aws_service = "ecs", 228        aws_region = "all", 229        function_name = "describe_clusters", 230        key_get = "clusters"231    )232    #detail_function = "list_container_instances",233    #join_key = "clusterName", 234    #detail_join_key = "cluster", 235    #detail_get_key = ""236    237def get_ecs_services_inventory(oId):238    """239        Returns ECS tasks inventory  NOT WORKING YET240        :param oId: ownerId (AWS account)241        :type oId: string242        :return: ECS tasks inventory243        :rtype: json244    """245    return glob.get_inventory(246        ownerId = oId,247        aws_service = "ecs", 248        aws_region = "all", 249        function_name = "list_services", 250        key_get = "serviceArns",251        detail_function = "describe_services", 252        join_key = "", 253        detail_join_key = "services", 254        detail_get_key = "services",255        pagination = True,256        pagination_detail = True257    )258    259def get_ecs_tasks_inventory(oId):260    """261        Returns ECS tasks inventory262        :param oId: ownerId (AWS account)263        :type oId: string264        :return: ECS tasks inventory265        :rtype: json266    """267    return glob.get_inventory(268        ownerId = oId,269        aws_service = "ecs", 270        aws_region = "all", 271        function_name = "list_task_definitions", 272        key_get = "taskDefinitionArns",273        detail_function = "describe_task_definition", 274        join_key = "taskDefinitionArn", 275        detail_join_key = "taskDefinition", 276        detail_get_key = "taskDefinition",277        pagination = True,278        pagination_detail = True279    )280#  ------------------------------------------------------------------------281#282#    EKS283#284#  ------------------------------------------------------------------------285def get_eks_inventory(oId):286    """287        Returns eks inventory (if the region is avalaible)288        :param oId: ownerId (AWS account)289        :type oId: string290        :return: eks inventory291        :rtype: json292        .. note:: http://boto3.readthedocs.io/en/latest/reference/services/eks.html293    """294    inv = glob.get_inventory(295        ownerId = oId,296        aws_service = "eks", 297        aws_region = "all", 298        function_name = "list_clusters", 299        key_get = "clusters",300        detail_function = "describe_cluster", 301        join_key = "", 302        detail_join_key = "name", 303        detail_get_key = "cluster"304    )305    return inv306#  ------------------------------------------------------------------------307#308#    Autoscaling309#310#  ------------------------------------------------------------------------311def get_autoscaling_inventory(oId):312    """313        Returns eks inventory (if the region is avalaible)314        :param oId: ownerId (AWS account)315        :type oId: string316        :return: eks inventory317        :rtype: json318        .. note:: https://boto3.readthedocs.io/en/latest/reference/services/autoscaling.html319    """320    autoscaling_inventory = {}321    autoscaling_inventory['autoscaling-groups'] = glob.get_inventory(322        ownerId = oId,323        aws_service = "autoscaling", 324        aws_region = "all", 325        function_name = "describe_auto_scaling_groups", 326        key_get = "AutoScalingGroups",327        pagination = True328    )329    autoscaling_inventory['autoscaling-launch-configuration'] = glob.get_inventory(330        ownerId = oId,331        aws_service = "autoscaling", 332        aws_region = "all", 333        function_name = "describe_launch_configurations", 334        key_get = "LaunchConfigurations",335        pagination = True336    )337    autoscaling_inventory['autoscaling-plans'] = glob.get_inventory(338        ownerId = oId,339        aws_service = "autoscaling-plans", 340        aws_region = "all", 341        function_name = "describe_scaling_plans", 342        key_get = "ScalingPlans"343    )344    return autoscaling_inventory345#  ------------------------------------------------------------------------346#347#    Lambda348#349#  ------------------------------------------------------------------------350def get_lambda_inventory(oId):351    """352        Returns lambda inventory.353        :param oId: ownerId (AWS account)354        :type oId: string355        :return: lambda inventory356        :rtype: json357        .. note:: http://boto3.readthedocs.io/en/latest/reference/services/lambda.html358    """359    return glob.get_inventory(360        ownerId = oId,361        aws_service = "lambda", 362        aws_region = "all", 363        function_name = "list_functions", 364        key_get = "Functions",365        pagination = True366    )367#  ------------------------------------------------------------------------368#369#    Batch370#371#  ------------------------------------------------------------------------372def get_batch_inventory(oId):373    """374        Returns batch jobs inventory.375        :param oId: ownerId (AWS account)376        :type oId: string377        :return: batch inventory378        :rtype: json379        .. note:: http://boto3.readthedocs.io/en/latest/reference/services/batch.html380    """381    inventory = {}382    inventory['job-definitions'] = glob.get_inventory(383        ownerId = oId,384        aws_service = "batch", 385        aws_region = "all", 386        function_name = "describe_job_definitions", 387        key_get = "jobDefinitions"388    )389    inventory['job-queues'] = glob.get_inventory(390        ownerId = oId,391        aws_service = "batch", 392        aws_region = "all", 393        function_name = "describe_job_queues", 394        key_get = "jobQueues"395    )396    inventory['compute-environements'] = glob.get_inventory(397        ownerId = oId,398        aws_service = "batch", 399        aws_region = "all", 400        function_name = "describe_compute_environments", 401        key_get = "computeEnvironments"402    )403    return inventory404#  ------------------------------------------------------------------------405#406#    Lightsail407#408#  ------------------------------------------------------------------------409def get_lightsail_inventory(oId):410    """411        Returns lightsail inventory, with loadbalancers and IPs412        :param oId: ownerId (AWS account)413        :type oId: string414        :return: lightsail inventory415        :rtype: json416        .. note:: http://boto3.readthedocs.io/en/latest/reference/services/lightsail.html417    """418    lightsail_inventory = {}419    lightsail_inventory['lightsail-instances'] = glob.get_inventory(420        ownerId = oId,421        aws_service = "lightsail", 422        aws_region = "all", 423        function_name = "get_instances", 424        key_get = "instances",425        pagination = True426    )427    lightsail_inventory['lightsail-loadbalancers'] = glob.get_inventory(428        ownerId = oId,429        aws_service = "lightsail", 430        aws_region = "all", 431        function_name = "get_load_balancers", 432        key_get = "loadBalancers"433    )434    lightsail_inventory['lightsail-ip'] = glob.get_inventory(435        ownerId = oId,436        aws_service = "lightsail", 437        aws_region = "all", 438        function_name = "get_static_ips", 439        key_get = "staticIps"440    )441    lightsail_inventory['lightsail-disks'] = glob.get_inventory(442        ownerId = oId,443        aws_service = "lightsail", 444        aws_region = "all", 445        function_name = "get_disks", 446        key_get = "disks"447    )    448    return lightsail_inventory449#450# Hey, doc: we're in a module!451#452if (__name__ == '__main__'):...api_wrapper_test.py
Source:api_wrapper_test.py  
...9    def test_raises_not_logged_in_exception(self):10        api = ApiWrapper(get_fake_conf())11        api.set_position(*(42, 42, 0))12        request = api.create_request()13        request.get_inventory(test='awesome')14        with self.assertRaises(NotLoggedInException):15            request.call()16    #def test_api_call_with_no_requests_set(self):17    #    request = ApiWrapper(get_fake_conf()).create_request()18    #    with self.assertRaises(EmptySubrequestChainException):19    #        request.call()20    def test_api_wrong_request(self):21        request = ApiWrapper(get_fake_conf()).create_request()22        with self.assertRaises(AttributeError):23            request.wrong_request()24    def test_raises_no_player_position_set_exception(self):25        request = ApiWrapper(get_fake_conf()).create_request()26        request.get_inventory(test='awesome')27        with self.assertRaises(NoPlayerPositionSetException):28            request.call()29    @patch('pokemongo_bot.api_wrapper.sleep')30    def test_api_server_is_unreachable_raises_server_busy_or_offline_exception(self, sleep):31        sleep.return_value = True # we don't need to really sleep32        request = FakeApi().create_request('Wrong Value')33        request.get_inventory()34        # we expect an exception because the "server" isn't returning a valid response35        with self.assertRaises(ServerBusyOrOfflineException):36            request.call()37    def test_mocked_call(self):38        request = FakeApi().create_request(True)39        request.is_response_valid = MagicMock(return_value=True)40        request.get_inventory(test='awesome')41        result = request.call()42        self.assertTrue(result)43    def test_return_value_is_not_valid(self):44        api = FakeApi()45        def returnRequest(ret_value):46            request = api.create_request(ret_value)47            request.get_inventory(test='awesome')48            return request49        wrong_return_values = [50            None,51            False,52            {},53            {'responses': {}},54            {'status_code': 0},55            {'responses': {'GET_INVENTORY_OR_NOT': {}}, 'status_code': 0}56        ]57        for wrong in wrong_return_values:58            request = returnRequest(wrong)59            request_callers = request._pop_request_callers() # we can pop because we do no call60            is_valid = request.is_response_valid(wrong, request_callers)61            self.assertFalse(is_valid, 'return value {} is valid somehow ?'.format(wrong))62    def test_return_value_is_valid(self):63        request = FakeApi().create_request() # we set the return value below64        request.get_inventory(test='awesome')65        request_caller = request.request_callers[0] # only one request66        self.assertEqual(request_caller.upper(), 'GET_INVENTORY')67        good_return_value = {'responses': {request_caller.upper(): {}}, 'status_code': 0}68        request._call.return_value = good_return_value69        result = request.call()70        self.assertEqual(result, good_return_value)71        self.assertEqual(len(request.request_callers), 0, 'request_callers must be empty')72    def test_multiple_requests(self):73        request = FakeApi().create_request()74        request.get_inventory(test='awesome')75        request.fort_details()76        good_return_value = {'responses': {'GET_INVENTORY': {}, 'FORT_DETAILS': {}}, 'status_code': 0}77        request._call.return_value = good_return_value78        result = request.call()79        self.assertEqual(result, good_return_value)80    @timeout(1)81    def test_api_call_throttle_should_pass(self):82        request = FakeApi().create_request()83        request.is_response_valid = MagicMock(return_value=True)84        request.requests_per_seconds = 585        for i in range(request.requests_per_seconds):86            request.call()87    @timeout(1) # expects a timeout88    def test_api_call_throttle_should_fail(self):89        request = FakeApi().create_request()90        request.is_response_valid = MagicMock(return_value=True)91        request.requests_per_seconds = 592        with self.assertRaises(TimeoutError):93            for i in range(request.requests_per_seconds * 2):94                request.call()95    @patch('pokemongo_bot.api_wrapper.ApiRequest.is_response_valid')96    def test_api_direct_call(self, mock_method):97        mock_method.return_value = True98        result = FakeApi().get_inventory()...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
