From 1c418a01543f89ce93de6e0ebb620594a3a4cfd5 Mon Sep 17 00:00:00 2001 From: Chris Shin Date: Thu, 11 Feb 2021 10:49:06 -0800 Subject: [PATCH 1/3] Adds task type mapping to translate server response --- tableauserverclient/models/task_item.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tableauserverclient/models/task_item.py b/tableauserverclient/models/task_item.py index 2f3e6f3aa..17d62e096 100644 --- a/tableauserverclient/models/task_item.py +++ b/tableauserverclient/models/task_item.py @@ -9,6 +9,10 @@ class Type: ExtractRefresh = "extractRefresh" DataAcceleration = "dataAcceleration" + # This mapping is used to convert task type returned from server + _TASK_TYPE_MAPPING = {'RefreshExtractTask': Type.ExtractRefresh, + 'MaterializeViewsTask': Type.DataAcceleration} + def __init__(self, id_, task_type, priority, consecutive_failed_count=0, schedule_id=None, schedule_item=None, last_run_at=None, target=None): self.id = id_ @@ -58,9 +62,19 @@ def _parse_element(cls, element, ns): if last_run_at_element is not None: last_run_at = parse_datetime(last_run_at_element.text) - task_type = element.get('type', None) + # Server response has different names for task types + task_type = cls._translate_task_type(element.get('type', None)) + priority = int(element.get('priority', -1)) consecutive_failed_count = int(element.get('consecutiveFailedCount', 0)) id_ = element.get('id', None) return cls(id_, task_type, priority, consecutive_failed_count, schedule_item.id, schedule_item, last_run_at, target) + + @staticmethod + def _translate_task_type(task_type): + if task_type in TaskItem._TASK_TYPE_MAPPING: + return TaskItem._TASK_TYPE_MAPPING[task_type] + else: + return task_type + From ede8e836567543e87b52fd13ac617049f009d81f Mon Sep 17 00:00:00 2001 From: Chris Shin Date: Thu, 11 Feb 2021 19:44:15 -0800 Subject: [PATCH 2/3] Updates tests to match server response for task type --- test/assets/tasks_no_workbook_or_datasource.xml | 6 +++--- test/assets/tasks_with_dataacceleration_task.xml | 2 +- test/assets/tasks_with_datasource.xml | 2 +- test/assets/tasks_with_workbook.xml | 2 +- test/assets/tasks_with_workbook_and_datasource.xml | 6 +++--- test/test_task.py | 2 ++ 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/test/assets/tasks_no_workbook_or_datasource.xml b/test/assets/tasks_no_workbook_or_datasource.xml index 7ddbcae62..da84194bf 100644 --- a/test/assets/tasks_no_workbook_or_datasource.xml +++ b/test/assets/tasks_no_workbook_or_datasource.xml @@ -4,17 +4,17 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-2.6.xsd"> - + - + - + diff --git a/test/assets/tasks_with_dataacceleration_task.xml b/test/assets/tasks_with_dataacceleration_task.xml index cbe837405..beb5d59eb 100644 --- a/test/assets/tasks_with_dataacceleration_task.xml +++ b/test/assets/tasks_with_dataacceleration_task.xml @@ -2,7 +2,7 @@ - + diff --git a/test/assets/tasks_with_datasource.xml b/test/assets/tasks_with_datasource.xml index 68e23a417..097161bf7 100644 --- a/test/assets/tasks_with_datasource.xml +++ b/test/assets/tasks_with_datasource.xml @@ -4,7 +4,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-2.6.xsd"> - + diff --git a/test/assets/tasks_with_workbook.xml b/test/assets/tasks_with_workbook.xml index 1565abf74..81e974e78 100644 --- a/test/assets/tasks_with_workbook.xml +++ b/test/assets/tasks_with_workbook.xml @@ -4,7 +4,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-2.6.xsd"> - + diff --git a/test/assets/tasks_with_workbook_and_datasource.xml b/test/assets/tasks_with_workbook_and_datasource.xml index 4389fa06c..81777bb46 100644 --- a/test/assets/tasks_with_workbook_and_datasource.xml +++ b/test/assets/tasks_with_workbook_and_datasource.xml @@ -4,19 +4,19 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-2.6.xsd"> - + - + - + diff --git a/test/test_task.py b/test/test_task.py index 789f97187..566167d4a 100644 --- a/test/test_task.py +++ b/test/test_task.py @@ -104,6 +104,7 @@ def test_get_materializeviews_tasks(self): self.assertEqual('b22190b4-6ac2-4eed-9563-4afc03444413', task.schedule_id) self.assertEqual(parse_datetime('2019-12-09T22:30:00Z'), task.schedule_item.next_run_at) self.assertEqual(parse_datetime('2019-12-09T20:45:04Z'), task.last_run_at) + self.assertEqual(TSC.TaskItem.Type.DataAcceleration, task.task_type) def test_delete_data_acceleration(self): with requests_mock.mock() as m: @@ -124,6 +125,7 @@ def test_get_by_id(self): self.assertEqual('c7a9327e-1cda-4504-b026-ddb43b976d1d', task.target.id) self.assertEqual('workbook', task.target.type) self.assertEqual('b60b4efd-a6f7-4599-beb3-cb677e7abac1', task.schedule_id) + self.assertEqual(TSC.TaskItem.Type.ExtractRefresh, task.task_type) def test_run_now(self): task_id = 'f84901ac-72ad-4f9b-a87e-7a3500402ad6' From 71f91b9ceb531ae68da1b7ed86bba0c4764f385c Mon Sep 17 00:00:00 2001 From: Chris Shin Date: Thu, 11 Feb 2021 19:55:37 -0800 Subject: [PATCH 3/3] Fixes pycodestyle error --- tableauserverclient/models/task_item.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tableauserverclient/models/task_item.py b/tableauserverclient/models/task_item.py index 17d62e096..27d26f215 100644 --- a/tableauserverclient/models/task_item.py +++ b/tableauserverclient/models/task_item.py @@ -77,4 +77,3 @@ def _translate_task_type(task_type): return TaskItem._TASK_TYPE_MAPPING[task_type] else: return task_type -