Skip to content

Commit

Permalink
add __str__ and __repr__ to both gcs and aws
Browse files Browse the repository at this point in the history
  • Loading branch information
MAfarrag committed Dec 23, 2024
1 parent 6a14d75 commit 1664d7b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/unicloud/aws/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ def __init__(self, bucket): # :boto3.resources("s3").Bucket
"""
self._bucket = bucket

def __str__(self):
"""__str__."""
return f"Bucket: {self.name}"

def __repr__(self):
"""__repr__."""
return f"Bucket: {self.name}"

@property
def bucket(self):
"""bucket."""
Expand Down
17 changes: 17 additions & 0 deletions tests/aws/test_aws_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,23 @@ def test_download_empty_directory(self):
self.bucket.download("empty-dir/", "tests/data/empty-dir/")


class TestPropertiesMock:

def setup_method(self):
self.mock_bucket = MagicMock()
self.mock_bucket.name = "test_bucket"
self.gcs_bucket = Bucket(self.mock_bucket)

def test_name_property(self):
assert self.gcs_bucket.name == "test_bucket"

def test__str__(self):
assert str(self.gcs_bucket) == "Bucket: test_bucket"

def test__repr__(self):
assert str(self.gcs_bucket.__repr__()) == "Bucket: test_bucket"


class TestUploadMock:
"""
Mock tests for the Bucket class.
Expand Down
17 changes: 17 additions & 0 deletions tests/google_cloud/test_gcs_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,23 @@ def test_delete_empty_directory_e2e(self, gcs_bucket: Bucket):
gcs_bucket.delete(directory)


class TestPropertiesMock:

def setup_method(self):
self.mock_bucket = MagicMock()
self.mock_bucket.name = "test_bucket"
self.gcs_bucket = Bucket(self.mock_bucket)

def test_name_property(self):
assert self.gcs_bucket.name == "test_bucket"

def test__str__(self):
assert str(self.gcs_bucket) == "Bucket: test_bucket"

def test__repr__(self):
assert str(self.gcs_bucket.__repr__()) == "Bucket: test_bucket"


class TestDownloadMock:

@pytest.mark.mock
Expand Down

0 comments on commit 1664d7b

Please sign in to comment.