Skip to content

Commit

Permalink
Add failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasMarwitzQC authored and thomasmarwitz committed Dec 20, 2024
1 parent 679b2fb commit f0d4ec2
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions tests/test_s3fs_minio.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from typing import NamedTuple

from minimalkv import get_store_from_url
Expand All @@ -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"]

Expand All @@ -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"
Expand All @@ -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."

0 comments on commit f0d4ec2

Please sign in to comment.