Beispiel #1
0
 def test_tagging_deletion(self):
     self.__moto_setup()
     s3_client = boto3.client('s3')
     # ek object upload karo
     source_objectname_value = '1.txt'
     source_objectname_value2 = '2.txt'
     s3_client.put_object(Bucket='shivam1052061', Key=source_objectname_value)
     s3_client.put_object(Bucket='shivam1052061', Key=source_objectname_value2)
     # tag dalo
     tagset_value = {'TagSet': [{'Key': 'notdivby2', 'Value': '2no'}]}
     t = Tags(parameter)
     t.tagging_insertion(source_objectname_value, tagset_value)
     # tag retrieve karo
     response = s3_client.get_object_tagging(
         Bucket=parameter['SourceBucketName'],
         Key=source_objectname_value
     )
     # delete karo
     output_to_be_checked = [tag for tag in response.get('TagSet')]
     # print(" last : \n")
     # print(output_to_be_checked)
     if output_to_be_checked == [{'Key': 'notdivby2', 'Value': '2no'}]:
         resp = s3_client.delete_object(
             Bucket=parameter["SourceBucketName"],
             Key=source_objectname_value
         )
         #  print("lol \n")
         # print(resp)
         # print(resp['ResponseMetadata']['HTTPStatusCode'])
         # self.assertEqual(resp['ResponseMetadata']['HTTPStatusCode'],204)
         # obect_count_in_the_bucket_before_deletion = 2
         object_count_in_the_bucket_after_deletion = 1
         s3_bucket_object_count = 0
         response = s3_client.list_objects_v2(Bucket='shivam1052061')
         if response:
             try:
                 for _object in response['Contents']:
                     s3_bucket_object_count = s3_bucket_object_count + 1
             except KeyError:
                 print("KeyError. No such key exists in the specified bucket")
         # print("object_count_in_the_bucket_after_deletion")
         # print(s3_bucket_object_count)
         # assertequals karo
         self.assertEqual(1, object_count_in_the_bucket_after_deletion)
Beispiel #2
0
    def test_tagging_insertion(self):
        self.__moto_setup()
        s3_client = boto3.client('s3')
        source_objectname_value = '1.txt'
        s3_client.put_object(Bucket='shivam1052061', Key=source_objectname_value)
        tagset_value = {'TagSet': [{'Key': 'notdivby2', 'Value': '2no'},
                                   {'Key': 'key1', 'Value': 'val1'}]}
        t = Tags(parameter)

        t.tagging_insertion(source_objectname_value, tagset_value)
        s3_client = boto3.client('s3')
        response = s3_client.get_object_tagging(
            Bucket=parameter['SourceBucketName'],
            Key=source_objectname_value
        )
        # print("get object taggings")
        output_to_be_checked = [tag for tag in response.get('TagSet')]
        # print(output_to_be_checked)
        for b in output_to_be_checked:
            self.assertIn(b, output_to_be_checked)