8000 Create dummy clients which will throw an exception when instantiated · Pull Request #386 · twilio/twilio-python · GitHub
[go: up one dir, main page]

Skip to content

Create dummy clients which will throw an exception when instantiated #386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions tests/unit/rest/test_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import unittest
from twilio.rest import (
TwilioClient,
TwilioRestClient,
TwilioIpMessagingClient,
TwilioLookupsClient,
TwilioMonitorClient,
TwilioPricingClient,
TwilioTaskRouterClient,
TwilioTrunkingClient,
)
from twilio.base.obsolete import ObsoleteException

class TestDummyClients(unittest.TestCase):
def test_obsolete_exception_twilioclient(self):
self.assertRaises(ObsoleteException, TwilioClient,
"Expected raised ObsoleteException")

def test_obsolete_exception_twiliorestclient(self):
self.assertRaises(ObsoleteException, TwilioRestClient,
"Expected raised ObsoleteException")

def test_obsolete_exception_twilioipmessagingclient(self):
self.assertRaises(ObsoleteException, TwilioIpMessagingClient,
"Expected raised ObsoleteException")

def test_obsolete_exception_twiliolookupsclient(self):
self.assertRaises(ObsoleteException, TwilioLookupsClient,
"Expected raised ObsoleteException")

def test_obsolete_exception_twiliomonitorclient(self):
self.assertRaises(ObsoleteException, TwilioMonitorClient,
"Expected raised ObsoleteException")

def test_obsolete_exception_twiliopricingclient(self):
self.assertRaises(ObsoleteException, TwilioPricingClient,
"Expected raised ObsoleteException")

def test_obsolete_exception_twiliotaskrouterclient(self):
self.assertRaises(ObsoleteException, TwilioTaskRouterClient,
"Expected raised ObsoleteException")

def test_obsolete_exception_twiliotrunkingclient(self):
self.assertRaises(ObsoleteException, TwilioTrunkingClient,
"Expected raised ObsoleteException")
21 changes: 21 additions & 0 deletions twilio/base/obsolete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import warnings
import functools


class ObsoleteException(BaseException):
""" Base class for warnings about obsolete features. """
pass


def obsolete_client(func):
'''This is a decorator which can be used to mark Client classes
as obsolete. It will result in an error being emitted
when the class is instantiated.'''

@functools.wraps(func)
def new_func(*args, **kwargs):
raise ObsoleteException("{} has been removed from this version of the library. "
"Please refer to current documentation for guidance."
.format(func.__name__))

return new_func
73 changes: 73 additions & 0 deletions twilio/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import platform
from twilio import __version__
from twilio.base.exceptions import TwilioException
from twilio.base.obsolete import obsolete_client
from twilio.http.http_client import TwilioHttpClient


Expand Down Expand Up @@ -496,3 +497,75 @@ def __repr__(self):
:rtype: str
"""
return '<Twilio {}>'.format(self.account_sid)


@obsolete_client
class TwilioClient(object):
""" Dummy client which provides no functionality. Please use
twilio.rest.Client instead. """

def __init__(self, *args):
pass


@obsolete_client
class TwilioRestClient(object):
""" Dummy client which provides no functionality. Please use
twilio.rest.Client instead. """

def __init__(self, *args):
pass


@obsolete_client
class TwilioIpMessagingClient(object):
""" Dummy client which provides no functionality. Please use
twilio.rest.Client instead. """

def __init__(self, *args):
pass


@obsolete_client
class TwilioLookupsClient(object):
""" Dummy client which provides no functionality. Please use
twilio.rest.Client instead. """

def __init__(self, *args):
pass


@obsolete_client
class TwilioMonitorClient(object):
""" Dummy client which provides no functionality. Please use
twilio.rest.Client instead. """

def __init__(self, *args):
pass


@obsolete_client
class TwilioPricingClient(object):
""" Dummy client which provides no functionality. Please use
twilio.rest.Client instead. """

def __init__(self, *args):
pass


@obsolete_client
class TwilioTaskRouterClient(object):
""" Dummy client which provides no functionality. Please use
twilio.rest.Client instead. """

def __init__(self, *args):
pass


@obsolete_client
class TwilioTrunkingClient(object):
""" Dummy client which provides no functionality. Please use
twilio.rest.Client instead. """

def __init__(self, *args):
pass
9 changes: 9 additions & 0 deletions twilio/twiml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import xml.etree.ElementTree as ET
from twilio.base.obsolete import obsolete_client


def lower_camel(string):
Expand Down Expand Up @@ -117,3 +118,11 @@ def xml(self):
el.append(verb.xml())

return el


@obsolete_client
class Client(object):
""" Dummy client which provides no functionality. """

def __init__(self, *args):
pass
0