-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* GET and POST tests verify headers, body, and query strings coming from `Endpoint`
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,47 @@ | ||
import unittest | ||
|
||
import requests | ||
import requests_mock | ||
|
||
import tableauserverclient as TSC | ||
|
||
|
||
class RequestTests(unittest.TestCase): | ||
def setUp(self): | ||
self.server = TSC.Server('http://test') | ||
|
||
# Fake sign in | ||
self.server._site_id = 'dad65087-b08b-4603-af4e-2887b8aafc67' | ||
self.server._auth_token = 'j80k54ll2lfMZ0tv97mlPvvSCRyD0DOM' | ||
|
||
self.baseurl = self.server.workbooks.baseurl | ||
|
||
def test_make_get_request(self): | ||
with requests_mock.mock() as m: | ||
m.get(requests_mock.ANY) | ||
url = "http://test/api/2.3/sites/dad65087-b08b-4603-af4e-2887b8aafc67/workbooks" | ||
opts = TSC.RequestOptions(pagesize=13, pagenumber=13) | ||
resp = self.server.workbooks._make_request(requests.get, | ||
url, | ||
content=None, | ||
request_object=opts, | ||
auth_token='j80k54ll2lfMZ0tv97mlPvvSCRyD0DOM', | ||
content_type='text/xml') | ||
|
||
self.assertEquals(resp.request.query, 'pagenumber=13&pagesize=13') | ||
self.assertEquals(resp.request.headers['x-tableau-auth'], 'j80k54ll2lfMZ0tv97mlPvvSCRyD0DOM') | ||
self.assertEquals(resp.request.headers['content-type'], 'text/xml') | ||
|
||
def test_make_post_request(self): | ||
with requests_mock.mock() as m: | ||
m.post(requests_mock.ANY) | ||
url = "http://test/api/2.3/sites/dad65087-b08b-4603-af4e-2887b8aafc67/workbooks" | ||
resp = self.server.workbooks._make_request(requests.post, | ||
url, | ||
content=b'1337', | ||
request_object=None, | ||
auth_token='j80k54ll2lfMZ0tv97mlPvvSCRyD0DOM', | ||
content_type='multipart/mixed') | ||
self.assertEquals(resp.request.headers['x-tableau-auth'], 'j80k54ll2lfMZ0tv97mlPvvSCRyD0DOM') | ||
self.assertEquals(resp.request.headers['content-type'], 'multipart/mixed') | ||
self.assertEquals(resp.request.body, b'1337') |