8000 Jac/smoke tests by jacalata · Pull Request #1115 · tableau/server-client-python · GitHub
[go: up one dir, main page]

Skip to content

Jac/smoke tests #1115

8000
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/pypi-smoke-tests.yml
10000
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will install TSC from pypi and validate that it runs. For more information see:
# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Pypi smoke tests

on:
workflow_dispatch:
schedule:
- cron: 0 11 * * * # Every day at 11AM UTC (7AM EST)

permissions:
contents: read

jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.x']

runs-on: ${{ matrix.os }}

steps:
- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: pip install
run: |
pip uninstall tableauserverclient
pip install tableauserverclient
- name: Launch app
run: |
python -c "import tableauserverclient as TSC
server = TSC.Server('http://example.com', use_server_version=False)"
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Tableau
Copyright (c) 2022 Tableau

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 8 additions & 0 deletions samples/smoke_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This sample verifies that tableau server client is installed
# and you can run it. It also shows the version of the client.

import tableauserverclient as TSC

server = TSC.Server("Fake-Server-Url", use_server_version=False)
print("Client details:")
print(TSC.server.endpoint.Endpoint._make_common_headers("fake-token", "any-content"))
1 change: 1 addition & 0 deletions tableauserverclient/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ._version import get_versions
from .namespace import NEW_NAMESPACE as DEFAULT_NAMESPACE
from .models import (
BackgroundJobItem,
Expand Down
38 changes: 20 additions & 18 deletions tableauserverclient/server/endpoint/endpoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import requests
import logging
from packaging.version import Version
from distutils.version import LooseVersion as Version
from functools import wraps
from xml.etree.ElementTree import ParseError
from typing import Any, Callable, Dict, Optional, TYPE_CHECKING
Expand All @@ -12,11 +12,11 @@
EndpointUnavailableError,
)
from ..query import QuerySet
from ... import helpers
from ..._version import get_versions
from ... import helpers, get_versions

__TSC_VERSION__ = get_versions()["version"]
del get_versions
if TYPE_CHECKING:
from ..server import Server
from requests import Response

logger = logging.getLogger("tableau.endpoint")

Expand All @@ -25,11 +25,10 @@
XML_CONTENT_TYPE = "text/xml"
JSON_CONTENT_TYPE = "application/json"

USERAGENT_HEADER = "User-Agent"

if TYPE_CHECKING:
from ..server import Server
from requests import Response
CONTENT_TYPE_HEADER = "content-type"
TABLEAU_AUTH_HEADER = "x-tableau-auth"
CLIENT_VERSION_HEADER = "X-TableauServerClient-Version"
USER_AGENT_HEADER = "User-Agent"


class Endpoint(object):
Expand All @@ -38,12 +37,13 @@ def __init__(self, parent_srv: "Server"):

@staticmethod
def _make_common_headers(auth_token, content_type):
_client_version: Optional[str] = get_versions()["version"]
headers = {}
if auth_token is not None:
headers["x-tableau-auth"] = auth_token
headers[TABLEAU_AUTH_HEADER] = auth_token
if content_type is not None:
headers["content-type"] = content_type
headers["User-Agent"] = "Tableau Server Client/{}".format(__TSC_VERSION__)
headers[CONTENT_TYPE_HEADER] = content_type
headers[USER_AGENT_HEADER] = "Tableau Server Client/{}".format(_client_version)
return headers

def _make_request(
Expand All @@ -56,9 +56,9 @@ def _make_request(
parameters: Optional[Dict[str, Any]] = None,
) -> "Response":
parameters = parameters or {}
parameters.update(self.parent_srv.http_options)
if "headers" not in parameters:
parameters["headers"] = {}
parameters.update(self.parent_srv.http_options)
parameters["headers"].update(Endpoint._make_common_headers(auth_token, content_type))

if content is not None:
Expand All @@ -83,12 +83,14 @@ def _check_status(self, server_response, url: str = None):
if server_response.status_code >= 500:
raise InternalServerError(server_response, url)
elif server_response.status_code not in Success_codes:
# todo: is an error reliably of content-type application/xml?
try:
raise ServerResponseError.from_response(server_response.content, self.parent_srv.namespace, url)
except ParseError:
# This will happen if we get a non-success HTTP code that doesn't return an xml error object
# e.g metadata endpoints, 503 pages, totally different servers
# we convert this to a better exception and pass through the raw response body
# This will happen if we get a non-success HTTP code that
# doesn't return an xml error object (like metadata endpoints or 503 pages)
# we convert this to a better exception and pass through the raw
# response body
raise NonXMLResponseError(server_response.content)
except Exception:
# anything else re-raise here
Expand Down Expand Up @@ -186,7 +188,7 @@ def api(version):
def _decorator(func):
@wraps(func)
def wrapper(self, *args, **kwargs):
self.parent_srv.assert_at_least_version(version, self.__class__.__name__)
self.parent_srv.assert_at_least_version(version, "endpoint")
return func(self, *args, **kwargs)

return wrapper
Expand Down
Empty file modified versioneer.py
100755 → 100644
Empty file.
0