-
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.
LITE-29732 Add endpoint to retrieve upload shcedule task information
- Loading branch information
Showing
11 changed files
with
119 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
Empty file.
Empty file.
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,18 @@ | ||
from typing import Any, Dict | ||
|
||
from connect_extension_utils.api.schemas import Events, NonNullSchema | ||
|
||
|
||
_DictAny = Dict[Any, Any] | ||
|
||
|
||
class EaasScheduleTaskSchema(NonNullSchema): | ||
id: str | ||
name: str | ||
description: str | ||
method: str | ||
parameter: _DictAny | ||
trigger: _DictAny | ||
environment: _DictAny | ||
events: Events | ||
status: str |
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,37 @@ | ||
|
||
from logging import Logger | ||
|
||
from connect.client import ConnectClient | ||
from connect.eaas.core.decorators import router | ||
from connect.eaas.core.inject.common import get_call_context, get_logger | ||
from connect.eaas.core.inject.models import Context | ||
from connect.eaas.core.inject.synchronous import get_installation_client | ||
from connect_extension_utils.api.errors import Http404 | ||
from fastapi import Depends, status | ||
|
||
from connect_bi_reporter.constants import CREATE_UPLOADS_METHOD_NAME | ||
from connect_bi_reporter.settings.api.schemas import EaasScheduleTaskSchema | ||
from connect_bi_reporter.scheduler import Scheduler | ||
|
||
|
||
class SettingsWebAppMixin: | ||
|
||
@router.get( | ||
'/settings/schedule-tasks/create-uploads', | ||
summary='Returns the Schedule Task named `create_uploads`', | ||
response_model=EaasScheduleTaskSchema, | ||
status_code=status.HTTP_200_OK, | ||
) | ||
def get_create_upload_task_info( | ||
self, | ||
client: ConnectClient = Depends(get_installation_client), | ||
context: Context = Depends(get_call_context), | ||
logger: Logger = Depends(get_logger), | ||
): | ||
scheduler = Scheduler(client, context, logger) | ||
|
||
task = scheduler.get_schedule_task_by_method_name(CREATE_UPLOADS_METHOD_NAME) | ||
|
||
if not task: | ||
raise Http404(obj_id=CREATE_UPLOADS_METHOD_NAME) | ||
return EaasScheduleTaskSchema(**task) |
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
Empty file.
Empty file.
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,8 @@ | ||
import json | ||
|
||
from connect_bi_reporter.settings.api.schemas import EaasScheduleTaskSchema | ||
|
||
|
||
def test_eaas_schema(eaas_schedule_task): | ||
task = EaasScheduleTaskSchema(**eaas_schedule_task) | ||
assert task.json() == json.dumps(eaas_schedule_task) |
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,42 @@ | ||
def test_get_create_upload_task( | ||
api_client, | ||
mocker, | ||
eaas_schedule_task, | ||
): | ||
mocker.patch( | ||
'connect_bi_reporter.scheduler.get_schedule_tasks', | ||
return_value=[eaas_schedule_task], | ||
) | ||
|
||
response = api_client.get( | ||
'/api/settings/schedule-tasks/create-uploads', | ||
) | ||
|
||
assert response.status_code == 200 | ||
|
||
response_data = response.json() | ||
|
||
assert response_data == eaas_schedule_task | ||
|
||
|
||
def test_get_create_upload_task_not_found( | ||
api_client, | ||
mocker, | ||
): | ||
mocker.patch( | ||
'connect_bi_reporter.scheduler.get_schedule_tasks', | ||
return_value=[], | ||
) | ||
|
||
response = api_client.get( | ||
'/api/settings/schedule-tasks/create-uploads', | ||
) | ||
|
||
assert response.status_code == 404 | ||
|
||
response_data = response.json() | ||
|
||
assert response_data == { | ||
'error_code': 'NFND_000', | ||
'errors': ['Object `create_uploads` not found.'], | ||
} |