-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
25 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,14 @@ | |
|
||
from libsys_airflow.plugins.digital_bookplates.dag_979_retries import ( | ||
failed_979_dags, | ||
run_failed_979_dags | ||
run_failed_979_dags, | ||
) | ||
|
||
|
||
def month(): | ||
return datetime.now().month | ||
|
||
|
||
def uuids(): | ||
return [ | ||
"47bf71da-5ca4-496d-a34e-fbc121cd3f1b", | ||
|
@@ -23,38 +24,38 @@ def uuids(): | |
"d062b41a-6809-4f1b-830f-48a3f95df98e", | ||
] | ||
|
||
|
||
def mock_dag_runs(): | ||
mock_dag_runs = [] | ||
|
||
def mock_get_state(): | ||
return 'failed' | ||
|
||
def mock_get_task_instance(*args): | ||
task_instance = MagicMock() | ||
task_instance.xcom_pull = mock_xcom_pull | ||
return task_instance | ||
|
||
for id, idx in enumerate(uuids()): | ||
mock_dag_run = MagicMock() | ||
mock_dag_run.get_state = mock_get_state | ||
mock_dag_run.run_id = f"scheduled__2024-{month()}-{idx}" | ||
mock_dag_run.dag.dag_id = "digital_bookplate_979" | ||
mock_dag_run.conf = { | ||
"druids_for_instance_id": {id: {}} | ||
} | ||
mock_dag_run.conf = {"druids_for_instance_id": {id: {}}} | ||
mock_dag_run.get_task_instance = mock_get_task_instance | ||
mock_dag_runs.append(mock_dag_run) | ||
|
||
return mock_dag_runs | ||
|
||
|
||
def mock_xcom_pull(*args, **kwargs): | ||
return { | ||
uuids()[-1]: [ | ||
{ | ||
'fund_name': 'KLEINH', | ||
'druid': 'vy482pt7540', | ||
'image_filename': 'vy482pt7540_00_0001.jp2', | ||
'title': 'The Herbert A. Klein Book Fund' | ||
'fund_name': 'KLEINH', | ||
'druid': 'vy482pt7540', | ||
'image_filename': 'vy482pt7540_00_0001.jp2', | ||
'title': 'The Herbert A. Klein Book Fund', | ||
} | ||
] | ||
} | ||
|
@@ -64,6 +65,7 @@ def mock_xcom_pull(*args, **kwargs): | |
def mock_variable(monkeypatch): | ||
def mock_get(key, *args): | ||
return "[email protected]" | ||
|
||
monkeypatch.setattr(Variable, "get", mock_get) | ||
|
||
|
||
|
@@ -82,7 +84,7 @@ def test_find_failed_979_dags(mocker, caplog): | |
"libsys_airflow.plugins.digital_bookplates.dag_979_retries.DagRun.find", | ||
return_value=mock_dag_runs(), | ||
) | ||
|
||
failed_dags = failed_979_dags.function() | ||
assert len(failed_dags["digital_bookplate_979s"]) == 5 | ||
assert f"Found: scheduled__2024-{month()}-4" in caplog.text | ||
|
@@ -97,7 +99,7 @@ def test_run_failed_979_dags(mocker, mock_variable, mock_dag_bag, caplog): | |
"libsys_airflow.plugins.digital_bookplates.bookplates.DagBag", | ||
return_value=mock_dag_bag, | ||
) | ||
|
||
dag_runs = {"digital_bookplate_979s": mock_dag_runs()} | ||
run_failed_979_dags.function(dags=dag_runs) | ||
|
||
|