Skip to content

Commit 3a61603

Browse files
Pylint Fixes
1 parent 8b3f537 commit 3a61603

7 files changed

Lines changed: 30 additions & 20 deletions

File tree

src/ContentProcessor/conftest.py

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

1414

15-
@pytest.fixture(autouse=True, scope="function")
15+
@pytest.fixture(autouse=True, scope="function")
1616
def mock_azure_credentials_for_helpers(request):
1717
"""
1818
Mock Azure credentials for azure_helper classes only.
@@ -22,13 +22,13 @@ def mock_azure_credentials_for_helpers(request):
2222
if "test_azure_credential_utils" in str(request.fspath):
2323
yield
2424
return
25-
25+
2626
with patch("helpers.azure_credential_utils.get_azure_credential") as mock_get_cred, \
2727
patch("helpers.azure_credential_utils.get_azure_credential_async") as mock_get_cred_async:
28-
28+
2929
# Create mock credential objects
3030
mock_credential = MagicMock()
3131
mock_get_cred.return_value = mock_credential
3232
mock_get_cred_async.return_value = mock_credential
33-
33+
3434
yield mock_credential

src/ContentProcessor/src/helpers/azure_credential_utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
async def get_azure_credential_async(client_id=None):
1010
"""
1111
Returns an Azure credential asynchronously based on the application environment.
12-
12+
1313
If the environment is 'dev', it uses AioDefaultAzureCredential.
1414
Otherwise, it uses AioManagedIdentityCredential.
15-
15+
1616
Args:
1717
client_id (str, optional): The client ID for the Managed Identity Credential.
18-
18+
1919
Returns:
2020
Credential object: Either AioDefaultAzureCredential or AioManagedIdentityCredential.
2121
"""
@@ -28,13 +28,13 @@ async def get_azure_credential_async(client_id=None):
2828
def get_azure_credential(client_id=None):
2929
"""
3030
Returns an Azure credential based on the application environment.
31-
31+
3232
If the environment is 'dev', it uses DefaultAzureCredential.
3333
Otherwise, it uses ManagedIdentityCredential.
34-
34+
3535
Args:
3636
client_id (str, optional): The client ID for the Managed Identity Credential.
37-
37+
3838
Returns:
3939
Credential object: Either DefaultAzureCredential or ManagedIdentityCredential.
4040
"""

src/ContentProcessor/src/libs/application/application_context.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# Licensed under the MIT License.
33
from typing import Any
44

5-
from helpers.azure_credential_utils import get_azure_credential
6-
75
from libs.application.application_configuration import AppConfiguration
86
from libs.base.application_models import AppModelBase
97

src/ContentProcessor/src/tests/helpers/test_azure_credential_utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
# Ensure src directory is on the Python path for imports
1010
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
1111

12-
import helpers.azure_credential_utils as azure_credential_utils
12+
# Import after path modification (flake8: noqa)
13+
import helpers.azure_credential_utils as azure_credential_utils # noqa: E402
14+
1315

1416
# Synchronous tests
1517

18+
1619
@patch("helpers.azure_credential_utils.os.getenv")
1720
@patch("helpers.azure_credential_utils.DefaultAzureCredential")
1821
@patch("helpers.azure_credential_utils.ManagedIdentityCredential")
@@ -29,6 +32,7 @@ def test_get_azure_credential_dev_env(mock_managed_identity_credential, mock_def
2932
mock_managed_identity_credential.assert_not_called()
3033
assert credential == mock_default_credential
3134

35+
3236
@patch("helpers.azure_credential_utils.os.getenv")
3337
@patch("helpers.azure_credential_utils.DefaultAzureCredential")
3438
@patch("helpers.azure_credential_utils.ManagedIdentityCredential")
@@ -44,8 +48,10 @@ def test_get_azure_credential_non_dev_env(mock_managed_identity_credential, mock
4448
mock_default_azure_credential.assert_not_called()
4549
assert credential == mock_managed_credential
4650

51+
4752
# Asynchronous tests
4853

54+
4955
@pytest.mark.asyncio
5056
@patch("helpers.azure_credential_utils.os.getenv")
5157
@patch("helpers.azure_credential_utils.AioDefaultAzureCredential")
@@ -63,6 +69,7 @@ async def test_get_azure_credential_async_dev_env(mock_aio_managed_identity_cred
6369
mock_aio_managed_identity_credential.assert_not_called()
6470
assert credential == mock_aio_default_credential
6571

72+
6673
@pytest.mark.asyncio
6774
@patch("helpers.azure_credential_utils.os.getenv")
6875
@patch("helpers.azure_credential_utils.AioDefaultAzureCredential")

src/ContentProcessorAPI/conftest.py

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

1414

15-
@pytest.fixture(autouse=True, scope="function")
15+
@pytest.fixture(autouse=True, scope="function")
1616
def mock_azure_credentials_for_helpers(request):
1717
"""
1818
Mock Azure credentials for azure_helper classes only.
@@ -22,13 +22,13 @@ def mock_azure_credentials_for_helpers(request):
2222
if "test_azure_credential_utils" in str(request.fspath):
2323
yield
2424
return
25-
25+
2626
with patch("helpers.azure_credential_utils.get_azure_credential") as mock_get_cred, \
2727
patch("helpers.azure_credential_utils.get_azure_credential_async") as mock_get_cred_async:
28-
28+
2929
# Create mock credential objects
3030
mock_credential = MagicMock()
3131
mock_get_cred.return_value = mock_credential
3232
mock_get_cred_async.return_value = mock_credential
33-
33+
3434
yield mock_credential

src/ContentProcessorAPI/helpers/azure_credential_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ def get_azure_credential(client_id=None):
3232
if os.getenv("APP_ENV", "prod").lower() == 'dev':
3333
return DefaultAzureCredential() # CodeQL [SM05139] Okay use of DefaultAzureCredential as it is only used in development
3434
else:
35-
return ManagedIdentityCredential(client_id=client_id)
35+
return ManagedIdentityCredential(client_id=client_id)

src/ContentProcessorAPI/tests/helpers/test_azure_credential_utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
14
import pytest
25
import sys
36
import os
@@ -6,7 +9,9 @@
69
# Ensure src/backend is on the Python path for imports
710
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
811

9-
import helpers.azure_credential_utils as azure_credential_utils
12+
# Import after path modification (flake8: noqa)
13+
import helpers.azure_credential_utils as azure_credential_utils # noqa: E402
14+
1015

1116
# Synchronous tests
1217

@@ -80,4 +85,4 @@ async def test_get_azure_credential_async_non_dev_env(mock_aio_managed_identity_
8085
mock_getenv.assert_called_once_with("APP_ENV", "prod")
8186
mock_aio_managed_identity_credential.assert_called_once_with(client_id="test-client-id")
8287
mock_aio_default_azure_credential.assert_not_called()
83-
assert credential == mock_aio_managed_credential
88+
assert credential == mock_aio_managed_credential

0 commit comments

Comments
 (0)