2021-10-13 19:36:37 +00:00
|
|
|
from tests.base_test import BaseTest
|
2021-10-14 15:02:51 +00:00
|
|
|
from crc.scripts.get_localtime import GetLocaltime
|
2021-10-20 16:16:18 +00:00
|
|
|
import dateparser
|
2021-11-03 12:36:24 +00:00
|
|
|
import datetime
|
2021-10-13 19:36:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestGetLocaltime(BaseTest):
|
|
|
|
|
|
|
|
def test_get_localtime(self):
|
|
|
|
self.load_example_data()
|
|
|
|
|
2021-11-03 12:36:24 +00:00
|
|
|
timestamp = datetime.datetime.utcnow()
|
2021-10-13 19:36:37 +00:00
|
|
|
workflow = self.create_workflow('get_localtime')
|
2021-11-03 12:36:24 +00:00
|
|
|
|
|
|
|
workflow_api = self.get_workflow_api(workflow)
|
|
|
|
task = workflow_api.next_task
|
|
|
|
|
|
|
|
workflow_api = self.complete_form(workflow, task, {'with_timestamp': True,
|
|
|
|
'with_timezone': False,
|
|
|
|
'timestamp': str(timestamp)})
|
|
|
|
task = workflow_api.next_task
|
|
|
|
|
|
|
|
# The workflow calls get_localtime twice, once with named arguments and once without
|
|
|
|
localtime_with = task.data['localtime_with']
|
|
|
|
localtime_without = task.data['localtime_without']
|
|
|
|
|
|
|
|
self.assertEqual(dateparser.parse(localtime_with), GetLocaltime().do_task(None, None, None, timestamp=str(timestamp)))
|
|
|
|
self.assertEqual(dateparser.parse(localtime_without), GetLocaltime().do_task(None, None, None, str(timestamp)))
|
|
|
|
|
|
|
|
def test_get_localtime_with_timezone(self):
|
|
|
|
self.load_example_data()
|
|
|
|
|
|
|
|
timestamp = datetime.datetime.utcnow()
|
|
|
|
workflow = self.create_workflow('get_localtime')
|
|
|
|
|
2021-10-13 19:36:37 +00:00
|
|
|
workflow_api = self.get_workflow_api(workflow)
|
|
|
|
task = workflow_api.next_task
|
|
|
|
|
2021-11-03 12:36:24 +00:00
|
|
|
workflow_api = self.complete_form(workflow, task, {'with_timestamp': True,
|
|
|
|
'with_timezone': True,
|
|
|
|
'timestamp': str(timestamp),
|
|
|
|
'timezone': 'US/Eastern'})
|
|
|
|
task = workflow_api.next_task
|
|
|
|
|
|
|
|
# The workflow calls get_localtime twice, once with named arguments and once without
|
|
|
|
localtime_with = task.data['localtime_with']
|
|
|
|
localtime_without = task.data['localtime_without']
|
|
|
|
|
|
|
|
self.assertEqual(dateparser.parse(localtime_with), GetLocaltime().do_task(None, None, None, timestamp=str(timestamp), timezone='US/Eastern'))
|
|
|
|
self.assertEqual(dateparser.parse(localtime_without), GetLocaltime().do_task(None, None, None, str(timestamp), 'US/Eastern'))
|
|
|
|
|
|
|
|
def test_get_localtime_no_timestamp(self):
|
|
|
|
workflow = self.create_workflow('get_localtime')
|
|
|
|
|
|
|
|
workflow_api = self.get_workflow_api(workflow)
|
|
|
|
task = workflow_api.next_task
|
2021-10-13 19:36:37 +00:00
|
|
|
|
2021-11-03 12:36:24 +00:00
|
|
|
with self.assertRaises(AssertionError):
|
|
|
|
self.complete_form(workflow, task, {'with_timestamp': False, 'with_timezone': False})
|