8000 Merge pull request #532 from tableau/webhooks-fixes · tableau/server-client-python@62f0f94 · GitHub
[go: up one dir, main page]

Skip to content

Commit 62f0f94

Browse files
authored
Merge pull request #532 from tableau/webhooks-fixes
Webhooks tests and samples
2 parents 83eb785 + f89b1d5 commit 62f0f94

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

contributing.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,8 @@ somewhere.
5959
> pip install versioneer
6060
> python setup.py build
6161
> python setup.py test
62-
>
62+
>
63+
64+
### before committing
65+
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
66+
> pycodestyle tableauserverclient test samples

samples/explore_webhooks.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ def main():
2525
parser.add_argument('--site', '-S', default=None)
2626
parser.add_argument('-p', default=None, help='password')
2727
parser.add_argument('--create', '-c', help='create a webhook')
28+
parser.add_argument('--delete', '-d', help='delete a webhook', action='store_true')
2829
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
2930
help='desired logging level (set to error by default)')
3031

3132
args = parser.parse_args()
32-
33-
3433
if args.p is None:
3534
password = getpass.getpass("Password: ")
3635
else:
@@ -52,7 +51,7 @@ def main():
5251

5352
with server.auth.sign_in(tableau_auth):
5453

55-
# Publish webhook if publish flag is set (-publish, -p)
54+
# Create webhook if create flag is set (-create, -c)
5655
if args.create:
5756

5857
new_webhook = TSC.WebhookItem()
@@ -74,7 +73,9 @@ def main():
7473
# sample_webhook.delete()
7574
print("+++"+sample_webhook.name)
7675

77-
76+
if (args.delete):
77+
print("Deleting webhook " + sample_webhook.name)
78+
server.webhooks.delete(sample_webhook.id)
7879

7980

8081
if __name__ == '__main__':

tableauserverclient/server/endpoint/webhooks_endpoint.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ def test(self, webhook_id):
6060
url = "{0}/{1}/test".format(self.baseurl, webhook_id)
6161
testOutcome = self.get_request(url)
6262
logger.info('Testing webhook (ID: {0} returned {1})'.format(webhook_id, testOutcome))
63+
return testOutcome

test/test_webhook.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,12 @@ def test_create(self):
6161
response_xml = f.read().decode('utf-8')
6262
with requests_mock.mock() as m:
6363
m.post(self.baseurl, text=response_xml)
64-
new_webhook = TSC.WebhookItem()
65-
new_webhook.name = "Test Webhook"
66-
new_webhook.url = "https://ifttt.com/maker-url"
67-
new_webhook.event = "datasource-created"
68-
new_webhook.owner_id =
64+
webhook_model = TSC.WebhookItem()
65+
webhook_model.name = "Test Webhook"
66+
webhook_model.url = "https://ifttt.com/maker-url"
67+
webhook_model.event = "datasource-created"
6968

70-
new_webhook = self.server.webhooks.create(new_webhook)
69+
new_webhook = self.server.webhooks.create(webhook_model)
7170

7271
self.assertNotEqual(new_webhook.id, None)
7372

@@ -80,4 +79,5 @@ def test_request_factory(self):
8079
None)
8180
webhook_request_actual = '{}\n'.format(RequestFactory.Webhook.create_req(webhook_item).decode('utf-8'))
8281
self.maxDiff = None
83-
self.assertEqual(webhook_request_expected, webhook_request_actual)
82+
# windows does /r/n for linebreaks, remove the extra char if it is there
83+
self.assertEqual(webhook_request_expected.replace('\r', ''), webhook_request_actual)

0 commit comments

Comments
 (0)
0