How to use update_usage method in localstack

Best Python code snippet using localstack_python

get_dependencies_test.py

Source:get_dependencies_test.py Github

copy

Full Screen

...19 self.assertNotEqual(unit_a, unit_d)20 self.assertNotEqual(unit_c, unit_d)21 def test_make_public(self):22 unit = AvailableInclude(hdr="hdr", used=IncludeUsage.NONE)23 unit.update_usage(IncludeUsage.PUBLIC)24 self.assertEqual(unit.used, IncludeUsage.PUBLIC)25 def test_make_private(self):26 unit = AvailableInclude(hdr="hdr", used=IncludeUsage.NONE)27 unit.update_usage(IncludeUsage.PRIVATE)28 self.assertEqual(unit.used, IncludeUsage.PRIVATE)29 def test_make_public_and_private(self):30 unit = AvailableInclude(hdr="hdr", used=IncludeUsage.NONE)31 unit.update_usage(IncludeUsage.PUBLIC_AND_PRIVATE)32 self.assertEqual(unit.used, IncludeUsage.PUBLIC_AND_PRIVATE)33 def test_add_private_to_public(self):34 unit = AvailableInclude(hdr="hdr", used=IncludeUsage.PUBLIC)35 unit.update_usage(IncludeUsage.PRIVATE)36 self.assertEqual(unit.used, IncludeUsage.PUBLIC_AND_PRIVATE)37 def test_add_public_to_private(self):38 unit = AvailableInclude(hdr="hdr", used=IncludeUsage.PRIVATE)39 unit.update_usage(IncludeUsage.PUBLIC)40 self.assertEqual(unit.used, IncludeUsage.PUBLIC_AND_PRIVATE)41 def test_public_and_private_state_is_stable(self):42 unit = AvailableInclude(hdr="hdr", used=IncludeUsage.PUBLIC_AND_PRIVATE)43 unit.update_usage(IncludeUsage.PUBLIC)44 self.assertEqual(unit.used, IncludeUsage.PUBLIC_AND_PRIVATE)45 unit.update_usage(IncludeUsage.PRIVATE)46 self.assertEqual(unit.used, IncludeUsage.PUBLIC_AND_PRIVATE)47 unit.update_usage(IncludeUsage.PUBLIC_AND_PRIVATE)48 self.assertEqual(unit.used, IncludeUsage.PUBLIC_AND_PRIVATE)49 def test_no_usage_resetting(self):50 unit = AvailableInclude(hdr="hdr")51 with self.assertRaises(Exception):52 unit.update_usage(IncludeUsage.NONE)53class TestGetAvailableDependencies(unittest.TestCase):54 def test_load_full_file(self):55 deps = get_available_dependencies(Path("src/analyze_includes/test/data/deps_info_full.json"))56 self.assertEqual(len(deps.private), 2)57 self.assertEqual(len(deps.public), 2)58 self.assertEqual(deps.private[0].name, "//private/dep:foo")59 self.assertEqual(60 deps.private[0].hdrs, [AvailableInclude("private/dep/foo_a.h"), AvailableInclude("private/dep/foo_b.h")]61 )62 self.assertEqual(deps.private[1].name, "//private/dep:bar")63 self.assertEqual(64 deps.private[1].hdrs, [AvailableInclude("private/dep/bar_a.h"), AvailableInclude("private/dep/bar_b.h")]65 )66 self.assertEqual(deps.public[0].name, "//public/dep:foo")...

Full Screen

Full Screen

lambda_function.py

Source:lambda_function.py Github

copy

Full Screen

2import urllib.parse3import boto34s3 = boto3.client("s3")5dynamodb = boto3.client("dynamodb")6def update_usage(user_id, size_change):7 response = dynamodb.update_item(8 TableName="Users",9 Key={10 "UserId": {"S": user_id},11 },12 UpdateExpression="ADD Size :size",13 ExpressionAttributeValues={":size": {"N": size_change}},14 )15def save_object_size(object_key, size):16 user_id = object_key.split("/")[0]17 response = dynamodb.put_item(18 TableName="Files",19 Item={20 "UserId": {"S": user_id},21 "FileName": {"S": object_key},22 "Size": {"N": str(size)},23 },24 )25 update_usage(user_id, str(size))26def remove_object_size(object_key):27 user_id = object_key.split("/")[0]28 response = dynamodb.delete_item(29 TableName="Files",30 Key={"UserId": {"S": user_id}, "FileName": {"S": object_key}},31 ReturnValues="ALL_OLD",32 )33 size = int(response["Attributes"]["Size"]["N"])34 update_usage(user_id, str(0 - size))35def lambda_handler(event, context):36 # Uncomment the line below to debug the event received37 # print("Received event: " + json.dumps(event, indent=2))38 for record in event["Records"]:39 event = record["eventName"]40 bucket = record["s3"]["bucket"]["name"]41 key = urllib.parse.unquote_plus(record["s3"]["object"]["key"], encoding="utf-8")42 size = record["s3"]["object"].get("size", None)43 print(44 f"Got a {event} event for object '{key}' in bucket '{bucket}'. Reported size is {size or 'unknown'}"45 )46 if event == "ObjectCreated:Put":47 save_object_size(key, size)48 elif event == "ObjectRemoved:Delete":...

Full Screen

Full Screen

seek_support.py

Source:seek_support.py Github

copy

Full Screen

...6 for item in single_support:7 supid = item[0]8 usage = item[3]9 new_usage = usage + 110 update_usage = support.Support().update_usage(supid, new_usage)11 if update_usage:12 return True, "Usage Updated Successfully!"13 else:...

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