8000 Add tests for find_credentials method · Twilio-api/twilio-python@d5157c5 · GitHub
[go: up one dir, main page]

Skip to content

Commit d5157c5

Browse files
author
Kevin Burke
committed
Add tests for find_credentials method
1 parent c330d05 commit d5157c5

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

tests/test_credentials.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from nose.tools import assert_equal
2+
3+
from twilio.rest import find_credentials
4+
5+
def test_creds_not_found():
6+
""" I shouldn't find credentials if they are not there """
7+
assert_equal(find_credentials({'foo': 'bar'}), (None, None))
8+
9+
def test_find_creds():
10+
""" I should find the credentials if they are there """
11+
env = {
12+
'TWILIO_ACCOUNT_SID': 'AC123',
13+
'foo': 'bar',
14+
'TWILIO_AUTH_TOKEN': '456',
15+
}
16+
assert_equal(find_credentials(env), ('AC123', '456'))
17+

twilio/rest/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828
from twilio.rest.resources import Usage
2929

3030

31-
def find_credentials():
31+
def find_credentials(environ=None):
3232
"""
3333
Look in the current environment for Twilio credentials
34+
35+
:param environ: the environment to check
3436
"""
37+
environment = environ or os.environ
3538
try:
36-
account = os.environ["TWILIO_ACCOUNT_SID"]
37-
token = os.environ["TWILIO_AUTH_TOKEN"]
39+
account = environment["TWILIO_ACCOUNT_SID"]
40+
token = environment["TWILIO_AUTH_TOKEN"]
3841
return account, token
3942
except KeyError:
4043
return None, None

0 commit comments

Comments
 (0)
0