8000 Add headers regardless, fix tests · madCode/twilio-python@3a3b61b · GitHub
[go: up one dir, main page]

Skip to content

Commit 3a3b61b

Browse files
committed
Add headers regardless, fix tests
1 parent b5b1952 commit 3a3b61b

13 files changed

+73
-39
lines changed

tests/test_authorized_connect_apps.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_get(self, mock):
2323

2424
self.resource.get("SID")
2525
mock.assert_called_with("GET", "/base/AuthorizedConnectApps/SID",
26-
auth=self.auth)
26+
auth=self.auth, use_json_extension=True)
2727

2828
@patch("twilio.rest.resources.base.make_twilio_request")
2929
def test_list(self, mock):
@@ -32,7 +32,8 @@ def test_list(self, mock):
3232

3333
self.resource.list()
3434
mock.assert_called_with("GET", "/base/AuthorizedConnectApps",
35-
params={}, auth=self.auth)
35+
params={}, auth=self.auth,
36+
use_json_extension=True)
3637

3738
def test_load(self):
3839
instance = AuthorizedConnectApp(Mock(), "sid")

tests/test_call_feedback.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_create_call_feedback(self, request):
4848
request.assert_called_with(
4949
"POST", "/base/CA123/Feedback",
5050
data=exp_data, auth=AUTH,
51-
timeout=ANY,
51+
timeout=ANY, use_json_extension=True,
5252
)
5353

5454
@patch('twilio.rest.resources.base.make_twilio_request')
@@ -78,6 +78,7 @@ def test_create_call_feedback_one_request(self, request):
7878
request.assert_called_with(
7979
"POST", uri,
8080
data=exp_data, auth=auth,
81+
use_json_extension=True,
8182
)
8283

8384

@@ -98,4 +99,5 @@ def test_get_call_feedback_summary(self, request):
9899
assert_equal(10200, feedback.call_count)
99100
assert_equal(729, feedback.call_feedback_count)
100101

101-
request.assert_called_with('GET', uri, params={}, auth=auth)
102+
request.assert_called_with('GET', uri, params={}, auth=auth,
103+
use_json_extension=True)

tests/test_calls.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def test_create_call(mock):
2828
'ApplicationSid': 'APPSID',
2929
}
3030

31-
mock.assert_called_with("POST", uri, data=exp_params, auth=AUTH)
31+
mock.assert_called_with("POST", uri, data=exp_params, auth=AUTH,
32+
use_json_extension=True)
3233

3334

3435
@patch("twilio.rest.resources.base.make_twilio_request")
@@ -40,7 +41,8 @@ def test_paging(mock):
4041
list_resource.list(started_before=date(2010, 12, 5))
4142
exp_params = {'StartTime<': '2010-12-05'}
4243

43-
mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH)
44+
mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH,
45+
use_json_extension=True)
4446

4547

4648
@patch("twilio.rest.resources.base.make_twilio_request")
@@ -52,7 +54,8 @@ def test_paging_iter(mock):
5254
next(list_resource.iter(started_before=date(2010, 12, 5)))
5355
exp_params = {'StartTime<': '2010-12-05'}
5456

55-
mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH)
57+
mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH,
58+
use_json_extension=True)
5659

5760

5861
@patch("twilio.rest.resources.base.make_twilio_request")
@@ -63,7 +66,8 @@ def test_get(mock):
6366
uri = "%s/Calls/%s" % (BASE_URI, CALL_SID)
6467
list_resource.get(CALL_SID)
6568

66-
mock.assert_called_with("GET", uri, auth=AUTH)
69+
mock.assert_called_with("GET", uri, auth=AUTH,
70+
use_json_extension=True)
6771

6872

6973
@patch("twilio.rest.resources.base.make_twilio_request")
@@ -76,7 +80,8 @@ def test_hangup(mock):
7680
r = list_resource.hangup(CALL_SID)
7781
exp_data = {"Status": "completed"}
7882

79-
mock.assert_called_with("POST", uri, data=exp_data, auth=AUTH)
83+
mock.assert_called_with("POST", uri, data=exp_data, auth=AUTH,
84+
use_json_extension=True)
8085
assert_true(r)
8186

8287

@@ -90,7 +95,8 @@ def test_cancel(mock):
9095
r = list_resource.cancel(CALL_SID)
9196
exp_data = {"Status": "canceled"}
9297

