forked from tableau/server-client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_flowtask.py
More file actions
47 lines (36 loc) · 1.67 KB
/
test_flowtask.py
File metadata and controls
47 lines (36 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import unittest
from datetime import time
from pathlib import Path
import requests_mock
import tableauserverclient as TSC
from tableauserverclient.datetime_helpers import parse_datetime
from tableauserverclient.models.task_item import TaskItem
TEST_ASSET_DIR = Path(__file__).parent / "assets"
GET_XML_CREATE_FLOW_TASK_RESPONSE = os.path.join(TEST_ASSET_DIR, "tasks_create_flow_task.xml")
class TaskTests(unittest.TestCase):
def setUp(self):
self.server = TSC.Server("http://test", False)
self.server.version = "3.22"
# Fake Signin
self.server._site_id = "dad65087-b08b-4603-af4e-2887b8aafc67"
self.server._auth_token = "j80k54ll2lfMZ0tv97mlPvvSCRyD0DOM"
self.baseurl = self.server.flow_tasks.baseurl
def test_create_flow_task(self):
monthly_interval = TSC.MonthlyInterval(start_time=time(23, 30), interval_value=15)
monthly_schedule = TSC.ScheduleItem(
"Monthly Schedule",
50,
TSC.ScheduleItem.Type.Flow,
TSC.ScheduleItem.ExecutionOrder.Parallel,
monthly_interval,
)
target_item = TSC.Target("flow_id", "flow")
task = TaskItem(None, "RunFlow", None, schedule_item=monthly_schedule, target=target_item)
with open(GET_XML_CREATE_FLOW_TASK_RESPONSE, "rb") as f:
response_xml = f.read().decode("utf-8")
with requests_mock.mock() as m:
m.post(f"{self.baseurl}", text=response_xml)
create_response_content = self.server.flow_tasks.create(task).decode("utf-8")
self.assertTrue("schedule_id" in create_response_content)
self.assertTrue("flow_id" in create_response_content)