Skip to content

Commit

Permalink
initi commit (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
ADandyGuyInSpace committed Jul 29, 2021
1 parent 9c9c964 commit bee8bde
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 0 deletions.
22 changes: 22 additions & 0 deletions telnyx/api_resources/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,28 @@
@nested_resource_class_methods(
"gather_using_speak", path="actions/gather_using_speak", operations=["create"]
)
@nested_resource_class_methods(
"gather_stop", path="actions/gather_stop", operations=["create"]
)
@nested_resource_class_methods(
"playback_start", path="actions/playback_start", operations=["create"]
)
@nested_resource_class_methods(
"playback_stop", path="actions/playback_stop", operations=["create"]
)
@nested_resource_class_methods(
"record_pause", path="actions/record_pause", operations=["create"]
)
@nested_resource_class_methods(
"record_resume", path="actions/record_resume", operations=["create"]
)
@nested_resource_class_methods(
"record_start", path="actions/record_start", operations=["create"]
)
@nested_resource_class_methods(
"record_stop", path="actions/record_stop", operations=["create"]
)
@nested_resource_class_methods("refer", path="actions/refer", operations=["create"])
@nested_resource_class_methods(
"send_dtmf", path="actions/send_dtmf", operations=["create"]
)
Expand Down Expand Up @@ -78,18 +88,30 @@ def gather_using_audio(self, **params):
def gather_using_speak(self, **params):
return Call.create_gather_using_speak(self.call_control_id, **params)

def gather_stop(self, **params):
return Call.create_gather_stop(self.call_control_id, **params)

def playback_start(self, **params):
return Call.create_playback_start(self.call_control_id, **params)

def playback_stop(self, **params):
return Call.create_playback_stop(self.call_control_id, **params)

def record_pause(self, **params):
return Call.create_record_pause(self.call_control_id, **params)

def record_resume(self, **params):
return Call.create_record_resume(self.call_control_id, **params)

def record_start(self, **params):
return Call.create_record_start(self.call_control_id, **params)

def record_stop(self, **params):
return Call.create_record_stop(self.call_control_id, **params)

def refer(self, **params):
return Call.create_refer(self.call_control_id, **params)

def send_dtmf(self, **params):
return Call.create_send_dtmf(self.call_control_id, **params)

Expand Down
12 changes: 12 additions & 0 deletions telnyx/api_resources/conference.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
@nested_resource_class_methods("hold", path="actions/hold", operations=["create"])
@nested_resource_class_methods("unhold", path="actions/unhold", operations=["create"])
@nested_resource_class_methods("speak", path="actions/speak", operations=["create"])
@nested_resource_class_methods("play", path="actions/play", operations=["create"])
@nested_resource_class_methods("stop", path="actions/stop", operations=["create"])
@nested_resource_class_methods(
"record_start", path="actions/record_start", operations=["create"]
)
@nested_resource_class_methods(
"record_stop", path="actions/record_stop", operations=["create"]
)
@nested_resource_class_methods("update", path="actions/update", operations=["create"])
class Conference(CreateableAPIResource, ListableAPIResource):
OBJECT_NAME = "conference"

Expand All @@ -40,8 +43,17 @@ def unhold(self, **params):
def speak(self, **params):
return Conference.create_speak(self.id, **params)

def play(self, **params):
return Conference.create_play(self.call_control_id, **params)

def stop(self, **params):
return Conference.create_stop(self.call_control_id, **params)

def record_start(self, **params):
return Conference.create_record_start(self.id, **params)

def record_stop(self, **params):
return Conference.create_record_stop(self.id, **params)

def update(self, **params):
return Conference.create_update(self.id, **params)
70 changes: 70 additions & 0 deletions tests/api_resources/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,23 @@ def test_can_call_calls_gather_using_speak(self, request_mock):
)
assert isinstance(resource, telnyx.Call)

def test_can_call_gather_stop(self, request_mock):
resource = create_dial()
resource.call_control_id = CALL_CONTROL_ID
resource.gather_stop()
request_mock.assert_requested(
"post", "/v2/calls/%s/actions/gather_stop" % CALL_CONTROL_ID
)
assert isinstance(resource, telnyx.Call)

def test_can_call_calls_gather_stop(self, request_mock):
resource = create_dial()
resource.create_gather_stop(CALL_CONTROL_ID)
request_mock.assert_requested(
"post", "/v2/calls/%s/actions/gather_stop" % CALL_CONTROL_ID
)
assert isinstance(resource, telnyx.Call)

def test_can_call_playback_start(self, request_mock):
resource = create_dial()
resource.call_control_id = CALL_CONTROL_ID
Expand Down Expand Up @@ -198,6 +215,40 @@ def test_can_call_calls_playback_stop(self, request_mock):
)
assert isinstance(resource, telnyx.Call)

def test_can_call_record_pause(self, request_mock):
resource = create_dial()
resource.call_control_id = CALL_CONTROL_ID
resource.record_pause()
request_mock.assert_requested(
"post", "/v2/calls/%s/actions/record_pause" % CALL_CONTROL_ID
)
assert isinstance(resource, telnyx.Call)

