def test_queues_get(mock): resp = create_mock_json("tests/resources/queues_instance.json") mock.return_value = resp uri = "%s/Queues/%s" % (BASE_URI, QUEUE_SID) list_resource.get(QUEUE_SID) mock.assert_called_with("GET", uri, auth=AUTH)
def test_create_call_feedback_one_request(self, request): resp = create_mock_json('tests/resources/call_feedback.json') resp.status_code = 201 request.return_value = resp base_uri = 'https://api.twilio.com/2010-04-01/Accounts/AC123' account_sid = 'AC123' auth = (account_sid, "token") calls = Calls(base_uri, auth) uri = "%s/Calls/CA123/Feedback" % base_uri feedback = calls.feedback('CA123', quality_score=5, issue=['imperfect-audio', 'post-dial-delay']) exp_data = { 'QualityScore': 5, 'Issue': ['imperfect-audio', 'post-dial-delay'], } assert_equal(['imperfect-audio', 'post-dial-delay'], feedback.issues) request.assert_called_with( "POST", uri, data=exp_data, auth=auth, )
def test_triggers_create(request): resp = create_mock_json("tests/resources/usage_triggers_instance.json") resp.status_code = 201 request.return_value = resp usage.triggers.create( friendly_name="foo", usage_category="sms", trigger_by="count", recurring="price", trigger_value="10.00", callback_url="http://www.example.com", callback_method="POST" ) uri = "%s/Usage/Triggers" % BASE_URI request.assert_called_with("POST", uri, data={ "FriendlyName": "foo", "UsageCategory": "sms", "TriggerBy": "count", "Recurring": "price", "TriggerValue": "10.00", "CallbackUrl": "http://www.example.com", "CallbackMethod": "POST" }, auth=AUTH)
def test_triggers_create(request): resp = create_mock_json("tests/resources/usage_triggers_instance.json") resp.status_code = 201 request.return_value = resp usage.triggers.create( friendly_name="foo", usage_category="sms", trigger_by="count", recurring="price", trigger_value="10.00", callback_url="http://www.example.com", callback_method="POST", ) uri = "%s/Usage/Triggers" % BASE_URI request.assert_called_with( "POST", uri, data={ "FriendlyName": "foo", "UsageCategory": "sms", "TriggerBy": "count", "Recurring": "price", "TriggerValue": "10.00", "CallbackUrl": "http://www.example.com", "CallbackMethod": "POST", }, auth=AUTH, )
def test_create_call_feedback(self, request): resp = create_mock_json('tests/resources/call_feedback.json') resp.status_code = 201 request.return_value = resp mock = Mock() mock.uri = '/base' mock.auth = AUTH call = Call(mock, 'CA123') call.load_subresources() feedback = call.feedback.create( quality_score=5, issues=['imperfect-audio', 'post-dial-delay'], ) exp_data = { 'QualityScore': 5, 'Issues': ['imperfect-audio', 'post-dial-delay'], } assert_equal(5, feedback.quality_score, 5) assert_equal(['imperfect-audio', 'post-dial-delay'], feedback.issues) request.assert_called_with( "POST", "/base/CA123/Feedback", data=exp_data, auth=AUTH, timeout=ANY, )
def test_paging(mock): resp = create_mock_json("tests/resources/transcriptions_list.json") mock.return_value = resp uri = "%s/Transcriptions" % (BASE_URI) transcriptions.list(page=2) mock.assert_called_with("GET", uri, params={"Page": 2}, auth=AUTH)
def test_queue_delete(mock): resp = create_mock_json("tests/resources/queues_instance.json") mock.return_value = resp uri = "%s/Queues/%s" % (BASE_URI, QUEUE_SID) r = instance_resource.delete() mock.assert_called_with("DELETE", uri, auth=AUTH)
def test_members_list(mock): resp = create_mock_json("tests/resources/members_list.json") mock.return_value = resp uri = "%s/Members" % (BASE_URI) list_resource.list() mock.assert_called_with("GET", uri, params={}, auth=AUTH)
def test_members_dequeue_call(mock): resp = create_mock_json("tests/resources/members_instance.json") mock.return_value = resp uri = "%s/Members/%s" % (BASE_URI, CALL_SID) list_resource.dequeue(TWIML_URL, call_sid=CALL_SID) mock.assert_called_with("POST", uri, data={"Url": TWIML_URL}, auth=AUTH)
def test_get(mock): resp = create_mock_json("tests/resources/notifications_instance.json") mock.return_value = resp uri = "%s/Notifications/%s" % (BASE_URI, RE_SID) r = list_reosource.get(RE_SID) mock.assert_called_with("GET", uri, auth=AUTH)
def test_get(mock): resp = create_mock_json("tests/resources/transcriptions_instance.json") mock.return_value = resp uri = "%s/Transcriptions/TR123" % (BASE_URI) transcriptions.get("TR123") mock.assert_called_with("GET", uri, auth=AUTH)
def test_get(mock): resp = create_mock_json("tests/resources/notifications_instance.json") mock.return_value = resp uri = "{}/Notifications/{}".format(BASE_URI, RE_SID) r = list_reosource.get(RE_SID) mock.assert_called_with("GET", uri, auth=AUTH)
def test_get(mock): resp = create_mock_json("tests/resources/transcriptions_instance.json") mock.return_value = resp uri = "{}/Transcriptions/TR123".format(BASE_URI) transcriptions.get("TR123") mock.assert_called_with("GET", uri, auth=AUTH)
def test_paging(mock): resp = create_mock_json("tests/resources/transcriptions_list.json") mock.return_value = resp uri = "{}/Transcriptions".format(BASE_URI) transcriptions.list(page=2) mock.assert_called_with("GET", uri, params={"Page": 2}, auth=AUTH)
def test_queue_delete(mock): resp = create_mock_json("tests/resources/queues_instance.json") mock.return_value = resp uri = "%s/Queues/%s" % (BASE_URI, QUEUE_SID) instance_resource.delete() mock.assert_called_with("DELETE", uri, auth=AUTH)
def test_get(mock): resp = create_mock_json("tests/resources/calls_instance.json") mock.return_value = resp uri = "{}/Calls/{}".format(BASE_URI, CALL_SID) r = list_resource.get(CALL_SID) mock.assert_called_with("GET", uri, auth=AUTH)
def test_queues_list(mock): resp = create_mock_json("tests/resources/queues_list.json") mock.return_value = resp uri = "%s/Queues" % (BASE_URI) list_resource.list() mock.assert_called_with("GET", uri, params={}, auth=AUTH)
def test_queue_update(mock): resp = create_mock_json("tests/resources/queues_instance.json") mock.return_value = resp uri = "%s/Queues/%s" % (BASE_URI, QUEUE_SID) r = instance_resource.update(friendly_name='QQ') mock.assert_called_with("POST", uri, data={'FriendlyName':'QQ'}, auth=AUTH)
def test_paging(mock): resp = create_mock_json("tests/resources/notifications_list.json") mock.return_value = resp uri = "{}/Notifications".format(BASE_URI) list_resource.list(before=date(2010, 12, 5)) exp_params = {"MessageDate<": "2010-12-05"} mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH)
def test_paging(mock): resp = create_mock_json("tests/resources/recordings_list.json") mock.return_value = resp uri = "%s/Recordings" % (BASE_URI) recordings.list(call_sid="CA123", before=date(2010, 12, 5)) exp_params = {'CallSid': 'CA123', 'DateCreated<': '2010-12-05'} mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH)
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)
def test_paging(mock): resp = create_mock_json("tests/resources/calls_list.json") mock.return_value = resp uri = "{}/Calls".format(BASE_URI) list_resource.list(started_before=date(2010, 12, 5)) exp_params = {'StartTime<': '2010-12-05'} mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH)
def test_paging(mock): resp = create_mock_json("tests/resources/calls_list.json") mock.return_value = resp uri = "{}/Calls".format(BASE_URI) list_resource.list(started_before=date(2010,12,5)) exp_params = {'StartTime<': '2010-12-05'} mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH)
def test_paging(mock): resp = create_mock_json("tests/resources/notifications_list.json") mock.return_value = resp uri = "%s/Notifications" % (BASE_URI) list_resource.list(before=date(2010, 12, 5)) exp_params = {'MessageDate<': '2010-12-05'} mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH)
def test_paging(mock): resp = create_mock_json("tests/resources/calls_list.json") mock.return_value = resp uri = "%s/Calls" % (BASE_URI) list_resource.list(started=date(2010, 12, 5)) exp_params = {"StartTime": "2010-12-05"} mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH)
def test_delete_list(mock): resp = create_mock_json("tests/resources/recordings_instance.json") resp.status_code = 204 mock.return_value = resp uri = "%s/Recordings/%s" % (BASE_URI, RE_SID) r = recordings.delete(RE_SID) mock.assert_called_with("DELETE", uri, auth=AUTH) assert_true(r)
def test_triggers_paging(request): resp = create_mock_json("tests/resources/usage_triggers_list.json") request.return_value = resp uri = "%s/Usage/Triggers" % BASE_URI usage.triggers.list(recurring="daily", usage_category="sms", trigger_by="count") request.assert_called_with( "GET", uri, params={"Recurring": "daily", "UsageCategory": "sms", "TriggerBy": "count"}, auth=AUTH )
def test_get(mock): resp = create_mock_json("tests/resources/notifications_instance.json") resp.status_code = 204 mock.return_value = resp uri = "{}/Notifications/{}".format(BASE_URI, RE_SID) r = list_resource.delete(RE_SID) mock.assert_called_with("DELETE", uri, auth=AUTH) assert_true(r)
def test_create_call(mock): resp = create_mock_json("tests/resources/calls_instance.json") resp.status_code = 201 mock.return_value = resp uri = "%s/Calls" % (BASE_URI) list_resource.create("TO", "FROM", "url", record=True, application_sid="APPSID") exp_params = {"To": "TO", "From": "FROM", "Url": "url", "Record": "true", "ApplicationSid": "APPSID"} mock.assert_called_with("POST", uri, data=exp_params, auth=AUTH)
def test_records_paging(request): resp = create_mock_json("tests/resources/usage_records_list.json") request.return_value = resp uri = "%s/Usage/Records" % BASE_URI usage.records.list(start_date="2012-10-12", end_date="2012-10-13", category="sms") request.assert_called_with( "GET", uri, params={"StartDate": "2012-10-12", "EndDate": "2012-10-13", "Category": "sms"}, auth=AUTH )
def test_usage_triggers_subresource(self, request): resp = create_mock_json("tests/resources/usage_triggers_list.json") request.return_value = resp mock = Mock() mock.uri = "/base" account = Account(mock, 'AC123') account.load_subresources() triggers = account.usage_triggers.list() self.assertEquals(len(triggers), 2)
def test_get(mock): resp = create_mock_json("tests/resources/recordings_instance.json") resp.status_code = 204 mock.return_value = resp uri = "%s/Recordings/%s" % (BASE_URI, RE_SID) r = recordings.delete(RE_SID) mock.assert_called_with("DELETE", uri, auth=AUTH) assert_true(r)
def test_hangup(mock): resp = create_mock_json("tests/resources/calls_instance.json") resp.status_code = 204 mock.return_value = resp uri = "%s/Calls/%s" % (BASE_URI, CALL_SID) r = list_resource.hangup(CALL_SID) exp_data = {"Status": "completed"} mock.assert_called_with("POST", uri, data=exp_data, auth=AUTH) assert_true(r)
def test_cancel(mock): resp = create_mock_json("tests/resources/calls_instance.json") resp.status_code = 204 mock.return_value = resp uri = "{}/Calls/{}".format(BASE_URI, CALL_SID) r = list_resource.cancel(CALL_SID) exp_data = {"Status": "canceled"} mock.assert_called_with("POST", uri, data=exp_data, auth=AUTH) assert_true(r)
def test_get(mock): resp = create_mock_json("tests/resources/recordings_instance.json") mock.return_value = resp uri = "%s/Recordings/%s" % (BASE_URI, RE_SID) r = recordings.get(RE_SID) mock.assert_called_with("GET", uri, auth=AUTH) truri = "%s/Recordings/%s/Transcriptions" % (BASE_URI, RE_SID) assert_equals(r.transcriptions.uri, truri)
def test_get_call_feedback(self, request): resp = create_mock_json("tests/resources/call_feedback.json") request.return_value = resp mock = Mock() mock.uri = "/base" call = Call(mock, "CA123") call.load_subresources() feedback = call.feedback.get() assert_equal(5, feedback.quality_score, 5) assert_equal(["imperfect-audio", "post-dial-delay"], feedback.issues)
def test_queue_update(mock): resp = create_mock_json("tests/resources/queues_instance.json") mock.return_value = resp uri = "%s/Queues/%s" % (BASE_URI, QUEUE_SID) instance_resource.update(friendly_name='QQ') mock.assert_called_with("POST", uri, data={'FriendlyName': 'QQ'}, auth=AUTH)
def test_get_call_feedback(self, request): resp = create_mock_json('tests/resources/call_feedback.json') request.return_value = resp mock = Mock() mock.uri = '/base' call = Call(mock, 'CA123') call.load_subresources() feedback = call.feedback.get() assert_equal(5, feedback.quality_score, 5) assert_equal(['imperfect-audio', 'post-dial-delay'], feedback.issues)
def test_queues_create(mock): resp = create_mock_json("tests/resources/queues_instance.json") resp.status_code = 201 mock.return_value = resp uri = "%s/Queues" % (BASE_URI) list_resource.create('test', max_size=9001) mock.assert_called_with("POST", uri, data={'FriendlyName': 'test', 'MaxSize': 9001}, auth=AUTH)
def test_get_call_feedback_summary(self, request): resp = create_mock_json('tests/resources/call_feedback_summary.json') request.return_value = resp base_uri = 'https://api.twilio.com/2010-04-01/Accounts/AC123' account_sid = 'AC123' auth = (account_sid, "token") calls = Calls(base_uri, auth) uri = "%s/Calls/Summary" % base_uri feedback = calls.summary.get() assert_equal(10200, feedback.call_count) assert_equal(729, feedback.call_feedback_count) request.assert_called_with('GET', uri, params={}, auth=auth)
def test_queues_create(mock): resp = create_mock_json("tests/resources/queues_instance.json") resp.status_code = 201 mock.return_value = resp uri = "%s/Queues" % (BASE_URI) list_resource.create('test', max_size=9001) mock.assert_called_with("POST", uri, data={ 'FriendlyName': 'test', 'MaxSize': 9001 }, auth=AUTH)
def test_get_call_feedback_summary(self, request): resp = create_mock_json("tests/resources/call_feedback_summary.json") request.return_value = resp base_uri = "https://api.twilio.com/2010-04-01/Accounts/AC123" account_sid = "AC123" auth = (account_sid, "token") calls = Calls(base_uri, auth) uri = "%s/Calls/Summary" % base_uri feedback = calls.summary.get() assert_equal(10200, feedback.call_count) assert_equal(729, feedback.call_feedback_count) request.assert_called_with("GET", uri, params={}, auth=auth)
def test_triggers_paging(request): resp = create_mock_json("tests/resources/usage_triggers_list.json") request.return_value = resp uri = "%s/Usage/Triggers" % BASE_URI usage.triggers.list( recurring="daily", usage_category="sms", trigger_by="count") request.assert_called_with("GET", uri, params={ "Recurring": "daily", "UsageCategory": "sms", "TriggerBy": "count" }, auth=AUTH)
def test_records_paging(request): resp = create_mock_json("tests/resources/usage_records_list.json") request.return_value = resp uri = "%s/Usage/Records" % BASE_URI usage.records.list( start_date="2012-10-12", end_date="2012-10-13", category="sms") request.assert_called_with("GET", uri, params={ "StartDate": "2012-10-12", "EndDate": "2012-10-13", "Category": "sms" }, auth=AUTH)
def test_create_call_feedback(self, request): resp = create_mock_json("tests/resources/call_feedback.json") resp.status_code = 201 request.return_value = resp mock = Mock() mock.uri = "/base" mock.auth = AUTH call = Call(mock, "CA123") call.load_subresources() feedback = call.feedback.create(quality_score=5, issues=["imperfect-audio", "post-dial-delay"]) exp_data = {"QualityScore": 5, "Issues": ["imperfect-audio", "post-dial-delay"]} assert_equal(5, feedback.quality_score, 5) assert_equal(["imperfect-audio", "post-dial-delay"], feedback.issues) request.assert_called_with("POST", "/base/CA123/Feedback", data=exp_data, auth=AUTH, timeout=ANY)
def test_create_call_feedback_one_request(self, request): resp = create_mock_json("tests/resources/call_feedback.json") resp.status_code = 201 request.return_value = resp base_uri = "https://api.twilio.com/2010-04-01/Accounts/AC123" account_sid = "AC123" auth = (account_sid, "token") calls = Calls(base_uri, auth) uri = "%s/Calls/CA123/Feedback" % base_uri feedback = calls.feedback("CA123", quality_score=5, issue=["imperfect-audio", "post-dial-delay"]) exp_data = {"QualityScore": 5, "Issue": ["imperfect-audio", "post-dial-delay"]} assert_equal(["imperfect-audio", "post-dial-delay"], feedback.issues) request.assert_called_with("POST", uri, data=exp_data, auth=auth)
def test_create_call(mock): resp = create_mock_json("tests/resources/calls_instance.json") resp.status_code = 201 mock.return_value = resp uri = "%s/Calls" % (BASE_URI) list_resource.create("TO", "FROM", "url", record=True, application_sid='APPSID') exp_params = { 'To': "TO", 'From': "FROM", 'Url': "url", 'Record': "true", 'ApplicationSid': 'APPSID', } mock.assert_called_with("POST", uri, data=exp_params, auth=AUTH)
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)