Example #1
0
class RestClientTest(unittest.TestCase):
    def setUp(self):
        self.client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN")
        self.task_router_client = TwilioTaskRouterClient("ACCOUNT_SID",
                                                         "AUTH_TOKEN")

    @patch("twilio.rest.base.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',
                                         'Authorization':
                                         'Basic QUNDT1VOVF9TSUQ6QVVUSF9UT0tFTg=='},
                                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,
                                use_json_extension=True)

    @patch("twilio.rest.resources.base.make_request")
    def test_workflows(self, request):
        resp = create_mock_json(
            "tests/resources/task_router/workflows_list.json"
        )
        request.return_value = resp
        workflows = self.task_router_client.workflows("WS123")
        workflows = workflows.list()
        assert_true(workflows[0].sid is not None)
        uri = "https://taskrouter.twilio.com/v1/Workspaces/WS123/Workflows"
        request.assert_called_with("GET", uri, headers=ANY, params={},
                                   auth=AUTH)
Example #2
0
salesRuleTargets = []
salesRuleTarget = WorkflowRuleTarget(sales_queue_sid, null, null, null)
salesRuleTargets.append(salesRuleTarget)
salesRule = WorkflowRule("type=='sales'", salesRuleTargets, null)

marketingRuleTargets = []
marketingRuleTarget = WorkflowRuleTarget(marketing_queue_sid, null, null, null)
marketingRuleTargets.append(marketingRuleTarget)
marketingRule = WorkflowRule("type=='marketing'", marketingRuleTargets, null)

supportRuleTargets = []
supportRuleTarget = WorkflowRuleTarget(support_queue_sid, null, null, null)
supportRuleTargets.append(supportRuleTarget)
supportRule = WorkflowRule("type=='support'", supportRuleTargets, null)

rules.append(salesRule)
rules.append(marketingRule)
rules.append(supportRule)

defaultTarget = WorkflowRuleTarget(everyone_queue_sid, null, null, null)
config = WorkflowConfig(rules, defaultTarget)
json = config.toJson()

workflow = client.workflows(workspace_sid).create(
    friendly_name='Sales, Marketing, Support Workflow',
    assignment_callback_url='http://example.com',
    fallback_assignment_callback_url='http://example2.com',
    task_reservation_timeout='30',
    configuration=json)

print workflow.friendly_name
Example #3
0
class RestClientTest(unittest.TestCase):
    def setUp(self):
        self.client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN")
        self.task_router_client = TwilioTaskRouterClient(
            "ACCOUNT_SID", "AUTH_TOKEN")

    @patch("twilio.rest.base.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',
                                    'Authorization':
                                    'Basic QUNDT1VOVF9TSUQ6QVVUSF9UT0tFTg=='
                                },
                                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,
                                use_json_extension=True)

    @patch("twilio.rest.resources.base.make_request")
    def test_workflows(self, request):
        resp = create_mock_json(
            "tests/resources/task_router/workflows_list.json")
        request.return_value = resp
        workflows = self.task_router_client.workflows("WS123")
        workflows = workflows.list()
        assert_true(workflows[0].sid is not None)
        uri = "https://taskrouter.twilio.com/v1/Workspaces/WS123/Workflows"
        request.assert_called_with("GET",
                                   uri,
                                   headers=ANY,
                                   params={},
                                   auth=AUTH)
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioTaskRouterClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
workspace_sid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

client = TwilioTaskRouterClient(account_sid, auth_token)

for workflow in client.workflows(workspace_sid).list():
	print(workflow.friendly_name)
salesRuleTargets.append(salesRuleTarget)
salesRule = WorkflowRule("type=='sales'", salesRuleTargets, None)

marketingRuleTargets = []
marketingRuleTarget = WorkflowRuleTarget(marketing_queue_sid, None, None, None)
marketingRuleTargets.append(marketingRuleTarget)
marketingRule = WorkflowRule("type=='marketing'", marketingRuleTargets, None)

supportRuleTargets = []
supportRuleTarget = WorkflowRuleTarget(support_queue_sid, None, None, None)
supportRuleTargets.append(supportRuleTarget)
supportRule = WorkflowRule("type=='support'", supportRuleTargets, None)

rules.append(salesRule)
rules.append(marketingRule)
rules.append(supportRule)

defaultTarget = WorkflowRuleTarget(everyone_queue_sid, None, None, None)
config = WorkflowConfig(rules, defaultTarget)
json = config.to_json()

workflow = client.workflows(workspace_sid).create(
    friendly_name='Sales, Marketing, Support Workflow',
    assignment_callback_url='http://example.com',
    fallback_assignment_callback_url='http://example2.com',
    task_reservation_timeout='30',
    configuration=json
)

print(workflow.friendly_name)
Example #6
0
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioTaskRouterClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
workspace_sid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
workflow_sid = "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

client = TwilioTaskRouterClient(account_sid, auth_token)

workflow = client.workflows(workspace_sid).get(workflow_sid)
print(workflow.friendly_name)
Example #7
0
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioTaskRouterClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
workspace_sid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

client = TwilioTaskRouterClient(account_sid, auth_token)

for workflow in client.workflows(workspace_sid).list():
    print(workflow.friendly_name)
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioTaskRouterClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "{{ account_sid }}"
auth_token = "{{ auth_token }}"
workspace_sid = "{{ workspace_sid }}"
workflow_sid = "{{ workflow_sid }}"

client = TwilioTaskRouterClient(account_sid, auth_token)

statistics = client.workflows(workspace_sid).get(workflow_sid).statistics.get()
print statistics.cumulative["avg_task_acceptance_time"]
print statistics.cumulative["tasks_created"]
print statistics.realtime["tasks_by_status"]["pending"]
print statistics.realtime["tasks_by_status"]["assigned"]
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioTaskRouterClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "{{ account_sid }}"
auth_token = "{{ auth_token }}"
workspace_sid = "{{ workspace_sid }}"
workflow_sid = "{{ workflow_sid }}"

client = TwilioTaskRouterClient(account_sid, auth_token)

workflow = client.workflows(workspace_sid).update(workflow_sid,
                                                  task_reservation_timout='20')
print workflow.task_reservation_timeout

# alternatively
workflow = client.workflows(workspace_sid).get(workflow_sid)
workflow = workflow.update(task_reservation_timeout='20')
print workflow.task_reservation_timeout
Example #10
0
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioTaskRouterClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
workspace_sid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
workflow_sid = "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

client = TwilioTaskRouterClient(account_sid, auth_token)

workflow = client.workflows(workspace_sid).get(workflow_sid)
print(workflow.friendly_name)
Example #11
0
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioTaskRouterClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
workspace_sid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
workflow_sid = "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

client = TwilioTaskRouterClient(account_sid, auth_token)

workflow = client.workflows(workspace_sid).update(workflow_sid,task_reservation_timout='20')
print(workflow.task_reservation_timeout)

# alternatively
workflow = client.workflows(workspace_sid).get(workflow_sid)
workflow = workflow.update(task_reservation_timeout='20')
print(workflow.task_reservation_timeout)
Example #12
0
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioTaskRouterClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
workspace_sid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
workflow_sid = "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

client = TwilioTaskRouterClient(account_sid, auth_token)

statistics = client.workflows(workspace_sid).get(workflow_sid).statistics.get()
print(statistics.cumulative["avg_task_acceptance_time"])
print(statistics.cumulative["tasks_entered"])
print(statistics.realtime["tasks_by_status"]["pending"])
print(statistics.realtime["tasks_by_status"]["assigned"])