-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log Btch job details BEFORE adding sensitive info
- Loading branch information
1 parent
64e1cfb
commit c73a991
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import asyncio | ||
from typing import Any, Coroutine, Dict, List | ||
from unittest.mock import MagicMock, patch | ||
from uuid import UUID | ||
|
||
from fastapi.logger import logger | ||
|
||
from app.models.pydantic.change_log import ChangeLog | ||
from app.tasks.batch import submit_batch_job | ||
from app.tasks.vector_source_assets import _create_add_gfw_fields_job | ||
|
||
TEST_JOB_ENV: List[Dict[str, str]] = [{"name": "PASSWORD", "value": "DON'T LOG ME"}] | ||
|
||
|
||
async def mock_callback(uuid: UUID, changelog: ChangeLog): | ||
async def helper_function() -> Coroutine[Any, Any, None]: | ||
# Simulate some asynchronous work | ||
return asyncio.sleep(0) | ||
|
||
return helper_function() | ||
|
||
|
||
@patch("app.utils.aws.boto3.client") | ||
@patch.object(logger, "info") # Patch the logger.info directly | ||
@patch("app.tasks.batch.UUID") # Patch the UUID class | ||
async def test_submit_batch_job(mock_uuid, mock_logging_info, mock_boto3_client): | ||
mock_client = MagicMock() | ||
mock_boto3_client.return_value = mock_client | ||
|
||
attempt_duration_seconds: int = 100 | ||
|
||
job = await _create_add_gfw_fields_job( | ||
"some_dataset", | ||
"v1", | ||
parents=list(), | ||
job_env=TEST_JOB_ENV, | ||
callback=mock_callback, | ||
attempt_duration_seconds=attempt_duration_seconds, | ||
) | ||
|
||
# Call the function you want to test | ||
submit_batch_job(job) | ||
|
||
mock_boto3_client.assert_called_once_with( | ||
"batch", region_name="us-east-1", endpoint_url=None | ||
) | ||
|
||
# Assert that the logger.info was called with the expected log message | ||
assert "add_gfw_fields" in mock_logging_info.call_args.args[0] | ||
assert "DON'T LOG ME" not in mock_logging_info.call_args.args[0] |