mypy
This commit is contained in:
parent
3471ab792a
commit
3e1d6773e5
|
@ -2,6 +2,7 @@ from flask_bpmn.api.api_error import ApiError
|
|||
|
||||
from spiffworkflow_backend.scripts.script import Script
|
||||
|
||||
from datetime import datetime
|
||||
import pytz
|
||||
|
||||
from typing import Any
|
||||
|
@ -12,7 +13,7 @@ from SpiffWorkflow.task import Task as SpiffTask # type: ignore
|
|||
|
||||
class GetLocaltime(Script):
|
||||
|
||||
def get_description(self):
|
||||
def get_description(self) -> str:
|
||||
return """Converts a Datetime object into a Datetime object for a specific timezone.
|
||||
Defaults to US/Eastern"""
|
||||
|
||||
|
@ -22,21 +23,21 @@ class GetLocaltime(Script):
|
|||
environment_identifier: str,
|
||||
*args: Any,
|
||||
**kwargs: Any
|
||||
):
|
||||
) -> datetime:
|
||||
if len(args) > 0 or 'datetime' in kwargs:
|
||||
if 'datetime' in kwargs:
|
||||
datetime = kwargs['datetime']
|
||||
date_time = kwargs['datetime']
|
||||
else:
|
||||
datetime = args[0]
|
||||
date_time = args[0]
|
||||
if 'timezone' in kwargs:
|
||||
timezone = kwargs['timezone']
|
||||
elif len(args) > 1:
|
||||
timezone = args[1]
|
||||
else:
|
||||
timezone = 'US/Eastern'
|
||||
localtime = datetime.astimezone(pytz.timezone(timezone))
|
||||
localtime: datetime = date_time.astimezone(pytz.timezone(timezone))
|
||||
return localtime
|
||||
|
||||
else:
|
||||
raise ApiError(status_code='missing_datetime',
|
||||
raise ApiError(error_code='missing_datetime',
|
||||
message='You must include a datetime to convert.')
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
from spiffworkflow_backend.services.process_instance_processor import ProcessInstanceProcessor
|
||||
from spiffworkflow_backend.services.process_instance_service import ProcessInstanceService
|
||||
from tests.spiffworkflow_backend.helpers.base_test import BaseTest
|
||||
from flask.app import Flask
|
||||
from flask.testing import FlaskClient
|
||||
from spiffworkflow_backend.models.user import UserModel
|
||||
from spiffworkflow_backend.scripts.get_localtime import GetLocaltime
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
from flask.app import Flask
|
||||
from flask.testing import FlaskClient
|
||||
|
||||
from spiffworkflow_backend.scripts.get_localtime import GetLocaltime
|
||||
from spiffworkflow_backend.services.process_instance_processor import ProcessInstanceProcessor
|
||||
from spiffworkflow_backend.services.process_instance_service import ProcessInstanceService
|
||||
|
||||
from tests.spiffworkflow_backend.helpers.base_test import BaseTest
|
||||
from tests.spiffworkflow_backend.helpers.test_data import load_test_spec
|
||||
|
||||
|
||||
class TestGetLocaltime(BaseTest):
|
||||
"""TestProcessAPi."""
|
||||
|
||||
def test_get_localtime_script_directly(self):
|
||||
def test_get_localtime_script_directly(self) -> None:
|
||||
current_time = datetime.datetime.now()
|
||||
timezone = "US/Pacific"
|
||||
result = GetLocaltime().run(task=None, environment_identifier='testing', datetime=current_time, timezone=timezone)
|
||||
|
@ -51,6 +52,7 @@ class TestGetLocaltime(BaseTest):
|
|||
active_task.task_name, processor.bpmn_process_instance
|
||||
)
|
||||
|
||||
assert spiff_task
|
||||
data = spiff_task.data
|
||||
some_time = data['some_time']
|
||||
localtime = data['localtime']
|
||||
|
|
Loading…
Reference in New Issue