How to use endpoint_prefix_index method in localstack

Best Python code snippet using localstack_python

spec.py

Source:spec.py Github

copy

Full Screen

...86 for operation in operations:87 result[operation].append(service.service_name)88 return dict(result)89 @cached_property90 def endpoint_prefix_index(self) -> Dict[str, List[ServiceName]]:91 result = defaultdict(list)92 for service in self._services.values():93 result[service.endpoint_prefix].append(service.service_name)94 return dict(result)95 @cached_property96 def _services(self) -> Dict[ServiceName, ServiceModel]:97 return {service.service_name: service for service in list_services()}98class ServiceCatalog:99 index: ServiceCatalogIndex100 def __init__(self, index: ServiceCatalogIndex = None):101 self.index = index or LazyServiceCatalogIndex()102 @lru_cache(maxsize=512)103 def get(self, name: ServiceName) -> Optional[ServiceModel]:104 return load_service(name)105 @property106 def service_names(self) -> List[ServiceName]:107 return self.index.service_names108 @property109 def target_prefix_index(self) -> Dict[str, List[ServiceName]]:110 return self.index.target_prefix_index111 @property112 def signing_name_index(self) -> Dict[str, List[ServiceName]]:113 return self.index.signing_name_index114 @property115 def operations_index(self) -> Dict[str, List[ServiceName]]:116 return self.index.operations_index117 @property118 def endpoint_prefix_index(self) -> Dict[str, List[ServiceName]]:119 return self.index.endpoint_prefix_index120 def by_target_prefix(self, target_prefix: str) -> List[ServiceName]:121 return self.target_prefix_index.get(target_prefix, [])122 def by_signing_name(self, signing_name: str) -> List[ServiceName]:123 return self.signing_name_index.get(signing_name, [])124 def by_operation(self, operation_name: str) -> List[ServiceName]:125 return self.operations_index.get(operation_name, [])126def build_service_index_cache(file_path: str) -> ServiceCatalogIndex:127 """128 Creates a new ServiceCatalogIndex and stores it into the given file_path.129 :param file_path: the path to pickle to130 :return: the created ServiceCatalogIndex131 """132 return save_service_index_cache(LazyServiceCatalogIndex(), file_path)...

Full Screen

Full Screen

test_spec.py

Source:test_spec.py Github

copy

Full Screen

1from botocore.model import ServiceModel, StringShape2from localstack.aws.spec import (3 LazyServiceCatalogIndex,4 PatchingLoader,5 load_service_index_cache,6 save_service_index_cache,7)8def test_pickled_index_equals_lazy_index(tmp_path):9 file_path = tmp_path / "index-cache.pickle"10 lazy_index = LazyServiceCatalogIndex()11 save_service_index_cache(lazy_index, str(file_path))12 cached_index = load_service_index_cache(str(file_path))13 assert cached_index.service_names == lazy_index.service_names14 assert cached_index.target_prefix_index == lazy_index.target_prefix_index15 assert cached_index.signing_name_index == lazy_index.signing_name_index16 assert cached_index.operations_index == lazy_index.operations_index17 assert cached_index.endpoint_prefix_index == lazy_index.endpoint_prefix_index18def test_patching_loaders():19 # first test that specs remain intact20 loader = PatchingLoader({})21 description = loader.load_service_model("s3", "service-2")22 model = ServiceModel(description, "s3")23 shape = model.shape_for("NoSuchBucket")24 # by default, the s3 error shapes have no members, but AWS will actually return additional attributes25 assert not shape.members26 assert shape.metadata.get("exception")27 # now try it with a patch28 loader = PatchingLoader(29 {30 "s3/2006-03-01/service-2": [31 {32 "op": "add",33 "path": "/shapes/NoSuchBucket/members/BucketName",34 "value": {"shape": "BucketName"},35 },36 {37 "op": "add",38 "path": "/shapes/NoSuchBucket/error",39 "value": {"httpStatusCode": 404},40 },41 ],42 }43 )44 description = loader.load_service_model("s3", "service-2", "2006-03-01")45 model = ServiceModel(description, "s3")46 shape = model.shape_for("NoSuchBucket")47 assert "BucketName" in shape.members48 assert isinstance(shape.members["BucketName"], StringShape)49 assert shape.metadata["error"]["httpStatusCode"] == 404...

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