Best Python code snippet using localstack_python
tags.py
Source:tags.py
...5idents=[]6for i in cli:7 for j in iden:8 idents=idents+[i+'-'+j]9res=rds.list_tags_for_resource(ResourceName="arn:aws:rds:us-east-1:127246258661:db:tegna-sandbox")10for i in range(len(res)):11 print(res[i]['Key']," ---> ",res[i]["Value"])12des=rds.describe_db_instances()13des=rds.describe_db_instances(DBInstanceIdentifier='tegna-sandbox')14des["DBInstances"][0]['DBInstanceArn']15des["DBInstances"][0]['DBInstanceIdentifier']16import boto3 17 ...: rds=boto3.client("rds") 18 ...: des=rds.describe_db_instances() 19 ...: for i in range(len(des["DBInstances"])): 20 ...: if des["DBInstances"][i]["DBInstanceIdentifier"] in idents: 21 ...: print(des["DBInstances"][i]['DBInstanceIdentifier'])22 ...: arn=des["DBInstances"][i]['DBInstanceArn'] 23 ...: res=rds.list_tags_for_resource(ResourceName=arn) 24 ...: for j in range(len(res)): 25 ...: print(res[j]['Key']," ---> ",res[j]["Value"])26 for i in range(len(des["DBInstances"])): 27 ...: if des["DBInstances"][i]["DBInstanceIdentifier"] in idents: 28 ...: print(des["DBInstances"][i]["DBInstanceIdentifier"],"-"*20) 29 ...: metadata=des["DBInstances"][i]["DBInstanceIdentifier"].split('-')30 ...: print(metadata) 31 ...: arn=des["DBInstances"][i]['DBInstanceArn'] 32 ...: res=rds.list_tags_for_resource(ResourceName=arn)33 ...: for j in range(len(res["TagList"])): 34 ...: print(res["TagList"][j]['Key']," ---> ",res["TagList"][j]["Value"])35 ...: time.sleep(2)36response = client.add_tags_to_resource(ResourceName='string',Tags=[{'Key': 'string','Value': 'string'},])37des=rds.describe_db_instances()38for i in range(len(des["DBInstances"])):39 fy=des["DBInstances"][i]["DBInstanceIdentifier"]40 if fy in idents:41 print("-"*30,fy,"-"*30)42 metadata=fy.split('-')43 arn=des["DBInstances"][i]['DBInstanceArn']44 response = rds.add_tags_to_resource(ResourceName=arn,Tags=[{'Key': 'Name','Value':fy},{'Key': 'client','Value':metadata[0]},{'Key': 'env','Value':metadata[1]}])45 res=rds.list_tags_for_resource(ResourceName=arn)46 for j in range(len(res["TagList"])):47 print("{0:>15} ---> {1:<15}".format(res["TagList"][j]['Key'],res["TagList"][j]["Value"]))48 time.sleep(2) 49if fy in idents:50 print(fy,"-"*20)51 metadata=fy.split('-')52 print(metadata)53 arn='arn:aws:rds:us-east-1:127246258661:db:cmg-sandbox'54 res=rds.list_tags_for_resource(ResourceName=arn)55 response = rds.add_tags_to_resource(ResourceName=arn,Tags=[{'Key': 'Name','Value':fy}])56[{'Key': 'system_type', 'Value': 'postgres'},57 {'Key': 'lifespan', 'Value': '1time'},58 {'Key': 'client', 'Value': 'sps'},59 {'Key': 'workload-type', 'Value': 'lowerdb'},60 {'Key': 'env', 'Value': 'sandbox'},61 {'Key': 'Name', 'Value': 'sps-sandbox'}]62[{'Key': 'system_type', 'Value': 'postgres'},63 {'Key': 'lifespan', 'Value': '1time'},64 {'Key': 'client', 'Value': 'sps'},65 {'Key': 'workload-type', 'Value': 'lowerdb'},66 {'Key': 'env', 'Value': 'sandbox'},67 {'Key': 'Name', 'Value': 'sps-sandbox'}]68[{'Key': 'system_type', 'Value': 'postgres'},69 {'Key': 'lifespan', 'Value': '1time'},70 {'Key': 'client', 'Value': 'sps'},71 {'Key': 'workload-type', 'Value': 'qa'},72 {'Key': 'env', 'Value': 'qa'},73 {'Key': 'Name', 'Value': 'sps-qa'}]74[{'Key': 'system_type', 'Value': 'postgres'},75 {'Key': 'lifespan', 'Value': '1time'},76 {'Key': 'client', 'Value': 'sps'},77 {'Key': 'workload-type', 'Value': 'lowerdb'},78 {'Key': 'env', 'Value': 'sandbox'},79 {'Key': 'Name', 'Value': 'sps-sandbox'}]80[{'Key': 'system_type', 'Value': 'postgres'},81 {'Key': 'lifespan', 'Value': '1time'},82 {'Key': 'client', 'Value': 'sps'},83 {'Key': 'workload-type', 'Value': 'stage'},84 {'Key': 'env', 'Value': 'stage'},85 {'Key': 'Name', 'Value': 'sps-stage'}]86[{'Key': 'system_type', 'Value': 'postgres'},87 {'Key': 'lifespan', 'Value': '1time'},88 {'Key': 'client', 'Value': 'sps'},89 {'Key': 'workload-type', 'Value': 'lowerdb'},90 {'Key': 'env', 'Value': 'sandbox'},91 {'Key': 'Name', 'Value': 'sps-sandbox'}]92[{'Key': 'system_type', 'Value': 'postgres'},93 {'Key': 'lifespan', 'Value': '1time'},94 {'Key': 'client', 'Value': 'sps'},95 {'Key': 'workload-type', 'Value': 'lowerdb'},96 {'Key': 'env', 'Value': 'sandbox'},97 {'Key': 'Name', 'Value': 'sps-sandbox'}]98 import time99 ...: for i in envr:100 ...: print('*'*25,i,'*'*25)101 ...: des=rds.describe_db_instances(DBInstanceIdentifier='sps-'+i)102 ...: arn=des['DBInstances'][0]['DBInstanceArn']103 ...: pprint.pprint(rds.list_tags_for_resource(ResourceName=arn)['TagList'][-2:])104 ...: print()105 ...: res=rds.add_tags_to_resource(ResourceName=arn,Tags=[{'Key': 'Name','Value':'sps-'+i},{'Key': 'client','Value':'s106 ...: ps'},{'Key': 'env','Value':i}])107 ...: #print(res)108 ...: pprint.pprint(rds.list_tags_for_resource(ResourceName=arn)['TagList'])109 ...: ...
test_tagging.py
Source:test_tagging.py
2from localstack.utils.tagging import TaggingService3class TestTaggingService(unittest.TestCase):4 svc = TaggingService()5 def test_list_empty(self):6 result = self.svc.list_tags_for_resource("test")7 self.assertEqual({"Tags": []}, result)8 def test_create_tag(self):9 tags = [{"Key": "key_key", "Value": "value_value"}]10 self.svc.tag_resource("arn", tags)11 actual = self.svc.list_tags_for_resource("arn")12 expected = {"Tags": [{"Key": "key_key", "Value": "value_value"}]}13 self.assertDictEqual(expected, actual)14 def test_delete_tag(self):15 tags = [{"Key": "key_key", "Value": "value_value"}]16 self.svc.tag_resource("arn", tags)17 self.svc.untag_resource("arn", ["key_key"])18 result = self.svc.list_tags_for_resource("arn")19 self.assertEqual({"Tags": []}, result)20 def test_list_empty_delete(self):21 self.svc.untag_resource("arn", ["key_key"])22 result = self.svc.list_tags_for_resource("arn")...
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!!