forked from twilio/twilio-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_client.py
More file actions
71 lines (56 loc) · 2.82 KB
/
test_client.py
File metadata and controls
71 lines (56 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import unittest
from mock import patch, Mock, sentinel, ANY
from nose.tools import assert_equal, assert_true
from twilio.rest.resources.imports import json
from twilio.rest import TwilioRestClient, resources
from tools import create_mock_json
AUTH = ("ACCOUNT_SID", "AUTH_TOKEN")
class RestClientTest(unittest.TestCase):
def setUp(self):
self.client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN")
@patch("twilio.rest.make_request")
def test_request(self, mock):
self.client.request("2010-04-01", method="GET")
mock.assert_called_with("GET", "https://api.twilio.com/2010-04-01",
headers={"User-Agent": ANY,
'Accept-Charset': 'utf-8'},
params={}, auth=AUTH, data=None)
called_kwargs = mock.mock_calls[0][2]
self.assertTrue(
'twilio-python' in called_kwargs['headers']['User-Agent']
)
def test_connect_apps(self):
assert_true(isinstance(self.client.connect_apps, resources.ConnectApps))
def test_authorized_apps(self):
assert_true(isinstance(self.client.authorized_connect_apps,
resources.AuthorizedConnectApps))
@patch("twilio.rest.resources.base.make_request")
def test_conferences(self, mock):
mock.return_value = Mock()
mock.return_value.ok = True
mock.return_value.content = '{"conferences": []}'
self.client.conferences.list()
@patch("twilio.rest.resources.base.make_twilio_request")
def test_members(self, mock):
resp = create_mock_json("tests/resources/members_list.json")
mock.return_value = resp
self.client.members("QU123").list()
uri = "https://api.twilio.com/2010-04-01/Accounts/ACCOUNT_SID/Queues/QU123/Members"
mock.assert_called_with("GET", uri, params={}, auth=AUTH)
class RestClientTimeoutTest(unittest.TestCase):
def setUp(self):
self.client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN", timeout=sentinel.timeout)
@patch("twilio.rest.resources.base.make_twilio_request")
def test_members(self, mock_request):
resp = create_mock_json("tests/resources/members_list.json")
mock_request.return_value = resp
self.client.members("QU123").list()
mock_request.assert_called_with("GET", ANY, params=ANY, auth=AUTH, timeout=sentinel.timeout)
@patch("twilio.rest.resources.base.make_twilio_request")
def test_arbitrary_member(self, mock_request):
mock_response = Mock()
mock_response.ok = True
mock_response.content = json.dumps({"short_codes": []})
mock_request.return_value = mock_response
assert_equal([], self.client.sms.short_codes.list())
mock_request.assert_called_once_with("GET", ANY, params=ANY, auth=AUTH, timeout=sentinel.timeout)