-
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.
Merge pull request #446 from wri/develop
Merge-up code to redact environment when logging Batch payloads
- Loading branch information
Showing
4 changed files
with
62 additions
and
11 deletions.
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
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,40 @@ | ||
from typing import Dict, List | ||
from unittest.mock import MagicMock, patch | ||
|
||
from fastapi.logger import logger | ||
|
||
from app.tasks.batch import submit_batch_job | ||
from app.tasks.vector_source_assets import _create_add_gfw_fields_job | ||
from tests_v2.conftest import mock_callback | ||
|
||
TEST_JOB_ENV: List[Dict[str, str]] = [{"name": "PASSWORD", "value": "DON'T LOG ME"}] | ||
|
||
|
||
@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] |
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