Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew Meyers committed May 10, 2024
1 parent d555a0b commit a9e6887
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 106 deletions.
1 change: 0 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,6 @@ def status(
"""
job = check_job_integrity(db, job_id, new_job=False)
job = StatusInfo.model_validate(job)

ems_api_auth = HTTPBasicAuth(settings.ems_api_auth_username, settings.ems_api_auth_password)
try:
response = requests.get(
Expand Down
281 changes: 176 additions & 105 deletions unity-test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,71 +67,141 @@ def client():
def mock_get_existing_dag(requests_mock):
return requests_mock.get(
re.compile(f"{settings.ems_api_url}/dags/([^/]*)$"),
json={
"dag_id": "string",
"dag_display_name": "string",
"root_dag_id": "string",
"is_paused": True,
"is_active": True,
"is_subdag": True,
"last_parsed_time": "2019-08-24T14:15:22.548326+00:00",
"last_pickled": "2019-08-24T14:15:22.548326+00:00",
"last_expired": "2019-08-24T14:15:22.548326+00:00",
"scheduler_lock": True,
"pickle_id": "string",
"default_view": "string",
"fileloc": "string",
"file_token": "string",
"owners": ["string"],
"description": "string",
"schedule_interval": {"__type": "string", "days": 0, "seconds": 0, "microseconds": 0},
"timetable_description": "string",
"tags": [{"name": "string"}],
"max_active_tasks": 0,
"max_active_runs": 0,
"has_task_concurrency_limits": True,
"has_import_errors": True,
"next_dagrun": "2019-08-24T14:15:22.548326+00:00",
"next_dagrun_data_interval_start": "2019-08-24T14:15:22.548326+00:00",
"next_dagrun_data_interval_end": "2019-08-24T14:15:22.548326+00:00",
"next_dagrun_create_after": "2019-08-24T14:15:22.548326+00:00",
},
[
{
"json": {
"dag_id": "string",
"dag_display_name": "string",
"root_dag_id": "string",
"is_paused": False,
"is_active": True,
"is_subdag": True,
"last_parsed_time": "2019-08-24T14:15:22.548326+00:00",
"last_pickled": "2019-08-24T14:15:22.548326+00:00",
"last_expired": "2019-08-24T14:15:22.548326+00:00",
"scheduler_lock": True,
"pickle_id": "string",
"default_view": "string",
"fileloc": "string",
"file_token": "string",
"owners": ["string"],
"description": "string",
"schedule_interval": {"__type": "string", "days": 0, "seconds": 0, "microseconds": 0},
"timetable_description": "string",
"tags": [{"name": "string"}],
"max_active_tasks": 0,
"max_active_runs": 0,
"has_task_concurrency_limits": True,
"has_import_errors": True,
"next_dagrun": "2019-08-24T14:15:22.548326+00:00",
"next_dagrun_data_interval_start": "2019-08-24T14:15:22.548326+00:00",
"next_dagrun_data_interval_end": "2019-08-24T14:15:22.548326+00:00",
"next_dagrun_create_after": "2019-08-24T14:15:22.548326+00:00",
}
},
{
"json": {
"dag_id": "string",
"dag_display_name": "string",
"root_dag_id": "string",
"is_paused": True,
"is_active": False,
"is_subdag": True,
"last_parsed_time": "2019-08-24T14:15:22.548326+00:00",
"last_pickled": "2019-08-24T14:15:22.548326+00:00",
"last_expired": "2019-08-24T14:15:22.548326+00:00",
"scheduler_lock": True,
"pickle_id": "string",
"default_view": "string",
"fileloc": "string",
"file_token": "string",
"owners": ["string"],
"description": "string",
"schedule_interval": {"__type": "string", "days": 0, "seconds": 0, "microseconds": 0},
"timetable_description": "string",
"tags": [{"name": "string"}],
"max_active_tasks": 0,
"max_active_runs": 0,
"has_task_concurrency_limits": True,
"has_import_errors": True,
"next_dagrun": "2019-08-24T14:15:22.548326+00:00",
"next_dagrun_data_interval_start": "2019-08-24T14:15:22.548326+00:00",
"next_dagrun_data_interval_end": "2019-08-24T14:15:22.548326+00:00",
"next_dagrun_create_after": "2019-08-24T14:15:22.548326+00:00",
}
},
],
)


@pytest.fixture(scope="function", autouse=True)
def mock_patch_existing_dag(requests_mock):
return requests_mock.patch(
re.compile(f"{settings.ems_api_url}/dags/([^/]*)$"),
json={
"dag_id": "string",
"dag_display_name": "string",
"root_dag_id": "string",
"is_paused": True,
"is_active": True,
"is_subdag": True,
"last_parsed_time": "2019-08-24T14:15:22Z",
"last_pickled": "2019-08-24T14:15:22Z",
"last_expired": "2019-08-24T14:15:22Z",
"scheduler_lock": True,
"pickle_id": "string",
"default_view": "string",
"fileloc": "string",
"file_token": "string",
"owners": ["string"],
"description": "string",
"schedule_interval": {"__type": "string", "days": 0, "seconds": 0, "microseconds": 0},
"timetable_description": "string",
"tags": [{"name": "string"}],
"max_active_tasks": 0,
"max_active_runs": 0,
"has_task_concurrency_limits": True,
"has_import_errors": True,
"next_dagrun": "2019-08-24T14:15:22Z",
"next_dagrun_data_interval_start": "2019-08-24T14:15:22Z",
"next_dagrun_data_interval_end": "2019-08-24T14:15:22Z",
"next_dagrun_create_after": "2019-08-24T14:15:22Z",
},
[
{
"json": {
"dag_id": "string",
"dag_display_name": "string",
"root_dag_id": "string",
"is_paused": False,
"is_active": True,
"is_subdag": True,
"last_parsed_time": "2019-08-24T14:15:22Z",
"last_pickled": "2019-08-24T14:15:22Z",
"last_expired": "2019-08-24T14:15:22Z",
"scheduler_lock": True,
"pickle_id": "string",
"default_view": "string",
"fileloc": "string",
"file_token": "string",
"owners": ["string"],
"description": "string",
"schedule_interval": {"__type": "string", "days": 0, "seconds": 0, "microseconds": 0},
"timetable_description": "string",
"tags": [{"name": "string"}],
"max_active_tasks": 0,
"max_active_runs": 0,
"has_task_concurrency_limits": True,
"has_import_errors": True,
"next_dagrun": "2019-08-24T14:15:22Z",
"next_dagrun_data_interval_start": "2019-08-24T14:15:22Z",
"next_dagrun_data_interval_end": "2019-08-24T14:15:22Z",
"next_dagrun_create_after": "2019-08-24T14:15:22Z",
}
},
{
"json": {
"dag_id": "string",
"dag_display_name": "string",
"root_dag_id": "string",
"is_paused": True,
"is_active": False,
"is_subdag": True,
"last_parsed_time": "2019-08-24T14:15:22Z",
"last_pickled": "2019-08-24T14:15:22Z",
"last_expired": "2019-08-24T14:15:22Z",
"scheduler_lock": True,
"pickle_id": "string",
"default_view": "string",
"fileloc": "string",
"file_token": "string",
"owners": ["string"],
"description": "string",
"schedule_interval": {"__type": "string", "days": 0, "seconds": 0, "microseconds": 0},
"timetable_description": "string",
"tags": [{"name": "string"}],
"max_active_tasks": 0,
"max_active_runs": 0,
"has_task_concurrency_limits": True,
"has_import_errors": True,
"next_dagrun": "2019-08-24T14:15:22Z",
"next_dagrun_data_interval_start": "2019-08-24T14:15:22Z",
"next_dagrun_data_interval_end": "2019-08-24T14:15:22Z",
"next_dagrun_create_after": "2019-08-24T14:15:22Z",
}
},
],
)


Expand Down Expand Up @@ -273,63 +343,64 @@ def mock_get_existing_running_dag_dagrun_tasks(requests_mock):
return requests_mock.get(
re.compile(f"{settings.ems_api_url}/dags/([^/]*)/dagRuns/([^/]*)/taskInstances$"),
json={
"tasks": [
"task_instances": [
{
"class_ref": {"module_path": "string", "class_name": "string"},
"task_id": "string",
"task_display_name": "string",
"owner": "string",
"start_date": "2019-08-24T14:15:22Z",
"end_date": "2019-08-24T14:15:22Z",
"trigger_rule": "all_success",
"extra_links": [{"class_ref": {"module_path": "string", "class_name": "string"}}],
"depends_on_past": True,
"is_mapped": True,
"wait_for_downstream": True,
"retries": 0,
"queue": "string",
"dag_id": "string",
"dag_run_id": "string",
"execution_date": "string",
"start_date": "string",
"end_date": "string",
"duration": 0,
"state": None,
"try_number": 0,
"map_index": 0,
"max_tries": 0,
"hostname": "string",
"unixname": "string",
"pool": "string",
"pool_slots": 0,
"execution_timeout": {"__type": "string", "days": 0, "seconds": 0, "microseconds": 0},
"retry_delay": {"__type": "string", "days": 0, "seconds": 0, "microseconds": 0},
"retry_exponential_backoff": True,
"queue": "string",
"priority_weight": 0,
"weight_rule": "downstream",
"ui_color": "string",
"ui_fgcolor": "string",
"template_fields": ["string"],
"sub_dag": {
"operator": "string",
"queued_when": "string",
"pid": 0,
"executor_config": "string",
"sla_miss": {
"task_id": "string",
"dag_id": "string",
"dag_display_name": "string",
"root_dag_id": "string",
"is_paused": True,
"is_active": True,
"is_subdag": True,
"last_parsed_time": "2019-08-24T14:15:22Z",
"last_pickled": "2019-08-24T14:15:22Z",
"last_expired": "2019-08-24T14:15:22Z",
"scheduler_lock": True,
"pickle_id": "string",
"default_view": "string",
"fileloc": "string",
"file_token": "string",
"owners": ["string"],
"execution_date": "string",
"email_sent": True,
"timestamp": "string",
"description": "string",
"schedule_interval": {"__type": "string", "days": 0, "seconds": 0, "microseconds": 0},
"timetable_description": "string",
"tags": [{"name": "string"}],
"max_active_tasks": 0,
"max_active_runs": 0,
"has_task_concurrency_limits": True,
"has_import_errors": True,
"next_dagrun": "2019-08-24T14:15:22Z",
"next_dagrun_data_interval_start": "2019-08-24T14:15:22Z",
"next_dagrun_data_interval_end": "2019-08-24T14:15:22Z",
"next_dagrun_create_after": "2019-08-24T14:15:22Z",
"notification_sent": True,
},
"downstream_task_ids": ["string"],
"rendered_map_index": "string",
"rendered_fields": {},
"trigger": {
"id": 0,
"classpath": "string",
"kwargs": "string",
"created_date": "string",
"triggerer_id": 0,
},
"triggerer_job": {
"id": 0,
"dag_id": "string",
"state": "string",
"job_type": "string",
"start_date": "string",
"end_date": "string",
"latest_heartbeat": "string",
"executor_class": "string",
"hostname": "string",
"unixname": "string",
},
"note": "string",
}
]
],
"total_entries": 0,
},
)

Expand Down

0 comments on commit a9e6887

Please sign in to comment.