-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into 1304-improve-pager-error-handling
- Loading branch information
Showing
10 changed files
with
178 additions
and
2 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import logging | ||
from typing import List, Optional, Tuple, TYPE_CHECKING | ||
|
||
from tableauserverclient.server.endpoint.endpoint import Endpoint, api | ||
from tableauserverclient.server.endpoint.exceptions import MissingRequiredFieldError | ||
from tableauserverclient.models import TaskItem, PaginationItem | ||
from tableauserverclient.server import RequestFactory | ||
|
||
from tableauserverclient.helpers.logging import logger | ||
|
||
if TYPE_CHECKING: | ||
from tableauserverclient.server.request_options import RequestOptions | ||
|
||
|
||
class FlowTasks(Endpoint): | ||
@property | ||
def baseurl(self) -> str: | ||
return "{0}/sites/{1}/tasks/flows".format(self.parent_srv.baseurl, self.parent_srv.site_id) | ||
|
||
@api(version="3.22") | ||
def create(self, flow_item: TaskItem) -> TaskItem: | ||
if not flow_item: | ||
error = "No flow provided" | ||
raise ValueError(error) | ||
logger.info("Creating an flow task %s", flow_item) | ||
url = self.baseurl | ||
create_req = RequestFactory.FlowTask.create_flow_task_req(flow_item) | ||
server_response = self.post_request(url, create_req) | ||
return server_response.content |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api https://help.tableau.com/samples/en-us/rest_api/ts-api_3_22.xsd"> | ||
<task> | ||
<flowRun id="flow_run_id" | ||
priority="50" | ||
consecutiveFailedCount="0" | ||
type="RunFlowTask"> | ||
<schedule id="schedule_id" | ||
name="schedu;e_name" | ||
state="Active" | ||
priority="50" | ||
createdAt="2024-04-09T18:54:12Z" | ||
updatedAt="2024-04-09T18:54:12Z" | ||
type="Flow" | ||
frequency="Daily" | ||
nextRunAt="2024-04-10T19:30:00Z"/> | ||
<flow id="flow_id" | ||
name="olympic 1"> | ||
</flow> | ||
<flowRunSpec flowId="flow_id"> | ||
<flowOutputSteps> | ||
<flowOutputStep id="flow_output_setp_id" | ||
name="Output"/> | ||
</flowOutputSteps> | ||
<flowParameterSpecs/> | ||
</flowRunSpec> | ||
</flowRun> | ||
</task> | ||
</tsResponse> |
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,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("{}".format(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) |
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