File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,9 @@ def __init__(self, **opts):
1414 """
1515 self .path = opts .get ('path' , os .path .abspath (os .path .dirname (__file__ )))
1616 self ._apikey = opts .get ('apikey' , os .environ .get ('SENDGRID_API_KEY' ))
17+ # Support v2 api_key naming
18+ self ._apikey = opts .get ('api_key' , os .environ .get ('SENDGRID_API_KEY' ))
19+ self ._api_key = self ._apikey
1720 self .useragent = 'sendgrid/{0};python' .format (__version__ )
1821 self .host = opts .get ('host' , 'https://api.sendgrid.com' )
1922 self .version = __version__
@@ -35,3 +38,11 @@ def apikey(self):
3538 @apikey .setter
3639 def apikey (self , value ):
3740 self ._apikey = value
41+
42+ @property
43+ def api_key (self ):
44+ return self ._apikey
45+
46+ @api_key .setter
47+ def api_key (self , value ):
48+ self ._apikey = value
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ class UnitTests(unittest.TestCase):
1818 def setUpClass (cls ):
1919 cls .host = host
2020 cls .path = '{0}{1}' .format (os .path .abspath (os .path .dirname (__file__ )), '/..' )
21- cls .sg = sendgrid .SendGridAPIClient (host = host , path = cls .path )
21+ cls .sg = sendgrid .SendGridAPIClient (host = host , path = cls .path , api_key = os . environ . get ( 'SENDGRID_API_KEY' ) )
2222 if os .path .isfile ('/usr/local/bin/prism' ) == False :
2323 if sys .platform != 'win32' :
2424 try :
@@ -38,6 +38,8 @@ def setUpClass(cls):
3838
3939 def test_apikey_init (self ):
4040 self .assertEqual (self .sg .apikey , os .environ .get ('SENDGRID_API_KEY' ))
41+ # Support the previous naming convention for API keys
42+ self .assertEqual (self .sg .api_key , self .sg .apikey )
4143
4244 def test_useragent (self ):
4345 useragent = '{0}{1}{2}' .format ('sendgrid/' , __version__ , ';python' )
You can’t perform that action at this time.
0 commit comments