How to use put_bucket_tagging method in localstack

Best Python code snippet using localstack_python

test_s3_bucket_tagging.py

Source: test_s3_bucket_tagging.py Github

copy

Full Screen

1#2# Licensed to the Apache Software Foundation (ASF) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The ASF licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http:/​/​www.apache.org/​licenses/​LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.18import os19import unittest20from unittest import mock21from moto import mock_s322from airflow.providers.amazon.aws.hooks.s3 import S3Hook23from airflow.providers.amazon.aws.operators.s3 import (24 S3DeleteBucketTaggingOperator,25 S3GetBucketTaggingOperator,26 S3PutBucketTaggingOperator,27)28BUCKET_NAME = os.environ.get("BUCKET_NAME", "test-airflow-bucket")29TAG_SET = [{'Key': 'Color', 'Value': 'Green'}]30TASK_ID = os.environ.get("TASK_ID", "test-s3-operator")31class TestS3GetBucketTaggingOperator(unittest.TestCase):32 def setUp(self):33 self.get_bucket_tagging_operator = S3GetBucketTaggingOperator(34 task_id=TASK_ID,35 bucket_name=BUCKET_NAME,36 )37 @mock_s338 @mock.patch.object(S3Hook, "get_bucket_tagging")39 @mock.patch.object(S3Hook, "check_for_bucket")40 def test_execute_if_bucket_exist(self, mock_check_for_bucket, get_bucket_tagging):41 mock_check_for_bucket.return_value = True42 # execute s3 get bucket tagging operator43 self.get_bucket_tagging_operator.execute({})44 mock_check_for_bucket.assert_called_once_with(BUCKET_NAME)45 get_bucket_tagging.assert_called_once_with(BUCKET_NAME)46 @mock_s347 @mock.patch.object(S3Hook, "get_bucket_tagging")48 @mock.patch.object(S3Hook, "check_for_bucket")49 def test_execute_if_not_bucket_exist(self, mock_check_for_bucket, get_bucket_tagging):50 mock_check_for_bucket.return_value = False51 # execute s3 get bucket tagging operator52 self.get_bucket_tagging_operator.execute({})53 mock_check_for_bucket.assert_called_once_with(BUCKET_NAME)54 get_bucket_tagging.assert_not_called()55class TestS3PutBucketTaggingOperator(unittest.TestCase):56 def setUp(self):57 self.put_bucket_tagging_operator = S3PutBucketTaggingOperator(58 task_id=TASK_ID,59 tag_set=TAG_SET,60 bucket_name=BUCKET_NAME,61 )62 @mock_s363 @mock.patch.object(S3Hook, "put_bucket_tagging")64 @mock.patch.object(S3Hook, "check_for_bucket")65 def test_execute_if_bucket_exist(self, mock_check_for_bucket, put_bucket_tagging):66 mock_check_for_bucket.return_value = True67 # execute s3 put bucket tagging operator68 self.put_bucket_tagging_operator.execute({})69 mock_check_for_bucket.assert_called_once_with(BUCKET_NAME)70 put_bucket_tagging.assert_called_once_with(71 key=None, value=None, tag_set=TAG_SET, bucket_name=BUCKET_NAME72 )73 @mock_s374 @mock.patch.object(S3Hook, "put_bucket_tagging")75 @mock.patch.object(S3Hook, "check_for_bucket")76 def test_execute_if_not_bucket_exist(self, mock_check_for_bucket, put_bucket_tagging):77 mock_check_for_bucket.return_value = False78 # execute s3 put bucket tagging operator79 self.put_bucket_tagging_operator.execute({})80 mock_check_for_bucket.assert_called_once_with(BUCKET_NAME)81 put_bucket_tagging.assert_not_called()82class TestS3DeleteBucketTaggingOperator(unittest.TestCase):83 def setUp(self):84 self.delete_bucket_tagging_operator = S3DeleteBucketTaggingOperator(85 task_id=TASK_ID,86 bucket_name=BUCKET_NAME,87 )88 @mock_s389 @mock.patch.object(S3Hook, "delete_bucket_tagging")90 @mock.patch.object(S3Hook, "check_for_bucket")91 def test_execute_if_bucket_exist(self, mock_check_for_bucket, delete_bucket_tagging):92 mock_check_for_bucket.return_value = True93 # execute s3 delete bucket tagging operator94 self.delete_bucket_tagging_operator.execute({})95 mock_check_for_bucket.assert_called_once_with(BUCKET_NAME)96 delete_bucket_tagging.assert_called_once_with(BUCKET_NAME)97 @mock_s398 @mock.patch.object(S3Hook, "delete_bucket_tagging")99 @mock.patch.object(S3Hook, "check_for_bucket")100 def test_execute_if_not_bucket_exist(self, mock_check_for_bucket, delete_bucket_tagging):101 mock_check_for_bucket.return_value = False102 # execute s3 delete bucket tagging operator103 self.delete_bucket_tagging_operator.execute({})104 mock_check_for_bucket.assert_called_once_with(BUCKET_NAME)...

Full Screen

Full Screen

lambda_s3_tagging.py

Source: lambda_s3_tagging.py Github

copy

Full Screen

...31 except Exception as error:32 print(error)33# --------------------------------- CREATE/​UPDATE TAGS34# get_bucket_tagging = get_bucket_tagging(list_buckets) >>> IF there is no tag:Name35# def put_bucket_tagging(get_bucket_tagging):36def put_bucket_tagging(list_buckets):37 try:38 # for i in get_bucket_tagging: >>> IF there is no tag:Name39 for i in list_buckets:40 response = client.put_bucket_tagging(41 Bucket = i,42 Tagging = {43 'TagSet': [44 {45 'Key': 'Name',46 'Value': i47 },48 {49 'Key': 'CreatedBy',50 'Value': 'Med'51 },52 ]53 }54 )55 except Exception as error:56 print(error)57# put_bucket_tagging(get_bucket_tagging) >>> IF there is no tag:Name...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

QA Innovation – Using the senseshaping concept to discover customer needs

QA Innovation - Using the senseshaping concept to discover customer needsQA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.

Best 23 Web Design Trends To Follow In 2023

Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.

Acquiring Employee Support for Change Management Implementation

Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.

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