diff --git a/tests/test_s3fs_minio.py b/tests/test_s3fs_minio.py index 977e4c5..1cb7d8a 100644 --- a/tests/test_s3fs_minio.py +++ b/tests/test_s3fs_minio.py @@ -1,3 +1,4 @@ +import os from typing import NamedTuple from minimalkv import get_store_from_url @@ -13,21 +14,23 @@ class User(NamedTuple): # user2 -> bucket2 # Including one bucket_name per `User` here is just for readability + def get_store_from_config(self): + return get_store_from_url( + f"hs3://{self.access_key}:{self.secret_key}@localhost:9000/{self.bucket_name}?force_bucket_suffix=false&verify=false" + ) + + +user1 = User("user1", "password1", "bucket1") +user2 = User("user2", "password2", "bucket2") + def test_access_multiple_users(): """Verify that two buckets of different users can be accessed in the same python process.""" - user1 = User("user1", "password1", "bucket1") - user2 = User("user2", "password2", "bucket2") - - bucket1 = get_store_from_url( - f"hs3://{user1.access_key}:{user1.secret_key}@localhost:9000/{user1.bucket_name}?force_bucket_suffix=false&verify=false" - ) + bucket1 = user1.get_store_from_config() assert bucket1.keys() == ["file1.txt"] - bucket2 = get_store_from_url( - f"hs3://{user2.access_key}:{user2.secret_key}@localhost:9000/{user2.bucket_name}?force_bucket_suffix=false&verify=false" - ) + bucket2 = user2.get_store_from_config() assert bucket2.keys() == ["file2.txt"] @@ -41,11 +44,9 @@ def test_example_interaction(): - get() - delete() """ - user = User("user1", "password1", "bucket1") + # TODO: Replace w/ testing strategy as done in `test_boto3_store.py` - bucket = get_store_from_url( - f"hs3://{user.access_key}:{user.secret_key}@localhost:9000/{user.bucket_name}?force_bucket_suffix=false&verify=false" - ) + bucket = user1.get_store_from_config() new_filename = "some-non-existing-file" new_content = b"content" @@ -58,3 +59,19 @@ def test_example_interaction(): bucket.delete(new_filename) assert new_filename not in bucket.keys() + + +def test_no_env_side_effects(): + pre_env_state = os.environ.copy() + + bucket = user1.get_store_from_config() + + assert dict(os.environ) == dict( + pre_env_state + ), "Retrieved bucket should not modify the environment." + + bucket.keys() + + assert ( + os.environ == pre_env_state + ), "Performing operations on the bucket should not modify the environment."