From f627233e9b181c81c77c696a3cd57b850acfe7cf Mon Sep 17 00:00:00 2001 From: Siddharth Manoj Date: Thu, 30 Nov 2023 04:45:19 -0500 Subject: [PATCH] fix tests --- .../unit/sidecars/live_data_watcher_tests.py | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tests/unit/sidecars/live_data_watcher_tests.py b/tests/unit/sidecars/live_data_watcher_tests.py index 9e1ef4517..828e7026b 100644 --- a/tests/unit/sidecars/live_data_watcher_tests.py +++ b/tests/unit/sidecars/live_data_watcher_tests.py @@ -19,17 +19,17 @@ class NodeWatcherTests(unittest.TestCase): mock_s3 = mock_s3() bucket_name = "test_bucket" - s3_client = boto3.client( - "s3", - region_name="us-east-1", - ) default_file_key = "test_file_key" def setUp(self): self.mock_s3.start() + s3_client = boto3.client( + "s3", + region_name="us-east-1", + ) s3_data = {"foo_encrypted": "bar_encrypted"} - self.s3_client.create_bucket(Bucket=self.bucket_name) + s3_client.create_bucket(Bucket=self.bucket_name) for file_shard_num in range(NUM_FILE_SHARDS): if file_shard_num == 0: # The first copy should just be the original file. @@ -37,7 +37,7 @@ def setUp(self): else: # All other copies should include the sharded prefix. sharded_file_key = str(file_shard_num) + "/" + self.default_file_key - self.s3_client.put_object( + s3_client.put_object( Bucket=self.bucket_name, Key=sharded_file_key, Body=json.dumps(s3_data).encode(), @@ -65,7 +65,11 @@ def test_s3_load_type_on_change(self): self.assertEqual(dest.group(), grp.getgrgid(os.getgid()).gr_name) # For additional good measure, let's also fetch the file from S3 and validate the contents. - obj = self.s3_client.get_object(Bucket=self.bucket_name, Key=self.default_file_key) + s3_client = boto3.client( + "s3", + region_name="us-east-1", + ) + obj = s3_client.get_object(Bucket=self.bucket_name, Key=self.default_file_key) actual_data = obj["Body"].read().decode("utf-8") assert actual_data == json.loads(expected_content) @@ -86,7 +90,11 @@ def test_s3_load_type_sharded_on_change(self): self.assertEqual(dest.group(), grp.getgrgid(os.getgid()).gr_name) # For additional good measure, let's also fetch the files from S3 and validate the contents. - obj = self.s3_client.get_object(Bucket=self.bucket_name, Key=self.default_file_key) + s3_client = boto3.client( + "s3", + region_name="us-east-1", + ) + obj = s3_client.get_object(Bucket=self.bucket_name, Key=self.default_file_key) actual_data = obj["Body"].read().decode("utf-8") assert actual_data == json.loads(expected_content) @@ -94,7 +102,7 @@ def test_s3_load_type_sharded_on_change(self): # data as the original. for i in range(1, NUM_FILE_SHARDS): file_key = str(i) + "/" + self.default_file_key - obj = self.s3_client.get_object(Bucket=self.bucket_name, Key=file_key) + obj = s3_client.get_object(Bucket=self.bucket_name, Key=file_key) actual_data = obj["Body"].read().decode("utf-8") assert actual_data == json.loads(expected_content)