93-
mock.assert_called_with("POST", uri, data=exp_data, auth=AUTH)
98+
mock.assert_called_with("POST", uri, data=exp_data, auth=AUTH,
99+
use_json_extension=True)
94100
assert_true(r)
95101

96102

tests/test_client.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def test_members(self, mock):
4747
mock.return_value = resp
4848
self.client.members("QU123").list()
4949
uri = "https://api.twilio.com/2010-04-01/Accounts/ACCOUNT_SID/Queues/QU123/Members"
50-
mock.assert_called_with("GET", uri, params={}, auth=AUTH)
50+
mock.assert_called_with("GET", uri, params={}, auth=AUTH,
51+
use_json_extension=True)
5152

5253
@patch("twilio.rest.resources.base.make_request")
5354
def test_workflows(self, request):
@@ -56,7 +57,7 @@ def test_workflows(self, request):
5657
workflows = self.task_router_client.workflows("WS123")
5758
workflows = workflows.list()
5859
assert_is_not_none(workflows[0].sid)
59-
uri = "https://taskrouter.twilio.com/v1/Workspaces/WS123/Workflows.json"
60+
uri = "https://taskrouter.twilio.com/v1/Workspaces/WS123/Workflows"
6061
request.assert_called_with("GET", uri, headers=ANY, params={}, auth=AUTH)
6162

6263

@@ -69,7 +70,9 @@ def test_members(self, mock_request):
6970
resp = create_mock_json("tests/resources/members_list.json")
7071
mock_request.return_value = resp
7172
self.client.members("QU123").list()
72-
mock_request.assert_called_with("GET", ANY, params=ANY, auth=AUTH, timeout=sentinel.timeout)
73+
mock_request.assert_called_with("GET", ANY, params=ANY, auth=AUTH,
74+
timeout=sentinel.timeout,
75+
use_json_extension=True)
7376

7477
@patch("twilio.rest.resources.base.make_twilio_request")
7578
def test_arbitrary_member(self, mock_request):
@@ -78,4 +81,6 @@ def test_arbitrary_member(self, mock_request):
7881
mock_response.content = json.dumps({"short_codes": []})
7982
mock_request.return_value = mock_response
8083
assert_equal([], self.client.sms.short_codes.list())
81-
mock_request.assert_called_once_with("GET", ANY, params=ANY, auth=AUTH, timeout=sentinel.timeout)
84+
mock_request.assert_called_once_with("GET", ANY, params=ANY, auth=AUTH,
85+
timeout=sentinel.timeout,
86+
use_json_extension=True)

tests/test_connect_apps.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_get(self, mock):
2020

2121
self.resource.get("SID")
2222
mock.assert_called_with("GET", "/base/ConnectApps/SID",
23-
auth=self.auth)
23+
auth=self.auth, use_json_extension=True)
2424

2525
@patch("twilio.rest.resources.base.make_twilio_request")
2626
def test_list_with_paging(self, mock):
@@ -29,7 +29,9 @@ def test_list_with_paging(self, mock):
2929

3030
self.resource.list(page=1, page_size=50)
3131
mock.assert_called_with("GET", "/base/ConnectApps",
32-
params={"Page": 1, "PageSize": 50}, auth=self.auth)
32+
params={"Page": 1, "PageSize": 50},
33+
auth=self.auth,
34+
use_json_extension=True)
3335

3436
@patch("twilio.rest.resources.base.make_twilio_request")
3537
def test_list(self, mock):
@@ -38,7 +40,8 @@ def test_list(self, mock):
3840

3941
self.resource.list()
4042
mock.assert_called_with("GET", "/base/ConnectApps",
41-
params={}, auth=self.auth)
43+
params={}, auth=self.auth,
44+
use_json_extension=True)
4245

4346
def test_create(self):
4447
self.assertRaises(AttributeError, getattr, self.resource, 'create')

tests/test_make_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_sequence_data(http_mock, response_mock):
8181
@patch('twilio.rest.resources.base.make_request')
8282
def test_make_twilio_request_headers(mock):
8383
url = "http://random/url"
84-
make_twilio_request("POST", url)
< 1241 /code>84+
make_twilio_request("POST", url, use_json_extension=True)
8585
mock.assert_called_with("POST", "http://random/url.json",
8686
headers=post_headers)
8787

tests/test_members.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def test_members_list(mock):
2121
uri = "%s/Members" % (BASE_URI)
2222
list_resource.list()
2323

