-
Notifications
You must be signed in to change notification settings - Fork 436
initial checkin for get background jobs #298
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
graysonarts
merged 3 commits into
tableau:development
from
graysonarts:add-get-all-jobs
May 31, 2018
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -4,9 +4,15 @@ | |
from ..namespace import Namespace | ||
from .endpoint import Sites, Views, Users, Groups, Workbooks, Datasources, Projects, Auth, \ | ||
Schedules, ServerInfo, Tasks, ServerInfoEndpointNotFoundError, Subscriptions, Jobs | ||
from .endpoint.exceptions import EndpointUnavailableError | ||
|
||
import requests | ||
|
||
try: | ||
from distutils2.version import NormalizedVersion as Version | ||
except ImportError: | ||
from distutils.version import LooseVersion as Version | ||
|
||
_PRODUCT_TO_REST_VERSION = { | ||
'10.0': '2.3', | ||
'9.3': '2.2', | ||
|
@@ -94,6 +100,14 @@ def use_highest_version(self): | |
import warnings | ||
warnings.warn("use use_server_version instead", DeprecationWarning) | ||
|
||
def assert_at_least_version(self, version): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why move this to the server object itself? |
||
server_version = Version(self.version or "0.0") | ||
minimum_supported = Version(version) | ||
if server_version < minimum_supported: | ||
error = "This endpoint is not available in API version {}. Requires {}".format( | ||
server_version, minimum_supported) | ||
raise EndpointUnavailableError(error) | ||
|
||
@property | ||
def baseurl(self): | ||
return "{0}/api/{1}".format(self._server_address, str(self.version)) | ||
|
This file contains hidden or 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,10 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-3.1.xsd"> | ||
<pagination pageNumber="1" pageSize="100" totalAvailable="1"/> | ||
<backgroundJobs> | ||
<backgroundJob id="2eef4225-aa0c-41c4-8662-a76d89ed7336" status="Success" | ||
createdAt="2018-05-22T13:00:29Z" startedAt="2018-05-22T13:00:37Z" endedAt="2018-05-22T13:00:45Z" | ||
priority="50" jobType="single_subscription_notify"/> | ||
</backgroundJobs> | ||
</tsResponse> |
This file contains hidden or 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,45 @@ | ||
import unittest | ||
import os | ||
from datetime import datetime | ||
import requests_mock | ||
import tableauserverclient as TSC | ||
from tableauserverclient.datetime_helpers import utc | ||
|
||
TEST_ASSET_DIR = os.path.join(os.path.dirname(__file__), 'assets') | ||
|
||
GET_XML = os.path.join(TEST_ASSET_DIR, 'job_get.xml') | ||
|
||
|
||
class JobTests(unittest.TestCase): | ||
def setUp(self): | ||
self.server = TSC.Server('http://test') | ||
self.server.version = '3.1' | ||
|
||
# Fake signin | ||
self.server._site_id = 'dad65087-b08b-4603-af4e-2887b8aafc67' | ||
self.server._auth_token = 'j80k54ll2lfMZ0tv97mlPvvSCRyD0DOM' | ||
|
||
self.baseurl = self.server.jobs.baseurl | ||
|
||
def test_get(self): | ||
with open(GET_XML, 'rb') as f: | ||
response_xml = f.read().decode('utf-8') | ||
with requests_mock.mock() as m: | ||
m.get(self.baseurl, text=response_xml) | ||
all_jobs, pagination_item = self.server.jobs.get() | ||
job = all_jobs[0] | ||
created_at = datetime(2018, 5, 22, 13, 0, 29, tzinfo=utc) | ||
started_at = datetime(2018, 5, 22, 13, 0, 37, tzinfo=utc) | ||
ended_at = datetime(2018, 5, 22, 13, 0, 45, tzinfo=utc) | ||
self.assertEquals(1, pagination_item.total_available) | ||
self.assertEquals('2eef4225-aa0c-41c4-8662-a76d89ed7336', job.id) | ||
self.assertEquals('Success', job.status) | ||
self.assertEquals('50', job.priority) | ||
self.assertEquals('single_subscription_notify', job.type) | ||
self.assertEquals(created_at, job.created_at) | ||
self.assertEquals(started_at, job.started_at) | ||
self.assertEquals(ended_at, job.ended_at) | ||
|
||
def test_get_before_signin(self): | ||
self.server._auth_token = None | ||
self.assertRaises(TSC.NotSignedInError, self.server.jobs.get) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see now, you need to call this assert to check that it's > 3.1 and also keep the > 2.6 for old back compat. I need to think about this, maybe it's better to have another decorator behavior_changed_in... or something like that.
But this seems fine for now