2019-01-17 00:54:01 +01:00
|
|
|
import json
|
2020-05-26 07:16:25 +02:00
|
|
|
from unittest import mock
|
2018-12-28 20:45:54 +01:00
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
|
|
|
from typing import Dict
|
|
|
|
|
2020-01-18 08:57:08 +01:00
|
|
|
class TestVideoCall(ZulipTestCase):
|
2018-12-28 20:45:54 +01:00
|
|
|
def setUp(self) -> None:
|
2019-10-19 20:47:00 +02:00
|
|
|
super().setUp()
|
2018-12-28 20:45:54 +01:00
|
|
|
user_profile = self.example_user('hamlet')
|
2020-03-06 18:40:46 +01:00
|
|
|
self.login_user(user_profile)
|
2018-12-28 20:45:54 +01:00
|
|
|
|
|
|
|
def test_create_video_call_success(self) -> None:
|
|
|
|
with mock.patch('zerver.lib.actions.request_zoom_video_call_url', return_value={'join_url': 'example.com'}):
|
|
|
|
result = self.client_get("/json/calls/create")
|
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assertEqual(200, result.status_code)
|
|
|
|
content = result.json()
|
|
|
|
self.assertEqual(content['zoom_url'], 'example.com')
|
|
|
|
|
|
|
|
def test_create_video_call_failure(self) -> None:
|
|
|
|
with mock.patch('zerver.lib.actions.request_zoom_video_call_url', return_value=None):
|
|
|
|
result = self.client_get("/json/calls/create")
|
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assertEqual(200, result.status_code)
|
|
|
|
content = result.json()
|
|
|
|
self.assertEqual(content['zoom_url'], '')
|
|
|
|
|
|
|
|
def test_create_video_request_success(self) -> None:
|
|
|
|
class MockResponse:
|
|
|
|
def __init__(self) -> None:
|
|
|
|
self.status_code = 200
|
|
|
|
|
|
|
|
def json(self) -> Dict[str, str]:
|
|
|
|
return {"join_url": "example.com"}
|
|
|
|
|
2019-01-17 00:25:22 +01:00
|
|
|
def raise_for_status(self) -> None:
|
|
|
|
return None
|
|
|
|
|
2018-12-28 20:45:54 +01:00
|
|
|
with mock.patch('requests.post', return_value=MockResponse()):
|
|
|
|
result = self.client_get("/json/calls/create")
|
|
|
|
self.assert_json_success(result)
|
2019-01-17 00:54:01 +01:00
|
|
|
|
|
|
|
def test_create_video_request_http_error(self) -> None:
|
|
|
|
class MockResponse:
|
|
|
|
def __init__(self) -> None:
|
|
|
|
self.status_code = 401
|
|
|
|
|
|
|
|
def raise_for_status(self) -> None:
|
|
|
|
raise Exception("Invalid request!")
|
|
|
|
|
|
|
|
with mock.patch('requests.post', return_value=MockResponse()):
|
|
|
|
result = self.client_get("/json/calls/create")
|
|
|
|
self.assert_json_success(result)
|
|
|
|
result_dict = json.loads(result.content.decode('utf-8'))
|
|
|
|
|
|
|
|
# TODO: Arguably this is the wrong result for errors, but
|
|
|
|
# in any case we should test it.
|
|
|
|
self.assertEqual(result_dict['zoom_url'], '')
|
2018-12-28 20:45:54 +01:00
|
|
|
|
|
|
|
def test_create_video_request(self) -> None:
|
|
|
|
with mock.patch('requests.post'):
|
|
|
|
result = self.client_get("/json/calls/create")
|
|
|
|
self.assert_json_success(result)
|