Skip to content

Commit 1a73d99

Browse files
authored
Update environment variables to match secrets (#30)
1 parent 9a8f09a commit 1a73d99

File tree

1 file changed

+57
-60
lines changed

1 file changed

+57
-60
lines changed

tests/integration/api_tests.py

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88
from bandwidth.bandwidth_client import BandwidthClient
99
from bandwidth.messaging.exceptions.messaging_exception import MessagingException
10-
from bandwidth.voice.exceptions.api_exception import APIException
10+
from bandwidth.exceptions.api_exception import APIException
1111
from bandwidth.messaging.models.message_request import MessageRequest
1212
from bandwidth.voice.models.create_call_request import CreateCallRequest
1313
from bandwidth.voice.models.machine_detection_request import MachineDetectionRequest
@@ -20,17 +20,14 @@
2020
import os
2121

2222
try:
23-
USERNAME = os.environ["USERNAME"]
24-
PASSWORD = os.environ["PASSWORD"]
25-
ACCOUNT_ID = os.environ["ACCOUNT_ID"]
26-
VOICE_APPLICATION_ID = os.environ["VOICE_APPLICATION_ID"]
27-
MESSAGING_APPLICATION_ID = os.environ["MESSAGING_APPLICATION_ID"]
28-
CALLBACK_URL = os.environ["CALLBACK_URL"]
29-
PHONE_NUMBER_OUTBOUND = os.environ["PHONE_NUMBER_OUTBOUND"]
30-
PHONE_NUMBER_INBOUND = os.environ["PHONE_NUMBER_INBOUND"]
31-
MFA_MESSAGING_APPLICATION_ID = os.environ["MFA_MESSAGING_APPLICATION_ID"]
32-
MFA_VOICE_APPLICATION_ID = os.environ["MFA_VOICE_APPLICATION_ID"]
33-
PHONE_NUMBER_MFA = os.environ["PHONE_NUMBER_MFA"]
23+
BW_USERNAME = os.environ["BW_USERNAME"]
24+
BW_PASSWORD = os.environ["BW_PASSWORD"]
25+
BW_ACCOUNT_ID = os.environ["BW_ACCOUNT_ID"]
26+
BW_VOICE_APPLICATION_ID = os.environ["BW_VOICE_APPLICATION_ID"]
27+
BW_MESSAGING_APPLICATION_ID = os.environ["BW_MESSAGING_APPLICATION_ID"]
28+
BASE_CALLBACK_URL = os.environ["BASE_CALLBACK_URL"]
29+
BW_NUMBER = os.environ["BW_NUMBER"]
30+
USER_NUMBER = os.environ["USER_NUMBER"]
3431
except:
3532
raise Exception("Environmental variables not found")
3633

@@ -45,14 +42,14 @@ def setUp(self):
4542
Creates the client object
4643
"""
4744
self.bandwidth_client = BandwidthClient(
48-
voice_basic_auth_user_name=USERNAME,
49-
voice_basic_auth_password=PASSWORD,
50-
messaging_basic_auth_user_name=USERNAME,
51-
messaging_basic_auth_password=PASSWORD,
52-
multi_factor_auth_basic_auth_user_name=USERNAME,
53-
multi_factor_auth_basic_auth_password=PASSWORD,
54-
phone_number_lookup_basic_auth_user_name=USERNAME,
55-
phone_number_lookup_basic_auth_password=PASSWORD,
45+
voice_basic_auth_user_name=BW_USERNAME,
46+
voice_basic_auth_password=BW_PASSWORD,
47+
messaging_basic_auth_user_name=BW_USERNAME,
48+
messaging_basic_auth_password=BW_PASSWORD,
49+
multi_factor_auth_basic_auth_user_name=BW_USERNAME,
50+
multi_factor_auth_basic_auth_password=BW_PASSWORD,
51+
phone_number_lookup_basic_auth_user_name=BW_USERNAME,
52+
phone_number_lookup_basic_auth_password=BW_PASSWORD,
5653
)
5754
self.voice_client = self.bandwidth_client.voice_client.client
5855
self.messaging_client = self.bandwidth_client.messaging_client.client
@@ -62,22 +59,22 @@ def setUp(self):
6259

6360
def test_create_message(self):
6461
body = MessageRequest()
65-
body.application_id = MESSAGING_APPLICATION_ID
66-
body.to = [PHONE_NUMBER_INBOUND]
67-
body.mfrom = PHONE_NUMBER_OUTBOUND
62+
body.application_id = BW_MESSAGING_APPLICATION_ID
63+
body.to = [USER_NUMBER]
64+
body.mfrom = BW_NUMBER
6865
body.text = "Python Monitoring"
69-
response = self.messaging_client.create_message(ACCOUNT_ID, body)
66+
response = self.messaging_client.create_message(BW_ACCOUNT_ID, body)
7067
self.assertTrue(len(response.body.id) > 0) #validate that _some_ id was returned
7168

7269

7370
def test_create_message_invalid_phone_number(self):
7471
body = MessageRequest()
75-
body.application_id = MESSAGING_APPLICATION_ID
72+
body.application_id = BW_MESSAGING_APPLICATION_ID
7673
body.to = ["+1invalid"]
77-
body.mfrom = PHONE_NUMBER_OUTBOUND
74+
body.mfrom = BW_NUMBER
7875
body.text = "Python Monitoring"
7976
try:
80-
self.messaging_client.create_message(ACCOUNT_ID, body)
77+
self.messaging_client.create_message(BW_ACCOUNT_ID, body)
8178
self.assertTrue(False)
8279
except MessagingException as e:
8380
self.assertTrue(len(e.description) > 0)
@@ -91,37 +88,37 @@ def test_upload_download_media(self):
9188
media_file = b'12345'
9289

9390
#media upload
94-
self.messaging_client.upload_media(ACCOUNT_ID, media_file_name, media_file)
91+
self.messaging_client.upload_media(BW_ACCOUNT_ID, media_file_name, media_file)
9592

9693
#media download
97-
downloaded_media_file = self.messaging_client.get_media(ACCOUNT_ID, media_file_name).body
94+
downloaded_media_file = self.messaging_client.get_media(BW_ACCOUNT_ID, media_file_name).body
9895

9996
#validate that the response is the same as the upload
10097
self.assertEqual(media_file, downloaded_media_file)
10198

10299

103100
def test_create_call_and_get_call(self):
104101
body = CreateCallRequest()
105-
body.mfrom = PHONE_NUMBER_OUTBOUND
106-
body.to = PHONE_NUMBER_INBOUND
107-
body.application_id = VOICE_APPLICATION_ID
108-
body.answer_url = CALLBACK_URL
109-
response = self.voice_client.create_call(ACCOUNT_ID, body)
102+
body.mfrom = BW_NUMBER
103+
body.to = USER_NUMBER
104+
body.application_id = BW_VOICE_APPLICATION_ID
105+
body.answer_url = BASE_CALLBACK_URL
106+
response = self.voice_client.create_call(BW_ACCOUNT_ID, body)
110107
self.assertTrue(len(response.body.call_id) > 1)
111108

112109
#get phone call information
113-
response = self.voice_client.get_call(ACCOUNT_ID, response.body.call_id)
110+
response = self.voice_client.get_call(BW_ACCOUNT_ID, response.body.call_id)
114111
self.assertTrue(len(response.body.state) > 1)
115112

116113

117114
def test_create_call_invalid_phone_number(self):
118115
body = CreateCallRequest()
119-
body.mfrom = PHONE_NUMBER_OUTBOUND
116+
body.mfrom = BW_NUMBER
120117
body.to = "+1invalid"
121-
body.application_id = VOICE_APPLICATION_ID
122-
body.answer_url = CALLBACK_URL
118+
body.application_id = BW_VOICE_APPLICATION_ID
119+
body.answer_url = BASE_CALLBACK_URL
123120
try:
124-
self.voice_client.create_call(ACCOUNT_ID, body)
121+
self.voice_client.create_call(BW_ACCOUNT_ID, body)
125122
except APIException as e:
126123
self.assertTrue(len(e.description) > 0)
127124
except:
@@ -131,7 +128,7 @@ def test_create_call_invalid_phone_number(self):
131128
def create_call_amd_and_get_call(self):
132129
machine_detection_parameters = MachineDetectionRequest()
133130
machine_detection_parameters.mode = "async"
134-
machine_detection_parameters.callback_url = CALLBACK_URL
131+
machine_detection_parameters.callback_url = BASE_CALLBACK_URL
135132
machine_detection_parameters.callback_method = "POST"
136133
machine_detection_parameters.detection_timeout = 5.0
137134
machine_detection_parameters.silence_timeout = 5.0
@@ -140,16 +137,16 @@ def create_call_amd_and_get_call(self):
140137
machine_detection_parameters.delay_result = True
141138

142139
body = CreateCallRequest()
143-
body.mfrom = PHONE_NUMBER_OUTBOUND
144-
body.to = PHONE_NUMBER_INBOUND
145-
body.application_id = VOICE_APPLICATION_ID
146-
body.answer_url = CALLBACK_URL
140+
body.mfrom = BW_NUMBER
141+
body.to = USER_NUMBER
142+
body.application_id = BW_VOICE_APPLICATION_ID
143+
body.answer_url = BASE_CALLBACK_URL
147144
body.machine_detection = machine_detection_parameters
148-
create_response = self.voice_client.create_call(ACCOUNT_ID, body)
145+
create_response = self.voice_client.create_call(BW_ACCOUNT_ID, body)
149146
self.assertTrue(len(create_response.body.call_id) > 1)
150147

151148
#get phone call information
152-
get_response = self.voice_client.get_call(ACCOUNT_ID, create_response.body.call_id)
149+
get_response = self.voice_client.get_call(BW_ACCOUNT_ID, create_response.body.call_id)
153150
self.assertTrue(len(get_response.body.state) > 1)
154151
self.assertEqual(get_response.body.callId, create_response.body.call_id)
155152
self.assertIs(get_response.body.call_id, str)
@@ -172,51 +169,51 @@ def create_call_amd_and_get_call(self):
172169

173170
def test_mfa_messaging(self):
174171
body = TwoFactorCodeRequestSchema(
175-
mfrom = PHONE_NUMBER_MFA,
176-
to = PHONE_NUMBER_INBOUND,
177-
application_id = MFA_MESSAGING_APPLICATION_ID,
172+
mfrom = BW_NUMBER,
173+
to = USER_NUMBER,
174+
application_id = BW_MESSAGING_APPLICATION_ID,
178175
scope = "scope",
179176
digits = 6,
180177
message = "Your temporary {NAME} {SCOPE} code is {CODE}"
181178
)
182-
response = self.auth_client.create_messaging_two_factor(ACCOUNT_ID, body)
179+
response = self.auth_client.create_messaging_two_factor(BW_ACCOUNT_ID, body)
183180
self.assertTrue(len(response.body.message_id) > 0)
184181

185182

186183
def test_mfa_voice(self):
187184
body = TwoFactorCodeRequestSchema(
188-
mfrom = PHONE_NUMBER_MFA,
189-
to = PHONE_NUMBER_INBOUND,
190-
application_id = MFA_VOICE_APPLICATION_ID,
185+
mfrom = BW_NUMBER,
186+
to = USER_NUMBER,
187+
application_id = BW_VOICE_APPLICATION_ID,
191188
scope = "scope",
192189
digits = 6,
193190
message = "Your temporary {NAME} {SCOPE} code is {CODE}"
194191
)
195-
response = self.auth_client.create_voice_two_factor(ACCOUNT_ID, body)
192+
response = self.auth_client.create_voice_two_factor(BW_ACCOUNT_ID, body)
196193
self.assertTrue(len(response.body.call_id) > 0)
197194

198195

199196
def test_mfa_verify(self):
200197
body = TwoFactorVerifyRequestSchema(
201-
to = PHONE_NUMBER_INBOUND,
202-
application_id = MFA_VOICE_APPLICATION_ID,
198+
to = USER_NUMBER,
199+
application_id = BW_VOICE_APPLICATION_ID,
203200
scope = "scope",
204201
code = "123456",
205202
expiration_time_in_minutes = 3
206203
)
207-
response = self.auth_client.create_verify_two_factor(ACCOUNT_ID, body)
204+
response = self.auth_client.create_verify_two_factor(BW_ACCOUNT_ID, body)
208205
self.assertTrue(isinstance(response.body.valid, bool))
209206

210207

211208
def test_tn_lookup(self):
212209
body = OrderRequest()
213-
body.tns = [PHONE_NUMBER_OUTBOUND]
214-
response = self.tn_lookup_client.create_lookup_request(ACCOUNT_ID, body)
210+
body.tns = [BW_NUMBER]
211+
response = self.tn_lookup_client.create_lookup_request(BW_ACCOUNT_ID, body)
215212
self.assertTrue(response.status_code == 202)
216213

217214
# test get method with the returned request_id
218215
request_id = response.body.request_id
219-
get_response = self.tn_lookup_client.get_lookup_request_status(ACCOUNT_ID, request_id)
216+
get_response = self.tn_lookup_client.get_lookup_request_status(BW_ACCOUNT_ID, request_id)
220217
self.assertTrue(get_response.status_code == 200)
221218

222219

0 commit comments

Comments
 (0)