8000 Create dummy clients which will throw an exception when instantiated … · twilio/twilio-python@c6e75bc · GitHub
[go: up one dir, main page]

Skip to content

Commit c6e75bc

Browse files
tmconnorsdougblack
authored andcommitted
Create dummy clients which will throw an exception when instantiated (#386)
* Create dummy clients which will throw an exception when instantiated * using obsolete clients and custom warning instead of deprecated * converted warnings to exceptions * Updated tests * comment syntax
1 parent d75a66b commit c6e75bc

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed

tests/unit/rest/test_client.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import unittest
2+
from twilio.rest import (
3+
TwilioClient,
4+
TwilioRestClient,
5+
TwilioIpMessagingClient,
6+
TwilioLookupsClient,
7+
TwilioMonitorClient,
8+
TwilioPricingClient,
9+
TwilioTaskRouterClient,
10+
TwilioTrunkingClient,
11+
)
12+
from twilio.base.obsolete import ObsoleteException
13+
14+
class TestDummyClients(unittest.TestCase):
15+
def test_obsolete_exception_twilioclient(self):
16+
self.assertRaises(ObsoleteException, TwilioClient,
17+
"Expected raised ObsoleteException")
18+
19+
def test_obsolete_exception_twiliorestclient(self):
20+
self.assertRaises(ObsoleteException, TwilioRestClient,
21+
"Expected raised ObsoleteException")
22+
23+
def test_obsolete_exception_twilioipmessagingclient(self):
24+
self.assertRaises(ObsoleteException, TwilioIpMessagingClient,
25+
"Expected raised ObsoleteException")
26+
27+
def test_obsolete_exception_twiliolookupsclient(self):
28+
self.assertRaises(ObsoleteException, TwilioLookupsClient,
29+
"Expected raised ObsoleteException")
30+
31+
def test_obsolete_exception_twiliomonitorclient(self):
32+
self.assertRaises(ObsoleteException, TwilioMonitorClient,
33+
"Expected raised ObsoleteException")
34+
35+
def test_obsolete_exception_twiliopricingclient(self):
36+
self.assertRaises(ObsoleteException, TwilioPricingClient,
37+
"Expected raised ObsoleteException")
38+
39+
def test_obsolete_exception_twiliotaskrouterclient(self):
40+
self.assertRaises(ObsoleteException, TwilioTaskRouterClient,
41+
"Expected raised ObsoleteException")
42+
43+
def test_obsolete_exception_twiliotrunkingclient(self):
44+
self.assertRaises(ObsoleteException, TwilioTrunkingClient,
45+
"Expected raised ObsoleteException")

twilio/base/obsolete.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import warnings
2+
import functools
3+
4+
5+
class ObsoleteException(BaseException):
6+
""" Base class for warnings about obsolete features. """
7+
pass
8+
9+
10+
def obsolete_client(func):
11+
'''This is a decorator which can be used to mark Client classes
12+
as obsolete. It will result in an error being emitted
13+
when the class is instantiated.'''
14+
15+
@functools.wraps(func)
16+
def new_func(*args, **kwargs):
17+
raise ObsoleteException("{} has been removed from this version of the library. "
18+
"Please refer to current documentation for guidance."
19+
.format(func.__name__))
20+
21+
return new_func

twilio/rest/__init__.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import platform
1111
from twilio import __version__
1212
from twilio.base.exceptions import TwilioException
13+
from twilio.base.obsolete import obsolete_client
1314
from twilio.http.http_client import TwilioHttpClient
1415

1516

@@ -496,3 +497,75 @@ def __repr__(self):
496497
:rtype: str
497498
"""
498499
return '<Twilio {}>'.format(self.account_sid)
500+
501+
502+
@obsolete_client
503+
class TwilioClient(object):
504+
""" Dummy client which provides no functionality. Please use
505+
twilio.rest.Client instead. """
506+
507+
def __init__(self, *args):
508+
pass
509+
510+
511+
@obsolete_client
512+
class TwilioRestClient(object):
513+
""" Dummy client which provides no functionality. Please use
514+
twilio.rest.Client instead. """
515+
516+
def __init__(self, *args):
517+
pass
518+
519+
520+
@obsolete_client
521+
class TwilioIpMessagingClient(object):
522+
""" Dummy client which provides no functionality. Please use
523+
twilio.rest.Client instead. """
524+
525+
def __init__(self, *args):
526+
pass
527+
528+
529+
@obsolete_client
530+
class TwilioLookupsClient(object):
531+
""" Dummy client which provides no functionality. Please use
532+
twilio.rest.Client instead. """
533+
534+
def __init__(self, *args):
535+
pass
536+
537+
538+
@obsolete_client
539+
class TwilioMonitorClient(object):
540+
""" Dummy client which provides no functionality. Please use
541+
twilio.rest.Client instead. """
542+
543+
def __init__(self, *args):
544+
pass
545+
546+
547+
@obsolete_client
548+
class TwilioPricingClient(object):
549+
""" Dummy client which provides no functionality. Please use
550+
twilio.rest.Client instead. """
551+
552+
def __init__(self, *args):
553+
pass
554+
555+
556+
@obsolete_client
557+
class TwilioTaskRouterClient(object):
558+
""" Dummy client which provides no functionality. Please use
559+
twilio.rest.Client instead. """
560+
561+
def __init__(self, *args):
562+
pass
563+
564+
565+
@obsolete_client
566+
class TwilioTrunkingClient(object):
567+
""" Dummy client which provides no functionality. Please use
568+
twilio.rest.Client instead. """
569+
570+
def __init__(self, *args):
571+
pass

twilio/twiml/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import re
22
import xml.etree.ElementTree as ET
3+
from twilio.base.obsolete import obsolete_client
34

45

56
def lower_camel(string):
@@ -117,3 +118,11 @@ def xml(self):
117118
el.append(verb.xml())
118119

119120
return el
121+
122+
123+
@obsolete_client
124+
class Client(object):
125+
""" Dummy client which provides no functionality. """
126+
127+
def __init__(self, *args):
128+
pass

0 commit comments

Comments
 (0)
0