Skip to content

Commit 8b3f537

Browse files
test workflow final fixes
1 parent 7979ca6 commit 8b3f537

4 files changed

Lines changed: 37 additions & 38 deletions

File tree

src/ContentProcessor/conftest.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,23 @@
1212
pytest_plugins = ["pytest_mock"]
1313

1414

15-
@pytest.fixture(autouse=True, scope="session")
16-
def mock_azure_services():
15+
@pytest.fixture(autouse=True, scope="function")
16+
def mock_azure_credentials_for_helpers(request):
1717
"""
18-
Mock all Azure services and credentials to prevent real authentication
19-
and network calls during testing.
18+
Mock Azure credentials for azure_helper classes only.
19+
Skip this for credential utility tests that need to test the actual logic.
2020
"""
21-
with patch("azure.identity.DefaultAzureCredential") as mock_default, \
22-
patch("azure.identity.ManagedIdentityCredential") as mock_managed, \
23-
patch("helpers.azure_credential_utils.get_azure_credential") as mock_get_cred, \
21+
# Skip mocking for credential utility tests
22+
if "test_azure_credential_utils" in str(request.fspath):
23+
yield
24+
return
25+
26+
with patch("helpers.azure_credential_utils.get_azure_credential") as mock_get_cred, \
2427
patch("helpers.azure_credential_utils.get_azure_credential_async") as mock_get_cred_async:
2528

2629
# Create mock credential objects
2730
mock_credential = MagicMock()
28-
mock_default.return_value = mock_credential
29-
mock_managed.return_value = mock_credential
3031
mock_get_cred.return_value = mock_credential
3132
mock_get_cred_async.return_value = mock_credential
3233

33-
yield {
34-
"credential": mock_credential,
35-
"default": mock_default,
36-
"managed": mock_managed,
37-
"get_credential": mock_get_cred,
38-
"get_credential_async": mock_get_cred_async
39-
}
34+
yield mock_credential

src/ContentProcessor/src/tests/azure_helper/test_storage_blob.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import pytest
22
from io import BytesIO
3-
from unittest.mock import MagicMock
4-
from libs.azure_helper.storage_blob import StorageBlobHelper
3+
from unittest.mock import MagicMock, patch
4+
5+
# Ensure Azure credentials are mocked before any imports
6+
with patch("helpers.azure_credential_utils.get_azure_credential") as mock_cred:
7+
mock_cred.return_value = MagicMock()
8+
from libs.azure_helper.storage_blob import StorageBlobHelper
59

610

711
@pytest.fixture
812
def mock_blob_service_client(mocker):
9-
"""Mock BlobServiceClient to prevent any network calls."""
10-
return mocker.patch("azure.storage.blob.BlobServiceClient")
13+
"""Mock BlobServiceClient class for tests."""
14+
return mocker.patch("libs.azure_helper.storage_blob.BlobServiceClient")
1115

1216

1317
@pytest.fixture
1418
def storage_blob_helper(mock_blob_service_client):
15-
"""Create StorageBlobHelper with all Azure services mocked via conftest.py."""
19+
"""Create StorageBlobHelper with mocked BlobServiceClient."""
1620
return StorageBlobHelper(
1721
account_url="https://testaccount.blob.core.windows.net",
1822
container_name="testcontainer",

src/ContentProcessorAPI/app/tests/libs/test_storage_blob.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import pytest
22
from azure.storage.blob import BlobServiceClient, ContainerClient, BlobClient
33
from azure.core.exceptions import ResourceNotFoundError
4-
from app.libs.storage_blob.helper import StorageBlobHelper
4+
from unittest.mock import MagicMock, patch
5+
6+
# Ensure Azure credentials are mocked before any imports
7+
with patch("helpers.azure_credential_utils.get_azure_credential") as mock_cred:
8+
mock_cred.return_value = MagicMock()
9+
from app.libs.storage_blob.helper import StorageBlobHelper
510

611

712
@pytest.fixture

src/ContentProcessorAPI/conftest.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,23 @@
1212
pytest_plugins = ["pytest_mock"]
1313

1414

15-
@pytest.fixture(autouse=True, scope="session")
16-
def mock_azure_services():
15+
@pytest.fixture(autouse=True, scope="function")
16+
def mock_azure_credentials_for_helpers(request):
1717
"""
18-
Mock all Azure services and credentials to prevent real authentication
19-
and network calls during testing.
18+
Mock Azure credentials for azure_helper classes only.
19+
Skip this for credential utility tests that need to test the actual logic.
2020
"""
21-
with patch("azure.identity.DefaultAzureCredential") as mock_default, \
22-
patch("azure.identity.ManagedIdentityCredential") as mock_managed, \
23-
patch("helpers.azure_credential_utils.get_azure_credential") as mock_get_cred, \
21+
# Skip mocking for credential utility tests
22+
if "test_azure_credential_utils" in str(request.fspath):
23+
yield
24+
return
25+
26+
with patch("helpers.azure_credential_utils.get_azure_credential") as mock_get_cred, \
2427
patch("helpers.azure_credential_utils.get_azure_credential_async") as mock_get_cred_async:
2528

2629
# Create mock credential objects
2730
mock_credential = MagicMock()
28-
mock_default.return_value = mock_credential
29-
mock_managed.return_value = mock_credential
3031
mock_get_cred.return_value = mock_credential
3132
mock_get_cred_async.return_value = mock_credential
3233

33-
yield {
34-
"credential": mock_credential,
35-
"default": mock_default,
36-
"managed": mock_managed,
37-
"get_credential": mock_get_cred,
38-
"get_credential_async": mock_get_cred_async
39-
}
34+
yield mock_credential

0 commit comments

Comments
 (0)