Skip to content

Commit

Permalink
Mock call to AuthClient fetchCredentials() in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RupinderKaurSSB committed Jun 12, 2024
1 parent 486dcfd commit 38f5075
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from unittest.mock import Mock
from unittest.mock import patch

from dapla import FileClient
from dapla import FileClient, AuthClient

PATH_WITH_PREFIX = "gs://bucket/path"
PATH_WITHOUT_PREFIX = "bucket/path"
Expand Down Expand Up @@ -43,6 +43,8 @@ def test_get_versions_valid_file(self, mock_client: Mock) -> None:
time_deleted=None,
)

AuthClient.fetch_google_credentials = Mock(return_value="test_credentials")

mock_client.return_value.list_blobs.return_value = [mock_blob1, mock_blob2]

files = FileClient.get_versions(bucket_name, file_name)
Expand All @@ -58,6 +60,7 @@ def test_get_versions_empty_bucket(self, mock_client: Mock) -> None:
bucket_name = "test-bucket"
file_name = "test-file.txt"
mock_client.return_value.list_blobs.return_value = []
AuthClient.fetch_google_credentials = Mock(return_value="test_credentials")

files = FileClient.get_versions(bucket_name, file_name)

Expand All @@ -71,6 +74,7 @@ def test_get_versions_non_existent_file(self, mock_client: Mock) -> None:
bucket_name = "test-bucket"
file_name = "non-existent-file.txt"
mock_client.return_value.list_blobs.return_value = []
AuthClient.fetch_google_credentials = Mock(return_value="test_credentials")

files = FileClient.get_versions(bucket_name, file_name)

Expand All @@ -85,6 +89,7 @@ def test_restore_version_success(self, mock_client: Mock) -> None:
mock_source_blob = Mock()
mock_client.return_value.bucket.return_value = mock_bucket
mock_bucket.blob.return_value = mock_source_blob
AuthClient.fetch_google_credentials = Mock(return_value="test_credentials")

blob = FileClient.restore_version(
bucket_name="test-bucket",
Expand All @@ -111,6 +116,7 @@ def test_restore_version_existing_live_version(self, mock_client: Mock) -> None:
mock_source_blob = Mock()
mock_client.return_value.bucket.return_value = mock_bucket
mock_bucket.blob.return_value = mock_source_blob
AuthClient.fetch_google_credentials = Mock(return_value="test_credentials")

blob = FileClient.restore_version(
bucket_name="test-bucket",
Expand Down

0 comments on commit 38f5075

Please sign in to comment.