2017-12-18 01:56:03 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
2018-08-01 10:53:40 +02:00
|
|
|
from zerver.lib.users import get_api_key
|
2017-12-18 01:56:03 +01:00
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2017-12-18 01:56:03 +01:00
|
|
|
class DropboxHookTests(WebhookTestCase):
|
2024-05-04 22:02:50 +02:00
|
|
|
CHANNEL_NAME = "test"
|
2018-03-13 23:43:02 +01:00
|
|
|
URL_TEMPLATE = "/api/v1/external/dropbox?&api_key={api_key}&stream={stream}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "dropbox"
|
2017-12-18 01:56:03 +01:00
|
|
|
|
|
|
|
def test_file_updated(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Dropbox"
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_message = "File has been updated on Dropbox!"
|
2017-12-18 01:56:03 +01:00
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"file_updated",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-12-18 01:56:03 +01:00
|
|
|
|
|
|
|
def test_verification_request(self) -> None:
|
2024-05-04 22:02:50 +02:00
|
|
|
self.subscribe(self.test_user, self.CHANNEL_NAME)
|
|
|
|
get_params = {"stream_name": self.CHANNEL_NAME, "api_key": get_api_key(self.test_user)}
|
2017-12-18 01:56:03 +01:00
|
|
|
result = self.client_get(self.url, get_params)
|
2020-05-13 05:55:22 +02:00
|
|
|
self.assert_json_error(result, "Missing 'challenge' argument", 400)
|
2017-12-18 01:56:03 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
get_params["challenge"] = "9B2SVL4orbt5DxLMqJHI6pOTipTqingt2YFMIO0g06E"
|
2020-05-13 05:55:22 +02:00
|
|
|
result = self.client_get(self.url, get_params)
|
|
|
|
|
|
|
|
self.assertEqual(result.status_code, 200)
|
|
|
|
self.assertEqual(result["Content-Type"], "text/plain; charset=UTF-8")
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assert_in_response("9B2SVL4orbt5DxLMqJHI6pOTipTqingt2YFMIO0g06E", result)
|