Skip to content

Commit

Permalink
rename GCSBucket to Bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
MAfarrag committed Dec 14, 2024
1 parent d275b70 commit cffd50a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/unicloud/google_cloud/gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def download(self, cloud_path, local_path):
blob.download_to_filename(local_path)
print(f"File {cloud_path} downloaded to {local_path}.")

def get_bucket(self, bucket_id: str) -> "GCSBucket":
def get_bucket(self, bucket_id: str) -> "Bucket":
"""get_bucket.
get_bucket returns the bucket object
Expand All @@ -215,10 +215,10 @@ def get_bucket(self, bucket_id: str) -> "GCSBucket":
>>> bucket_usr = gcs.get_bucket(my_bucket_id) # doctest: +SKIP
"""
bucket = storage.Bucket(self.client, bucket_id, user_project=self.project_id)
return GCSBucket(bucket)
return Bucket(bucket)


class GCSBucket:
class Bucket:
"""GCSBucket."""

def __init__(self, bucket: storage.bucket.Bucket):
Expand Down
4 changes: 2 additions & 2 deletions tests/google_cloud/test_gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytest

from unicloud.google_cloud.gcs import GCS, GCSBucket
from unicloud.google_cloud.gcs import GCS, Bucket

MY_TEST_BUCKET = "testing-repositories"
PROJECT_ID = "earth-engine-415620"
Expand Down Expand Up @@ -179,4 +179,4 @@ def test_upload_and_download(self, test_file: Path, test_file_content: str):

def test_get_bucket(self):
bucket = self.gcs.get_bucket(self.bucket_name)
assert isinstance(bucket, GCSBucket)
assert isinstance(bucket, Bucket)
32 changes: 16 additions & 16 deletions tests/google_cloud/test_gcs_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
from google.cloud import storage

from unicloud.google_cloud.gcs import GCS, GCSBucket
from unicloud.google_cloud.gcs import GCS, Bucket

MY_TEST_BUCKET = "testing-repositories"
PROJECT_ID = "earth-engine-415620"
Expand All @@ -20,7 +20,7 @@ def setup_class(cls):
"""Set up resources before running tests."""
client = GCS(PROJECT_ID).client
bucket = storage.Bucket(client, MY_TEST_BUCKET, user_project=PROJECT_ID)
cls.bucket = GCSBucket(bucket)
cls.bucket = Bucket(bucket)

def test_list_files(self):
blobs = self.bucket.list_files()
Expand Down Expand Up @@ -106,7 +106,7 @@ def test_search():
mock_blob4,
]

gcs_bucket = GCSBucket(mock_bucket)
gcs_bucket = Bucket(mock_bucket)

matching_files = gcs_bucket.search("*.txt")
assert matching_files == ["file1.txt", "data/file2.txt", "logs/log1.txt"]
Expand All @@ -119,10 +119,10 @@ def test_search():
class TestDeleteE2E:

@pytest.fixture
def gcs_bucket(self) -> GCSBucket:
def gcs_bucket(self) -> Bucket:
return GCS(PROJECT_ID).get_bucket(MY_TEST_BUCKET)

def test_delete_single_file_e2e(self, gcs_bucket: GCSBucket):
def test_delete_single_file_e2e(self, gcs_bucket: Bucket):

blob = gcs_bucket.bucket.blob("test_delete_single.txt")
blob.upload_from_string("Test content")
Expand All @@ -131,7 +131,7 @@ def test_delete_single_file_e2e(self, gcs_bucket: GCSBucket):
gcs_bucket.delete("test_delete_single.txt")
assert not gcs_bucket.file_exists("test_delete_single.txt")

def test_delete_directory_e2e(self, gcs_bucket: GCSBucket):
def test_delete_directory_e2e(self, gcs_bucket: Bucket):