24-
mock.assert_called_with("GET", uri, params={}, auth=AUTH)
24+
mock.assert_called_with("GET", uri, params={}, auth=AUTH,
25+
use_json_extension=True)
2526

2627

2728
@patch("twilio.rest.resources.base.make_twilio_request")
@@ -32,7 +33,8 @@ def test_members_dequeue_front(mock):
3233
uri = "%s/Members/Front" % (BASE_URI)
3334
list_resource.dequeue(TWIML_URL)
3435

35-
mock.assert_called_with("POST", uri, data={"Url": TWIML_URL}, auth=AUTH)
36+
mock.assert_called_with("POST", uri, data={"Url": TWIML_URL}, auth=AUTH,
37+
use_json_extension=True)
3638

3739

3840
@patch("twilio.rest.resources.base.make_twilio_request")
@@ -43,4 +45,5 @@ def test_members_dequeue_call(mock):
4345
uri = "%s/Members/%s" % (BASE_URI, CALL_SID)
4446
list_resource.dequeue(TWIML_URL, call_sid=CALL_SID)
4547

46-
mock.assert_called_with("POST", uri, data={"Url": TWIML_URL}, auth=AUTH)
48+
mock.assert_called_with("POST", uri, data={"Url": TWIML_URL}, auth=AUTH,
49+
use_json_extension=True)

tests/test_notifications.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def test_paging(mock):
2222
list_resource.list(before=date(2010, 12, 5))
2323
exp_params = {'MessageDate<': '2010-12-05'}
2424

25-
mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH)
25+
mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH,
26+
use_json_extension=True)
2627

2728

2829
@patch("twilio.rest.resources.base.make_twilio_request")
@@ -33,7 +34,8 @@ def test_get(mock):
3334
uri = "%s/Notifications/%s" % (BASE_URI, RE_SID)
3435
list_resource.get(RE_SID)
3536

36-
mock.assert_called_with("GET", uri, auth=AUTH)
37+
mock.assert_called_with("GET", uri, auth=AUTH,
38+
use_json_extension=True)
3739

3840

3941
@patch("twilio.rest.resources.base.make_twilio_request")
@@ -45,7 +47,8 @@ def test_get2(mock):
4547
uri = "%s/Notifications/%s" % (BASE_URI, RE_SID)
4648
r = list_resource.delete(RE_SID)
4749

48-
mock.assert_called_with("DELETE", uri, auth=AUTH)
50+
mock.assert_called_with("DELETE", uri, auth=AUTH,
51+
use_json_extension=True)
4952
assert_true(r)
5053

5154

tests/test_queues.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def test_queues_list(mock):
2020
uri = "%s/Queues" % (BASE_URI)
2121
list_resource.list()
2222

23-
mock.assert_called_with("GET", uri, params={}, auth=AUTH)
23+
mock.assert_called_with("GET", uri, params={}, auth=AUTH,
24+
use_json_extension=True)
2425

2526

2627
@patch("twilio.rest.resources.base.make_twilio_request")
@@ -34,7 +35,8 @@ def test_queues_create(mock):
3435

3536
mock.assert_called_with("POST", uri,
3637
data={'FriendlyName': 'test', 'MaxSize': 9001},
37-
auth=AUTH)
38+
auth=AUTH,
39+
use_json_extension=True)
3840

3941

4042
@patch("twilio.rest.resources.base.make_twilio_request")
@@ -44,7 +46,8 @@ def test_queues_get(mock):
4446

4547
uri = "%s/Queues/%s" % (BASE_URI, QUEUE_SID)
4648
list_resource.get(QUEUE_SID)
47-
mock.assert_called_with("GET", uri, auth=AUTH)
49+
mock.assert_called_with("GET", uri, auth=AUTH,
50+
use_json_extension=True)
4851

4952

5053
@patch("twilio.rest.resources.base.make_twilio_request")
@@ -56,7 +59,8 @@ def test_queue_update(mock):
5659
instance_resource.update(friendly_name='QQ')
5760

5861
mock.assert_called_with("POST", uri,
59-
data={'FriendlyName': 'QQ'}, auth=AUTH)
62+
data={'FriendlyName': 'QQ'}, auth=AUTH,
63+
use_json_extension=True)
6064

6165

6266
@patch("twilio.rest.resources.base.make_twilio_request")
@@ -67,4 +71,4 @@ def test_queue_delete(mock):
6771
uri = "%s/Queues/%s" % (BASE_URI, QUEUE_SID)
6872
instance_resource.delete()
6973

