Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_execution(self):
self.worker.start()
notification_data = json.loads(get_resource('data/webhook_notification.json', pkg_name='tests'))
subscription = onedrivesdk.Subscription()
subscription.id = notification_data['subscriptionId']
self.worker.add_subscription(subscription, self.repo)
# Send a notification.
self.worker.queue_input(json.dumps({'value': [notification_data]}).encode('utf-8'))
# Duplicate notifications should be ignored.
self.worker.queue_input(json.dumps(notification_data).encode('utf-8'))
# Unknown subscriptions should be ignored.
notification_data['subscriptionId'] = '233'
self.worker.queue_input(json.dumps(notification_data).encode('utf-8'))
self.assertTrue(self.callback_called_sem.acquire(timeout=3))
self.assertFalse(self.callback_called_sem.acquire(timeout=1))
self.assertEqual([self.repo], self.callback_repos)
self.assertEqual(1, self.callback_count)
def update_subscription(self, subscription):
""" A temp patch for bug https://github.com/OneDrive/onedrive-sdk-python/issues/95. """
self.content_type = "application/json"
self.method = "PATCH"
entity = onedrivesdk.Subscription(json.loads(self.send(subscription).content))
return entity
def create_subscription(folder_item_request, repo, webhook_url, expiration_time):
"""
:param onedrivesdk.ItemRequestBuilder folder_item_request:
:param onedrived.od_repo.OneDriveLocalRepository repo:
:param str webhook_url:
:param datetime.datetime.datetime expiration_time:
:return onedrivesdk.Subscription:
"""
subscriptions_collection_req = folder_item_request.subscriptions
subscription_req_builder = onedrivesdk.SubscriptionRequestBuilder(subscriptions_collection_req._request_url,
subscriptions_collection_req._client)
subscription_req = item_request_call(repo, subscription_req_builder.request)
subscription_req.content_type = "application/json"
subscription_req.method = "POST"
subscription = onedrivesdk.Subscription()
subscription.notification_url = webhook_url
subscription.expiration_date_time = expiration_time
return onedrivesdk.Subscription(json.loads(subscription_req.send(subscription).content))
:param onedrivesdk.ItemRequestBuilder folder_item_request:
:param onedrived.od_repo.OneDriveLocalRepository repo:
:param str webhook_url:
:param datetime.datetime.datetime expiration_time:
:return onedrivesdk.Subscription:
"""
subscriptions_collection_req = folder_item_request.subscriptions
subscription_req_builder = onedrivesdk.SubscriptionRequestBuilder(subscriptions_collection_req._request_url,
subscriptions_collection_req._client)
subscription_req = item_request_call(repo, subscription_req_builder.request)
subscription_req.content_type = "application/json"
subscription_req.method = "POST"
subscription = onedrivesdk.Subscription()
subscription.notification_url = webhook_url
subscription.expiration_date_time = expiration_time
return onedrivesdk.Subscription(json.loads(subscription_req.send(subscription).content))