blob1 = gcs_bucket.bucket.blob("test_directory/file1.txt")
blob1.upload_from_string("File 1 content")
Expand All @@ -148,14 +148,14 @@ def test_delete_directory_e2e(self, gcs_bucket: GCSBucket):
assert not gcs_bucket.file_exists("test_directory/file1.txt")
assert not gcs_bucket.file_exists("test_directory/subdir/file2.txt")

def test_delete_nonexistent_file_e2e(self, gcs_bucket: GCSBucket):
def test_delete_nonexistent_file_e2e(self, gcs_bucket: Bucket):
"""Test deleting a file that does not exist."""
with pytest.raises(
ValueError, match="File non_existent_file.txt not found in the bucket."
):
gcs_bucket.delete("non_existent_file.txt")

def test_delete_empty_directory_e2e(self, gcs_bucket: GCSBucket):
def test_delete_empty_directory_e2e(self, gcs_bucket: Bucket):
"""Test deleting an empty directory."""
directory = "empty_directory/"
with pytest.raises(
Expand All @@ -179,7 +179,7 @@ def test_download_directory_from_gcs(self):

mock_bucket.list_blobs.return_value = [mock_blob1, mock_blob2, mock_blob3]

gcs_bucket = GCSBucket(mock_bucket)
gcs_bucket = Bucket(mock_bucket)

mock_blob1.download_to_filename = MagicMock()
mock_blob2.download_to_filename = MagicMock()
Expand Down Expand Up @@ -209,7 +209,7 @@ def test_download_single_file_from_gcs(self):
mock_blob.name = "test_file.txt"
mock_bucket.blob.return_value = mock_blob

gcs_bucket = GCSBucket(mock_bucket)
gcs_bucket = Bucket(mock_bucket)

mock_blob.download_to_filename = MagicMock()

Expand All @@ -229,7 +229,7 @@ def test_upload_single_file(self):
mock_bucket = MagicMock()
mock_bucket.blob.return_value = mock_blob

gcs_bucket = GCSBucket(mock_bucket)
gcs_bucket = Bucket(mock_bucket)

local_file = Path("local/file.txt")
bucket_path = "bucket/folder/file.txt"
Expand All @@ -245,7 +245,7 @@ def test_upload_single_file(self):
def test_upload_directory_with_subdirectories(self):

mock_bucket = MagicMock()
gcs_bucket = GCSBucket(mock_bucket)
gcs_bucket = Bucket(mock_bucket)

# Mock directory and files
local_directory = Path("local/directory")
Expand Down Expand Up @@ -285,7 +285,7 @@ def test_delete_single_file(self):
mock_bucket.blob.return_value = mock_blob
mock_blob.exists.return_value = True

gcs_bucket = GCSBucket(mock_bucket)
gcs_bucket = Bucket(mock_bucket)

file_name = "example.txt"
gcs_bucket.delete(file_name)
Expand All @@ -300,7 +300,7 @@ def test_delete_single_file_not_found(self):
mock_bucket.blob.return_value = mock_blob
mock_blob.exists.return_value = False

gcs_bucket = GCSBucket(mock_bucket)
gcs_bucket = Bucket(mock_bucket)

file_name = "non_existent_file.txt"
with pytest.raises(
Expand All @@ -320,7 +320,7 @@ def test_delete_directory(self):
mock_blob2.name = "data/subdir/file2.txt"
mock_bucket.list_blobs.return_value = [mock_blob1, mock_blob2]

gcs_bucket = GCSBucket(mock_bucket)
gcs_bucket = Bucket(mock_bucket)

directory = "data/"
gcs_bucket.delete(directory)
Expand All @@ -335,7 +335,7 @@ def test_delete_directory_empty(self):
mock_bucket = MagicMock()
mock_bucket.list_blobs.return_value = []

gcs_bucket = GCSBucket(mock_bucket)
gcs_bucket = Bucket(mock_bucket)

directory = "empty_directory/"
with pytest.raises(
Expand Down

0 comments on commit cffd50a

Please sign in to comment.