Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
drf7 committed Aug 9, 2024
1 parent 2f36615 commit 38fbb0a
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions nucliadb/tests/writer/unit/tus/test_gcs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from unittest.mock import MagicMock, patch

import pytest

from nucliadb.writer.tus.gcs import GCloudBlobStore


@pytest.mark.asyncio
@patch("nucliadb.writer.tus.gcs.aiohttp")
@patch("nucliadb.writer.tus.gcs.service_account")
async def test_tus_gcs(mock_sa, mock_aiohttp):
mock_session = MagicMock()
mock_aiohttp.ClientSession.return_value = mock_session
mock_aenter = MagicMock()
mock_aenter.__aenter__.return_value = MagicMock(status=200)
mock_session.get.return_value = mock_aenter

gblobstore = GCloudBlobStore()
await gblobstore.initialize(
bucket="test-bucket",
location="test-location",
project="test-project",
bucket_labels="test-labels",
object_base_url="test-url",
json_credentials="test-cred",
)

mock_sa.Credentials.from_service_account_info.assert_called_once_with(
"test-cred", scopes=["https://www.googleapis.com/auth/devstorage.read_write"]
)

assert await gblobstore.check_exists("test-bucket")


@pytest.mark.asyncio
@patch("nucliadb.writer.tus.gcs.google")
async def test_tus_gcs_empty_json_credentials(mock_google):
mock_google.auth.default.return_value = ("credential", "project")

gblobstore = GCloudBlobStore()
await gblobstore.initialize(
bucket="test-bucket",
location="test-location",
project="test-project",
bucket_labels="test-labels",
object_base_url="test-url",
json_credentials=None,
)

mock_google.auth.default.assert_called_once()

0 comments on commit 38fbb0a

Please sign in to comment.