Skip to content

Commit b351b89

Browse files
jorwoodst8y8jacalata
committed
Jorwoods/type hint flow runs (#950)
* Fix slack once and for all (#946) The red X keeps coming back so I'd like to mark this as allowably fail-able -- that way the innards of Slack/OAuth/Tableau credentials don't keep polluting test run reports :) (cherry picked from commit c8170ae) * Type hint Flow run item * Continue on error for slack step * Fix formatting Co-authored-by: Tyler Doyle <[email protected]> Co-authored-by: Jac <[email protected]>
1 parent 5565a36 commit b351b89

File tree

3 files changed

+41
-29
lines changed

3 files changed

+41
-29
lines changed

tableauserverclient/models/flow_run_item.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,48 @@
22
from ..datetime_helpers import parse_datetime
33
import itertools
44

5+
from typing import Dict, List, Optional, Type, TYPE_CHECKING
6+
7+
if TYPE_CHECKING:
8+
from datetime import datetime
9+
510

611
class FlowRunItem(object):
712
def __init__(self) -> None:
8-
self._id = None
9-
self._flow_id = None
10-
self._status = None
11-
self._started_at = None
12-
self._completed_at = None
13-
self._progress = None
14-
self._background_job_id = None
13+
self._id: str = ""
14+
self._flow_id: Optional[str] = None
15+
self._status: Optional[str] = None
16+
self._started_at: Optional["datetime"] = None
17+
self._completed_at: Optional["datetime"] = None
18+
self._progress: Optional[str] = None
19+
self._background_job_id: Optional[str] = None
1520

1621
@property
17-
def id(self):
22+
def id(self) -> str:
1823
return self._id
1924

2025
@property
21-
def flow_id(self):
26+
def flow_id(self) -> Optional[str]:
2227
return self._flow_id
2328

2429
@property
25-
def status(self):
30+
def status(self) -> Optional[str]:
2631
return self._status
2732

2833
@property
29-
def started_at(self):
34+
def started_at(self) -> Optional["datetime"]:
3035
return self._started_at
3136

3237
@property
33-
def completed_at(self):
38+
def completed_at(self) -> Optional["datetime"]:
3439
return self._completed_at
3540

3641
@property
37-
def progress(self):
42+
def progress(self) -> Optional[str]:
3843
return self._progress
3944

4045
@property
41-
def background_job_id(self):
46+
def background_job_id(self) -> Optional[str]:
4247
return self._background_job_id
4348

4449
def _set_values(
@@ -67,7 +72,7 @@ def _set_values(
6772
self._background_job_id = background_job_id
6873

6974
@classmethod
70-
def from_response(cls, resp, ns):
75+
def from_response(cls: Type["FlowRunItem"], resp: bytes, ns: Optional[Dict]) -> List["FlowRunItem"]:
7176
all_flowrun_items = list()
7277
parsed_response = ET.fromstring(resp)
7378
all_flowrun_xml = itertools.chain(

tableauserverclient/server/endpoint/flow_runs_endpoint.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,27 @@
55

66
import logging
77

8+
from typing import List, Optional, Tuple, TYPE_CHECKING, Union
9+
810
logger = logging.getLogger("tableau.endpoint.flowruns")
911

12+
if TYPE_CHECKING:
13+
from ..server import Server
14+
from ..request_options import RequestOptions
15+
1016

1117
class FlowRuns(QuerysetEndpoint):
12-
def __init__(self, parent_srv):
18+
def __init__(self, parent_srv: "Server") -> None:
1319
super(FlowRuns, self).__init__(parent_srv)
20+
return None
1421

1522
@property
16-
def baseurl(self):
23+
def baseurl(self) -> str:
1724
return "{0}/sites/{1}/flows/runs".format(self.parent_srv.baseurl, self.parent_srv.site_id)
1825

1926
# Get all flows
2027
@api(version="3.10")
21-
def get(self, req_options=None):
28+
def get(self, req_options: Optional["RequestOptions"] = None) -> Tuple[List[FlowRunItem], PaginationItem]:
2229
logger.info("Querying all flow runs on site")
2330
url = self.baseurl
2431
server_response = self.get_request(url, req_options)
@@ -28,7 +35,7 @@ def get(self, req_options=None):
2835

2936
# Get 1 flow by id
3037
@api(version="3.10")
31-
def get_by_id(self, flow_run_id):
38+
def get_by_id(self, flow_run_id: str) -> FlowRunItem:
3239
if not flow_run_id:
3340
error = "Flow ID undefined."
3441
raise ValueError(error)
@@ -39,7 +46,7 @@ def get_by_id(self, flow_run_id):
3946

4047
# Cancel 1 flow run by id
4148
@api(version="3.10")
42-
def cancel(self, flow_run_id):
49+
def cancel(self, flow_run_id: str) -> None:
4350
if not flow_run_id:
4451
error = "Flow ID undefined."
4552
raise ValueError(error)
@@ -49,7 +56,7 @@ def cancel(self, flow_run_id):
4956
logger.info("Deleted single flow (ID: {0})".format(id_))
5057

5158
@api(version="3.10")
52-
def wait_for_job(self, flow_run_id, *, timeout=None):
59+
def wait_for_job(self, flow_run_id: str, *, timeout: Optional[int] = None) -> FlowRunItem:
5360
if isinstance(flow_run_id, FlowRunItem):
5461
flow_run_id = flow_run_id.id
5562
assert isinstance(flow_run_id, str)

test/test_flowruns.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
class FlowRunTests(unittest.TestCase):
18-
def setUp(self):
18+
def setUp(self) -> None:
1919
self.server = TSC.Server("http://test")
2020

2121
# Fake signin
@@ -25,7 +25,7 @@ def setUp(self):
2525

2626
self.baseurl = self.server.flow_runs.baseurl
2727

28-
def test_get(self):
28+
def test_get(self) -> None:
2929
response_xml = read_xml_asset(GET_XML)
3030
with requests_mock.mock() as m:
3131
m.get(self.baseurl, text=response_xml)
@@ -46,7 +46,7 @@ def test_get(self):
4646
self.assertEqual("100", all_flow_runs[1].progress)
4747
self.assertEqual("1ad21a9d-2530-4fbf-9064-efd3c736e023", all_flow_runs[1].background_job_id)
4848

49-
def test_get_by_id(self):
49+
def test_get_by_id(self) -> None:
5050
response_xml = read_xml_asset(GET_BY_ID_XML)
5151
with requests_mock.mock() as m:
5252
m.get(self.baseurl + "/cc2e652d-4a9b-4476-8c93-b238c45db968", text=response_xml)
@@ -59,19 +59,19 @@ def test_get_by_id(self):
5959
self.assertEqual("100", flow_run.progress)
6060
self.assertEqual("1ad21a9d-2530-4fbf-9064-efd3c736e023", flow_run.background_job_id)
6161

62-
def test_cancel_id(self):
62+
def test_cancel_id(self) -> None:
6363
with requests_mock.mock() as m:
6464
m.put(self.baseurl + "/ee8c6e70-43b6-11e6-af4f-f7b0d8e20760", status_code=204)
6565
self.server.flow_runs.cancel("ee8c6e70-43b6-11e6-af4f-f7b0d8e20760")
6666

67-
def test_cancel_item(self):
67+
def test_cancel_item(self) -> None:
6868
run = TSC.FlowRunItem()
6969
run._id = "ee8c6e70-43b6-11e6-af4f-f7b0d8e20760"
7070
with requests_mock.mock() as m:
7171
m.put(self.baseurl + "/ee8c6e70-43b6-11e6-af4f-f7b0d8e20760", status_code=204)
7272
self.server.flow_runs.cancel(run)
7373

74-
def test_wait_for_job_finished(self):
74+
def test_wait_for_job_finished(self) -> None:
7575
# Waiting for an already finished job, directly returns that job's info
7676
response_xml = read_xml_asset(GET_BY_ID_XML)
7777
flow_run_id = "cc2e652d-4a9b-4476-8c93-b238c45db968"
@@ -82,7 +82,7 @@ def test_wait_for_job_finished(self):
8282
self.assertEqual(flow_run_id, flow_run.id)
8383
self.assertEqual(flow_run.progress, "100")
8484

85-
def test_wait_for_job_failed(self):
85+
def test_wait_for_job_failed(self) -> None:
8686
# Waiting for a failed job raises an exception
8787
response_xml = read_xml_asset(GET_BY_ID_FAILED_XML)
8888
flow_run_id = "c2b35d5a-e130-471a-aec8-7bc5435fe0e7"
@@ -91,7 +91,7 @@ def test_wait_for_job_failed(self):
9191
with self.assertRaises(FlowRunFailedException):
9292
self.server.flow_runs.wait_for_job(flow_run_id)
9393

94-
def test_wait_for_job_timeout(self):
94+
def test_wait_for_job_timeout(self) -> None:
9595
# Waiting for a job which doesn't terminate will throw an exception
9696
response_xml = read_xml_asset(GET_BY_ID_INPROGRESS_XML)
9797
flow_run_id = "71afc22c-9c06-40be-8d0f-4c4166d29e6c"

0 commit comments

Comments
 (0)