Best Python code snippet using localstack_python
prototype.py
Source:prototype.py
...63 self.transformers = []64 self.observed_state = {}65 self.recorded_state = self._load_state()66 self.transform = TransformerUtility67 def add_transformers_list(68 self, transformer_list: list[Transformer], priority: Optional[int] = 069 ):70 for transformer in transformer_list:71 self.transformers.append((transformer, priority)) # TODO72 def add_transformer(self, transformer: Transformer, *, priority: Optional[int] = 0):73 if isinstance(transformer, list):74 self.add_transformers_list(transformer, priority)75 else:76 self.transformers.append((transformer, priority or 0))77 def _persist_state(self) -> None:78 if self.update:79 Path(self.file_path).touch()80 with open(self.file_path, "r+") as fd:81 try:82 content = fd.read()83 fd.seek(0)84 fd.truncate()85 full_state = json.loads(content or "{}")86 recorded = {87 "recorded-date": datetime.now().strftime("%d-%m-%Y, %H:%M:%S"),88 "recorded-content": self.observed_state,...
test_cloudformation_iam.py
Source:test_cloudformation_iam.py
...78 get_iam_user = iam_client.get_user(UserName=user_name)79 snapshot.match("get_iam_user", get_iam_user)80@pytest.mark.aws_validated81def test_iam_user_access_key(deploy_cfn_template, iam_client, snapshot):82 snapshot.add_transformers_list(83 [84 snapshot.transform.key_value("AccessKeyId", "key-id"),85 snapshot.transform.key_value("UserName", "user-name"),86 snapshot.transform.key_value("SecretAccessKey", "secret-access-key"),87 ]88 )89 user_name = f"user-{short_uid()}"90 stack = deploy_cfn_template(91 template_path=os.path.join(os.path.dirname(__file__), "../templates/iam_access_key.yaml"),92 parameters={"UserName": user_name},93 )94 snapshot.match("key_outputs", stack.outputs)95 keys = iam_client.list_access_keys(UserName=user_name)["AccessKeyMetadata"]96 snapshot.match("access_key", keys[0])97@pytest.mark.aws_validated98@pytest.mark.skip_snapshot_verify(99 paths=[100 "$..Policy.Description",101 "$..Policy.IsAttachable",102 "$..Policy.PermissionsBoundaryUsageCount",103 "$..Policy.Tags",104 ]105)106def test_managed_policy_with_empty_resource(iam_client, deploy_cfn_template, snapshot):107 snapshot.add_transformer(108 snapshot.transform.iam_api(),109 )110 snapshot.add_transformers_list(111 [snapshot.transform.resource_name(), snapshot.transform.key_value("PolicyId", "policy-id")]112 )113 parameters = {114 "tableName": f"table-{short_uid()}",115 "policyName": f"managed-policy-{short_uid()}",116 }117 template_path = os.path.join(os.path.dirname(__file__), "../templates/dynamodb_iam.yaml")118 stack = deploy_cfn_template(template_path=template_path, parameters=parameters)119 snapshot.match("outputs", stack.outputs)120 policy_arn = stack.outputs["PolicyArn"]121 policy = iam_client.get_policy(PolicyArn=policy_arn)...
test_cloudformation_kinesis.py
Source:test_cloudformation_kinesis.py
...3@pytest.mark.aws_validated4@pytest.mark.skip_snapshot_verify(paths=["$..StreamDescription.StreamModeDetails"])5def test_stream_creation(kinesis_client, deploy_cfn_template, snapshot):6 snapshot.add_transformer(snapshot.transform.resource_name())7 snapshot.add_transformers_list(8 [9 snapshot.transform.key_value("StreamName", "stream-name"),10 snapshot.transform.key_value("ShardId", "shard-id", reference_replacement=False),11 snapshot.transform.key_value("EndingHashKey", "ending-hash-key"),12 snapshot.transform.key_value("StartingSequenceNumber", "sequence-number"),13 ]14 )15 template = json.dumps(16 {17 "Resources": {18 "TestStream": {19 "Type": "AWS::Kinesis::Stream",20 "Properties": {"ShardCount": 1},21 },...
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!!