Best Python code snippet using localstack_python
test_update.py
Source:test_update.py
1import pytest2import test_fixtures3from test_fixtures import context4from test_fixtures import log_groups5from test_fixtures import update_event6def test_update_no_existing(log_groups, update_event, context):7 return_value = log_groups.client.describe_log_groups.return_value8 log_groups.client.describe_log_groups.side_effect = [{'logGroups': []},test_fixtures.DESCRIBE_LOG_GROUPS]9 response = log_groups.handle(update_event,context)10 assert log_groups.client.create_log_group.called11 log_groups.client.put_retention_policy.assert_called_with(logGroupName=test_fixtures.LOG_GROUP_NAME, retentionInDays=30)12 assert log_groups.client.describe_subscription_filters.called13 assert not log_groups.client.delete_subscription_filter.called14 assert response == { 15 'PhysicalResourceId': test_fixtures.LOG_GROUP_NAME,16 'Data': { 'Arn': test_fixtures.FUNCTION_ARN }17 }18def test_update_retention(log_groups, update_event, context):19 update_event['ResourceProperties']['Retention'] = '7'20 response = log_groups.handle(update_event,context)21 assert not log_groups.client.create_log_group.called22 log_groups.client.put_retention_policy.assert_called_with(logGroupName=test_fixtures.LOG_GROUP_NAME, retentionInDays=7)23 assert log_groups.client.describe_subscription_filters.called24 assert not log_groups.client.delete_subscription_filter.called25 assert not log_groups.client.put_subscription_filter.called26 assert response == { 27 'PhysicalResourceId': test_fixtures.LOG_GROUP_NAME,28 'Data': { 'Arn': test_fixtures.FUNCTION_ARN }29 }30def test_update_new_subscription(log_groups, update_event, context):31 update_event['ResourceProperties']['Subscription'] = {32 'FilterName': 'Default',33 'FilterPattern': '',34 'DestinationArn': test_fixtures.SUBSCRIPTION_ARN35 }36 response = log_groups.handle(update_event,context)37 assert not log_groups.client.create_log_group.called38 log_groups.client.put_retention_policy.assert_called_with(logGroupName=test_fixtures.LOG_GROUP_NAME, retentionInDays=30)39 assert log_groups.client.describe_subscription_filters.called40 assert not log_groups.client.delete_subscription_filter.called41 assert log_groups.client.put_subscription_filter.called42 assert response == { 43 'PhysicalResourceId': test_fixtures.LOG_GROUP_NAME,44 'Data': { 'Arn': test_fixtures.FUNCTION_ARN }45 }46def test_update_existing_subscription(log_groups, update_event, context):47 update_event['ResourceProperties']['Subscription'] = {48 'FilterName': 'Default',49 'FilterPattern': '[filter]',50 'DestinationArn': test_fixtures.SUBSCRIPTION_ARN51 }52 log_groups.client.describe_subscription_filters.return_value = test_fixtures.DESCRIBE_SUBSCRIPTION_FILTERS53 response = log_groups.handle(update_event,context)54 assert not log_groups.client.create_log_group.called55 log_groups.client.put_retention_policy.assert_called_with(logGroupName=test_fixtures.LOG_GROUP_NAME, retentionInDays=30)56 assert log_groups.client.describe_subscription_filters.called57 assert log_groups.client.delete_subscription_filter.called58 assert log_groups.client.put_subscription_filter.called59 assert response == { 60 'PhysicalResourceId': test_fixtures.LOG_GROUP_NAME,61 'Data': { 'Arn': test_fixtures.FUNCTION_ARN }62 }63def test_update_existing_subscription_no_changes(log_groups, update_event, context):64 update_event['ResourceProperties']['Subscription'] = {65 'FilterName': 'Default',66 'FilterPattern': '',67 'DestinationArn': test_fixtures.SUBSCRIPTION_ARN68 }69 log_groups.client.describe_subscription_filters.return_value = test_fixtures.DESCRIBE_SUBSCRIPTION_FILTERS70 response = log_groups.handle(update_event,context)71 assert not log_groups.client.create_log_group.called72 log_groups.client.put_retention_policy.assert_called_with(logGroupName=test_fixtures.LOG_GROUP_NAME, retentionInDays=30)73 assert log_groups.client.describe_subscription_filters.called74 assert not log_groups.client.delete_subscription_filter.called75 assert not log_groups.client.put_subscription_filter.called76 assert response == { 77 'PhysicalResourceId': test_fixtures.LOG_GROUP_NAME,78 'Data': { 'Arn': test_fixtures.FUNCTION_ARN }...
updateLogs.py
Source:updateLogs.py
...35 )36 except:37 pass38 try:39 client.put_retention_policy(40 logGroupName=f"/aws/lambda/{ContentLambdaName}",41 retentionInDays=int(ContentLogsRetention)42 )43 client.put_retention_policy(44 logGroupName=f"/aws/lambda/{RecommendationsLambdaName}",45 retentionInDays=int(RecommendationsLogsRetention)46 )47 client.put_retention_policy(48 logGroupName=f"/aws/lambda/{EventsLambdaName}",49 retentionInDays=int(EventsLogsRetention)50 )51 except ClientError as e:52 responseData = {}53 responseData['Data'] = f"{e}"...
Retention_policy_change.py
Source:Retention_policy_change.py
...13 for logs in response['logGroups']:14 newlist.append(logs['logGroupName'])15 for i in newlist:16 if 'Int' in i or 'inegration' in i:17 log=client.put_retention_policy(18 logGroupName=i,19 retentionInDays=3020 )21 elif 'stage' in i or 'Stg' in i or 'Staging' in i:22 log=client.put_retention_policy(23 logGroupName=i,24 retentionInDays=90 25 )26 elif 'Prod' in i or 'Prd' in i or 'production' in i:27 log=client.put_retention_policy(28 logGroupName=i,29 retentionInDays=180...
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!!