70-
mock.assert_called_with("DELETE", uri, auth=AUTH)
74+
mock.assert_called_with("DELETE", uri, auth=AUTH, use_json_extension=True)

tests/test_recordings.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ def test_paging(mock):
2323
recordings.list(call_sid="CA123", before=date(2010, 12, 5))
2424
exp_params = {'CallSid': 'CA123', 'DateCreated<': '2010-12-05'}
2525

26-
mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH)
26+
mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH,
27+
use_json_extension=True)
2728

2829

2930
@patch("twilio.rest.resources.base.make_twilio_request")
@@ -34,7 +35,8 @@ def test_get(mock):
3435
uri = "%s/Recordings/%s" % (BASE_URI, RE_SID)
3536
r = recordings.get(RE_SID)
3637

37-
mock.assert_called_with("GET", uri, auth=AUTH)
38+
mock.assert_called_with("GET", uri, auth=AUTH,
39+
use_json_extension=True)
3840

3941
truri = "%s/Recordings/%s/Transcriptions" % (BASE_URI, RE_SID)
4042
assert_equals(r.transcriptions.uri, truri)
@@ -49,7 +51,7 @@ def test_delete_list(mock):
4951
uri = "%s/Recordings/%s" % (BASE_URI, RE_SID)
5052
r = recordings.delete(RE_SID)
5153

52-
mock.assert_called_with("DELETE", uri, auth=AUTH)
54+
mock.assert_called_with("DELETE", uri, auth=AUTH, use_json_extension=True)
5355
assert_true(r)
5456

5557

@@ -63,7 +65,8 @@ def test_delete_instance(mock):
6365
rec = Recording(recordings, RE_SID)
6466
r = rec.delete()
6567

66-
mock.assert_called_with("DELETE", uri, auth=AUTH)
68+
mock.assert_called_with("DELETE", uri, auth=AUTH,
69+
use_json_extension=True)
6770
assert_true(r)
6871

6972

tests/test_transcriptions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def test_paging(mock):
1818
uri = "%s/Transcriptions" % (BASE_URI)
1919
transcriptions.list(page=2)
2020

21-
mock.assert_called_with("GET", uri, params={"Page": 2}, auth=AUTH)
21+
mock.assert_called_with("GET", uri, params={"Page": 2}, auth=AUTH,
22+
use_json_extension=True)
2223

2324

2425
@patch("twilio.rest.resources.base.make_twilio_request")
@@ -29,7 +30,8 @@ def test_get(mock):
2930
uri = "%s/Transcriptions/TR123" % (BASE_URI)
3031
transcriptions.get("TR123")
3132

C2EE 32-
mock.assert_called_with("GET", uri, auth=AUTH)
33+
mock.assert_called_with("GET", uri, auth=AUTH,
34+
use_json_extension=True)
3335

3436

3537
@patch("twilio.rest.resources.base.Resource.request")

tests/test_usage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_triggers_create(request):
3737
"TriggerValue": "10.00",
3838
"CallbackUrl": "http://www.example.com",
3939
"CallbackMethod": "POST"
40-
}, auth=AUTH)
40+
}, auth=AUTH, use_json_extension=True)
4141

4242

4343
@patch("twilio.rest.resources.base.make_twilio_request")
@@ -55,7 +55,7 @@ def test_triggers_paging(request):
5555
"Recurring": "daily",
5656
"UsageCategory": "sms",
5757
"TriggerBy": "count"
58-
}, auth=AUTH)
58+
}, auth=AUTH, use_json_extension=True)
5959

6060

6161
@patch("twilio.rest.resources.base.make_twilio_request")
@@ -73,7 +73,7 @@ def test_records_paging(request):
7373
"StartDate": "2012-10-12",
7474
"EndDate": "2012-10-13",
7575
"Category": "sms"
76-
}, auth=AUTH)
76+
}, auth=AUTH, use_json_extension=True)
7777

7878

7979
@patch("twilio.rest.resources.base.Resource.request")

twilio/rest/resources/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ def make_twilio_request(method, uri, **kwargs):
143143

144144
kwargs["headers"] = headers
145145

146-
if "Accept" not in headers and kwargs.pop('use_json_extension', False):
146+
if "Accept" not in headers:
147147
headers["Accept"] = "application/json"
148+
149+
if kwargs.pop('use_json_extension', False):
148150
uri += ".json"
149151

150152
resp = make_request(method, uri, **kwargs)

0 commit comments

Comments
 (0)
0