|
| 1 | +from unittest import TestCase |
| 2 | + |
| 3 | +from mdps_ds_lib.lib.aws.aws_s3 import AwsS3 |
| 4 | + |
| 5 | + |
| 6 | +class TestAwsS3(TestCase): |
| 7 | + def test_delete_one_01(self): |
| 8 | + bucket = 'uds-sbx-cumulus-staging' |
| 9 | + s3 = AwsS3() |
| 10 | + single_path = 'tmp/unit-test/file1.txt' |
| 11 | + s3.set_s3_url(f's3://{bucket}/{single_path}').upload_bytes('This is a test'.encode()) |
| 12 | + d = s3.delete_one() |
| 13 | + print(d) |
| 14 | + return |
| 15 | + |
| 16 | + def test_delete_multiple_01(self): |
| 17 | + bucket = 'uds-sbx-cumulus-staging' |
| 18 | + s3 = AwsS3() |
| 19 | + deleting_s3_urls = [] |
| 20 | + for i in range(10): |
| 21 | + single_path = f'tmp/unit-test/file{i}.txt' |
| 22 | + deleting_s3_urls.append(f's3://{bucket}/{single_path}') |
| 23 | + s3.set_s3_url(deleting_s3_urls[-1]).upload_bytes(f'This is a test - {i}'.encode()) |
| 24 | + d = s3.delete_multiple(s3_urls=deleting_s3_urls) |
| 25 | + print(d) |
| 26 | + return |
| 27 | + |
| 28 | + def test_delete_multiple_02(self): |
| 29 | + bucket = 'uds-sbx-cumulus-staging' |
| 30 | + s3 = AwsS3() |
| 31 | + deleting_s3_paths = [] |
| 32 | + for i in range(10): |
| 33 | + single_path = f'tmp/unit-test/file{i}.txt' |
| 34 | + deleting_s3_paths.append(single_path) |
| 35 | + s3.set_s3_url(f's3://{bucket}/{single_path}').upload_bytes(f'This is a test - {i}'.encode()) |
| 36 | + d = s3.delete_multiple(s3_bucket=bucket, s3_paths=deleting_s3_paths) |
| 37 | + print(d) |
| 38 | + return |
| 39 | + |
| 40 | + def test_delete_multiple_03(self): |
| 41 | + bucket = 'uds-sbx-cumulus-staging' |
| 42 | + s3 = AwsS3() |
| 43 | + with self.assertRaises(ValueError) as context: |
| 44 | + s3.delete_multiple(s3_bucket=bucket, s3_paths=[]) |
| 45 | + self.assertTrue(str(context.exception).startswith('unable to delete empty list of URLs or Paths')) |
| 46 | + |
| 47 | + with self.assertRaises(ValueError) as context: |
| 48 | + s3.delete_multiple(s3_urls=[]) |
| 49 | + self.assertTrue(str(context.exception).startswith('unable to delete empty list of URLs or Paths')) |
| 50 | + |
| 51 | + with self.assertRaises(ValueError) as context: |
| 52 | + s3.delete_multiple(s3_bucket='', s3_paths=['a', 'b', 'c']) |
| 53 | + self.assertTrue(str(context.exception).startswith('empty s3 bucket for paths')) |
| 54 | + |
| 55 | + with self.assertRaises(ValueError) as context: |
| 56 | + s3.delete_multiple(s3_urls=['s3://a/b', 's3://b/c']) |
| 57 | + self.assertTrue(str(context.exception).startswith('unable to delete multiple s3 buckets')) |
| 58 | + return |
0 commit comments