8000 Add custom session injection, Fix bug for http_options (#1119) · Gbagade02/server-client-python@ef9e7fd · GitHub
[go: up one dir, main page]

Skip to content

Commit ef9e7fd

Browse files
jacalataMrwanBaghdadjorwoodsbcantoni
authored
Add custom session injection, Fix bug for http_options (tableau#1119)
* ssl-verify is an option, not a header * Allow injection of session_factory to allow use of a custom session * show server info (tableau#1118) * Fix bug in exposing ExcelRequestOptions and test (tableau#1123) * Fix a few pylint errors (tableau#1124) Co-authored-by: Marwan Baghdad <mrwanbaghdad76@gmail.com> Co-authored-by: jorwoods <jorwoods@users.noreply.github.com> Co-authored-by: Brian Cantoni <bcantoni@salesforce.com>
1 parent f653e15 commit ef9e7fd

17 files changed

+174
-69
lines changed

contributing.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,22 @@ pytest
6666
pip install .
6767
```
6868

69+
### Debugging Tools
70+
See what your outgoing requests look like: https://requestbin.net/ (unaffiliated link not under our control)
71+
72+
6973
### Before Committing
7074

7175
Our CI runs include a Python lint run, so you should run this locally and fix complaints before committing as this will fail your checkin.
7276

7377
```shell
7478
# this will run the formatter without making changes
75-
black --line-length 120 tableauserverclient test samples --check
79+
black . --check
7680

7781
# this will format the directory and code for you
78-
black --line-length 120 tableauserverclient test samples
82+
black .
7983

8084
# this will run type checking
8185
pip install mypy
82-
mypy --show-error-codes --disable-error-code misc --disable-error-code import tableauserverclient test
86+
mypy tableauserverclient test samples
8387
```

samples/create_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def main():
4646
logging.basicConfig(level=logging_level)
4747

4848
tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
49-
server = TSC.Server(args.server, use_server_version=True)
49+
server = TSC.Server(args.server, use_server_version=True, http_options={"verify": False})
5050
with server.auth.sign_in(tableau_auth):
5151
# this code shows 3 different error codes that mean "resource is already in collection"
5252
# 409009: group already exists on server

samples/initialize_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ def main():
5656

5757
# Create the site if it doesn't exist
5858
if existing_site is None:
59-
print("Site not found: {0} Creating it...").format(args.site_id)
59+
print("Site not found: {0} Creating it...".format(args.site_id))
6060
new_site = TSC.SiteItem(
6161
name=args.site_id,
6262
content_url=args.site_id.replace(" ", ""),
6363
admin_mode=TSC.SiteItem.AdminMode.ContentAndUsers,
6464
)
6565
server.sites.create(new_site)
6666
else:
67-
print("Site {0} exists. Moving on...").format(args.site_id)
67+
print("Site {0} exists. Moving on...".format(args.site_id))
6868

6969
################################################################################
7070
# Step 3: Sign-in to our target site
@@ -87,7 +87,7 @@ def main():
8787

8888
# Create our project if it doesn't exist
8989
if project is None:
90-
print("Project not found: {0} Creating it...").format(args.project)
90+
print("Project not found: {0} Creating it...".format(args.project))
9191
new_project = TSC.ProjectItem(name=args.project)
9292
project = server_upload.projects.create(new_project)
9393

tableauserverclient/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
)
4040
from .server import (
4141
CSVRequestOptions,
42+
ExcelRequestOptions,
4243
ImageRequestOptions,
4344
PDFRequestOptions,
4445
RequestOptions,

tableauserverclient/models/flow_item.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ def description(self, value: str) -> None:
9393
def project_name(self) -> Optional[str]:
9494
return self._project_name
9595

96-
@property
97-
def flow_type(self): # What is this? It doesn't seem to get set anywhere.
98-
return self._flow_type
99-
10096
@property
10197
def updated_at(self) -> Optional["datetime.datetime"]:
10298
return self._updated_at

tableauserverclient/models/permissions_item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def from_response(cls, resp, ns=None) -> List["PermissionsRule"]:
6969
mode = capability_xml.get("mode")
7070

7171
if name is None or mode is None:
72-
logger.error("Capability was not valid: ", capability_xml)
72+
logger.error("Capability was not valid: {}".format(capability_xml))
7373
raise UnpopulatedPropertyError()
7474
else:
7575
capability_dict[name] = mode

tableauserverclient/models/revision_item.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ def user_name(self) -> Optional[str]:
5353

5454
def __repr__(self):
5555
return (
56-
"<RevisionItem# revisionNumber={_revision_number} " "current={_current} deleted={_deleted} user={_user_id}>"
57-
).format(**self.__dict__)
56+
"<RevisionItem# revisionNumber={_revision_number} "
57+
"current={_current} deleted={_deleted} user={_user_id}>".format(**self.__dict__)
58+
)
5859

5960
@classmethod
6061
def from_response(cls, resp: bytes, ns, resource_item) -> List["RevisionItem"]:

tableauserverclient/models/server_info_item.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import warnings
2+
import xml
3+
14
from defusedxml.ElementTree import fromstring
25

36

@@ -32,7 +35,11 @@ def rest_api_version(self):
3235

3336
@classmethod
3437
def from_response(cls, resp, ns):
35-
parsed_response = fromstring(resp)
38+
try:
39+
parsed_response = fromstring(resp)
40+
except xml.etree.ElementTree.ParseError as error:
41+
warnings.warn("Unexpected response for ServerInfo: {}".format(resp))
42+
return cls("Unknown", "Unknown", "Unknown")
3643
product_version_tag = parsed_response.find(".//t:productVersion", namespaces=ns)
3744
rest_api_version_tag = parsed_response.find(".//t:restApiVersion", namespaces=ns)
3845

tableauserverclient/models/site_item.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import warnings
22
import xml.etree.ElementTree as ET
33

4-
from distutils.version import Version
54
from defusedxml.ElementTree import fromstring
65
from .property_decorators import (
76
property_is_enum,

tableauserverclient/models/tableau_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def credentials(self):
99
+"This method returns values to set as an attribute on the credentials element of the request"
1010

1111
def __repr__(self):
12-
display = "All Credentials types must have a debug display that does not print secrets"
12+
return "All Credentials types must have a debug display that does not print secrets"
1313

1414

1515
def deprecate_site_attribute():

0 commit comments

Comments
 (0)
0