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):
|
|
|
|
STREAM_NAME = 'test'
|
2018-03-13 23:43:02 +01:00
|
|
|
URL_TEMPLATE = "/api/v1/external/dropbox?&api_key={api_key}&stream={stream}"
|
2017-12-18 01:56:03 +01:00
|
|
|
FIXTURE_DIR_NAME = 'dropbox'
|
|
|
|
|
|
|
|
def test_file_updated(self) -> None:
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_topic = "Dropbox"
|
|
|
|
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",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-12-18 01:56:03 +01:00
|
|
|
|
|
|
|
def test_verification_request(self) -> None:
|
|
|
|
self.subscribe(self.test_user, self.STREAM_NAME)
|
|
|
|
get_params = {'stream_name': self.STREAM_NAME,
|
2018-08-01 10:53:40 +02:00
|
|
|
'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
|
|
|
|
2020-05-13 05:55:22 +02:00
|
|
|
get_params['challenge'] = '9B2SVL4orbt5DxLMqJHI6pOTipTqingt2YFMIO0g06E'
|
|
|
|
result = self.client_get(self.url, get_params)
|
|
|
|
|
|
|
|
self.assertEqual(result.status_code, 200)
|
|
|
|
self.assertEqual(result["Content-Type"], "text/plain; charset=UTF-8")
|
2017-12-18 01:56:03 +01:00
|
|
|
self.assert_in_response('9B2SVL4orbt5DxLMqJHI6pOTipTqingt2YFMIO0g06E', result)
|