Skip to content

Commit

Permalink
Merge a8eaf52 into e118c79
Browse files Browse the repository at this point in the history
  • Loading branch information
kanemathers committed Apr 1, 2020
2 parents e118c79 + a8eaf52 commit c20d39c
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ cache:
env:
global:
# If changing this number, please also change it in `tests/conftest.py`.
- TELNYX_MOCK_VERSION=0.8.6
- TELNYX_MOCK_VERSION=0.8.7

before_install:
# Unpack and start telnyx-mock so that the test suite can talk to it
Expand Down
2 changes: 2 additions & 0 deletions telnyx/api_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from telnyx.api_resources.event import Event
from telnyx.api_resources.fqdn import FQDN
from telnyx.api_resources.fqdn_connection import FQDNConnection
from telnyx.api_resources.inbound_channel import InboundChannel
from telnyx.api_resources.ip import IP
from telnyx.api_resources.ip_connection import IPConnection
from telnyx.api_resources.list_object import ListObject
Expand Down Expand Up @@ -43,6 +44,7 @@
"Event",
"FQDN",
"FQDNConnection",
"InboundChannel",
"IP",
"IPConnection",
"ListObject",
Expand Down
11 changes: 3 additions & 8 deletions telnyx/api_resources/abstract/updateable_api_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,14 @@ def save(self):

if updated_params:
self.refresh_from(
self.request(
UpdateableAPIResource.save_method(self),
self.instance_url(),
updated_params,
)
self.request(self.save_method(), self.instance_url(), updated_params)
)
else:
util.logger.debug("Trying to save already saved object %r", self)
return self

@classmethod
def save_method(cls, instance):
if instance.id is None:
def save_method(self):
if self.id is None:
return "post"
else:
return "patch"
26 changes: 26 additions & 0 deletions telnyx/api_resources/inbound_channel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from __future__ import absolute_import, division, print_function

from telnyx.api_resources.abstract import UpdateableAPIResource


class InboundChannel(UpdateableAPIResource):
OBJECT_NAME = "inbound_channels"

@classmethod
def class_url(cls):
return "/v2/phone_numbers/inbound_channels"

def instance_url(self):
return "/v2/phone_numbers/inbound_channels"

@classmethod
def modify(cls, **params):
url = "/v2/phone_numbers/inbound_channels"
return cls._modify(url, **params)

@classmethod
def retrieve(cls, api_key=None, **params):
return super().retrieve(None, api_key, **params)

def save_method(self):
return "patch"
1 change: 1 addition & 0 deletions telnyx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def load_object_classes():
api_resources.CredentialConnection.OBJECT_NAME: api_resources.CredentialConnection,
api_resources.FQDN.OBJECT_NAME: api_resources.FQDN,
api_resources.FQDNConnection.OBJECT_NAME: api_resources.FQDNConnection,
api_resources.InboundChannel.OBJECT_NAME: api_resources.InboundChannel,
api_resources.IP.OBJECT_NAME: api_resources.IP,
api_resources.IPConnection.OBJECT_NAME: api_resources.IPConnection,
api_resources.Message.OBJECT_NAME: api_resources.Message,
Expand Down
25 changes: 25 additions & 0 deletions tests/api_resources/test_inbound_channel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import absolute_import, division, print_function

import pytest

import telnyx


class TestInboundChannels(object):
def test_is_retrievable(self, request_mock):
resource = telnyx.InboundChannel.retrieve()
request_mock.assert_requested("get", "/v2/phone_numbers/inbound_channels")
assert isinstance(resource, telnyx.InboundChannel)

def test_is_saveable(self, request_mock):
inbound_channels = telnyx.InboundChannel.retrieve()
inbound_channels.channels = 10
resource = inbound_channels.save()
request_mock.assert_requested("patch", "/v2/phone_numbers/inbound_channels")
assert isinstance(resource, telnyx.InboundChannel)
assert resource is inbound_channels

def test_is_modifiable(self, request_mock):
resource = telnyx.InboundChannel.modify(channels=10)
request_mock.assert_requested("patch", "/v2/phone_numbers/inbound_channels")
assert isinstance(resource, telnyx.InboundChannel)
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from telnyx.six.moves.urllib.request import urlopen

# When changing this number, don't forget to change it in `.travis.yml` too.
MOCK_MINIMUM_VERSION = "0.8.6"
MOCK_MINIMUM_VERSION = "0.8.7"

# Starts telnyx-mock if an OpenAPI spec override is found in `openapi/`, and
# otherwise fall back to `TELNYX_MOCK_PORT` or 12111.
Expand Down

0 comments on commit c20d39c

Please sign in to comment.