def test_can_call_calls_record_pause(self, request_mock):
resource = create_dial()
resource.create_record_pause(CALL_CONTROL_ID)
request_mock.assert_requested(
"post", "/v2/calls/%s/actions/record_pause" % CALL_CONTROL_ID
)
assert isinstance(resource, telnyx.Call)

def test_can_call_record_resume(self, request_mock):
resource = create_dial()
resource.call_control_id = CALL_CONTROL_ID
resource.record_resume()
request_mock.assert_requested(
"post", "/v2/calls/%s/actions/record_resume" % CALL_CONTROL_ID
)
assert isinstance(resource, telnyx.Call)

def test_can_call_calls_record_resume(self, request_mock):
resource = create_dial()
resource.create_record_resume(CALL_CONTROL_ID)
request_mock.assert_requested(
"post", "/v2/calls/%s/actions/record_resume" % CALL_CONTROL_ID
)
assert isinstance(resource, telnyx.Call)

def test_can_call_record_start(self, request_mock):
resource = create_dial()
resource.call_control_id = CALL_CONTROL_ID
Expand Down Expand Up @@ -232,6 +283,25 @@ def test_can_call_calls_record_stop(self, request_mock):
)
assert isinstance(resource, telnyx.Call)

def test_can_call_refer(self, request_mock):
resource = create_dial()
resource.call_control_id = CALL_CONTROL_ID
resource.refer(sip_address="sip:username@sip.non-telnyx-address.com")
request_mock.assert_requested(
"post", "/v2/calls/%s/actions/refer" % CALL_CONTROL_ID
)
assert isinstance(resource, telnyx.Call)

def test_can_call_calls_refer(self, request_mock):
resource = create_dial()
resource.create_refer(
CALL_CONTROL_ID, sip_address="sip:username@sip.non-telnyx-address.com"
)
request_mock.assert_requested(
"post", "/v2/calls/%s/actions/refer" % CALL_CONTROL_ID
)
assert isinstance(resource, telnyx.Call)

def test_can_call_send_dtmf(self, request_mock):
resource = create_dial()
resource.call_control_id = CALL_CONTROL_ID
Expand Down
57 changes: 57 additions & 0 deletions tests/api_resources/test_conference.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import, division, print_function

import pytest

import telnyx

CONFERENCE_ID = "3fa85f64-5717-4562-b3fc-2c963f66afa6"
Expand All @@ -22,6 +24,11 @@ def test_is_listable(self, request_mock):
assert isinstance(resources.data, list)
assert isinstance(resources.data[0], telnyx.Conference)

def test_is_retrievable(self, request_mock):
resources = telnyx.Conference.retrieve(CONFERENCE_ID)
request_mock.assert_requested("get", "/v2/conferences/%s" % CONFERENCE_ID)
assert isinstance(resources, telnyx.Conference)

def test_is_creatable(self, request_mock):
resource = create_conference()
request_mock.assert_requested("post", "/v2/conferences")
Expand Down Expand Up @@ -147,6 +154,42 @@ def test_can_call_create_speak(self, request_mock):
)
assert isinstance(resource, telnyx.Conference)

def test_can_call_play(self, request_mock):
resource = create_conference()
resource.call_control_id = CONFERENCE_ID
resource.play(audio_url="http://www.example.com/sounds/greeting.wav")
request_mock.assert_requested(
"post", "/v2/conferences/%s/actions/play" % CONFERENCE_ID
)
assert isinstance(resource, telnyx.Conference)

def test_can_call_create_play(self, request_mock):
resource = create_conference()
resource.create_play(
CONFERENCE_ID, audio_url="http://www.example.com/sounds/greeting.wav"
)
request_mock.assert_requested(
"post", "/v2/conferences/%s/actions/play" % CONFERENCE_ID
)
assert isinstance(resource, telnyx.Conference)

def test_can_call_stop(self, request_mock):
resource = create_conference()
resource.call_control_id = CONFERENCE_ID
resource.stop()
request_mock.assert_requested(
"post", "/v2/conferences/%s/actions/stop" % CONFERENCE_ID
)
assert isinstance(resource, telnyx.Conference)

def test_can_call_create_stop(self, request_mock):
resource = create_conference()
resource.create_stop(CONFERENCE_ID)
request_mock.assert_requested(
"post", "/v2/conferences/%s/actions/stop" % CONFERENCE_ID
)
assert isinstance(resource, telnyx.Conference)

def test_can_call_record_start(self, request_mock):
resource = create_conference()
resource.record_start(
Expand Down Expand Up @@ -180,3 +223,17 @@ def test_can_call_create_record_stop(self, request_mock):
"post", "/v2/conferences/%s/actions/record_stop" % CONFERENCE_ID
)
assert isinstance(resource, telnyx.Conference)

@pytest.mark.skip(reason="Fix mock for multi args")
def test_can_call_update(self, request_mock):
resource = create_conference()
resource.create_update(
CONFERENCE_ID,
call_control_id=_call_control_id,
supervisor_role="whisper",
command_id="891510ac-f3e4-11e8-af5b-de00688a4901",
)
request_mock.assert_requested(
"post", "/v2/conference/%s/actions/update" % CONFERENCE_ID
)
assert isinstance(resource, telnyx.Conference)

0 comments on commit bee8bde

Please sign in to comment.