Skip to content

Commit 43d1916

Browse files
committed
restore test files
1 parent 5ab7b57 commit 43d1916

File tree

8 files changed

+1794
-255
lines changed

8 files changed

+1794
-255
lines changed

test/smoke/test_calls_api.py

Lines changed: 203 additions & 203 deletions
Large diffs are not rendered by default.

test/smoke/test_conferences_api.py

Lines changed: 468 additions & 0 deletions
Large diffs are not rendered by default.

test/smoke/test_media_api.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
"""
2+
Integration test for Bandwidth's Messaging Media API
3+
"""
4+
5+
import uuid
6+
import filecmp
7+
import unittest
8+
import logging
9+
10+
from bandwidth import ApiResponse
11+
12+
import bandwidth
13+
from hamcrest import *
14+
from bandwidth.api import media_api
15+
from bandwidth.models.media import Media
16+
from bandwidth.exceptions import ApiException, NotFoundException
17+
from test.utils.env_variables import *
18+
19+
20+
class TestMedia(unittest.TestCase):
21+
"""Media API integration Test
22+
"""
23+
24+
def setUp(self) -> None:
25+
configuration = bandwidth.Configuration(
26+
username=BW_USERNAME,
27+
password=BW_PASSWORD
28+
)
29+
self.api_client = bandwidth.ApiClient(configuration)
30+
self.api_instance = media_api.MediaApi(self.api_client)
31+
self.account_id = BW_ACCOUNT_ID
32+
self.media_path = "./test/fixtures/"
33+
self.media_file = "python_cat.jpeg"
34+
self.media_id = PYTHON_VERSION + "_" + RUNNER_OS + "_" + str(uuid.uuid4()) + "_" + self.media_file
35+
self.download_file_path = "cat_download.jpeg"
36+
self.original_file = open(self.media_path + self.media_file, "rb")
37+
38+
def uploadMedia(self) -> None:
39+
"""Test uploading media
40+
"""
41+
media_id = self.media_id
42+
content_type = "image/jpeg"
43+
cache_control = "no-cache"
44+
45+
api_response_with_http_info: ApiResponse = self.api_instance.upload_media_with_http_info(
46+
account_id=self.account_id,
47+
media_id=media_id,
48+
body=bytes(self.original_file.read()),
49+
_content_type=content_type,
50+
cache_control=cache_control
51+
)
52+
53+
logging.debug(api_response_with_http_info)
54+
assert_that(api_response_with_http_info.status_code, equal_to(204))
55+
56+
# reopen the media file
57+
# the client automatically closes any files passed into request bodies
58+
reopened_file = open(self.media_path + self.media_file, "rb")
59+
60+
# returns void
61+
self.api_instance.upload_media(
62+
account_id=self.account_id,
63+
media_id=media_id,
64+
body=bytes(reopened_file.read()),
65+
_content_type=content_type,
66+
cache_control=cache_control
67+
)
68+
69+
def listMedia(self) -> None:
70+
"""Test listing all media on the account
71+
"""
72+
api_response_with_http_info = self.api_instance.list_media_with_http_info(
73+
self.account_id)
74+
75+
assert_that(api_response_with_http_info.status_code, equal_to(200))
76+
77+
api_response = self.api_instance.list_media(self.account_id)
78+
logging.debug("List Media" + str(api_response))
79+
80+
assert_that(api_response[0], instance_of(Media))
81+
pass
82+
83+
def getMedia(self) -> None:
84+
"""Test downloading the media we previously uploaded
85+
"""
86+
api_response_with_http_info = self.api_instance.get_media_with_http_info(
87+
self.account_id, self.media_id)
88+
89+
logging.debug(api_response_with_http_info)
90+
assert_that(api_response_with_http_info.status_code, equal_to(200))
91+
assert_that(api_response_with_http_info.headers["Content-Type"], equal_to("image/jpeg"))
92+
93+
api_response = self.api_instance.get_media(
94+
self.account_id, self.media_id)
95+
96+
with open(self.media_path + self.download_file_path, "wb") as download_file:
97+
download_file.write(api_response)
98+
99+
assert_that(filecmp.cmp(self.media_path + self.media_file,
100+
self.media_path + self.download_file_path), equal_to(True))
101+
download_file.close()
102+
103+
def deleteMedia(self) -> None:
104+
"""Test deleting the media that we previously uploaded
105+
"""
106+
api_response_with_http_info = self.api_instance.delete_media_with_http_info(
107+
self.account_id, self.media_id)
108+
109+
logging.debug(api_response_with_http_info)
110+
assert_that(api_response_with_http_info.status_code, equal_to(204))
111+
112+
# returns void
113+
self.api_instance.delete_media(self.account_id, self.media_id)
114+
115+
def _steps(self):
116+
call_order = ['uploadMedia', 'listMedia', 'getMedia', 'deleteMedia']
117+
for name in call_order:
118+
yield name, getattr(self, name)
119+
120+
def test_steps(self) -> None:
121+
"""Test each function from _steps.call_order in specified order
122+
"""
123+
124+
for name, step in self._steps():
125+
step()
126+
127+
@unittest.skip("API does not support url encoded characters in path")
128+
def testGetMediaWithBandwidthId(self) -> None:
129+
# use a nonexistent mediaId - results in a 404
130+
media_id = "abcd1234-e5f6-1111-2222-3456ghi7890/image123456.jpg"
131+
132+
assert_that(calling(self.api_instance.get_media).with_args(
133+
self.account_id, media_id, _preload_content=False)), raises(NotFoundException)

test/smoke/test_messages_api.py

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -95,58 +95,58 @@ def test_create_message(self):
9595
)
9696
assert_that(api_response.time, instance_of(datetime))
9797

98-
# def test_create_message_bad_request(self):
99-
# assert_that(calling(self.api_instance.create_message).with_args(
100-
# self.account_id, self.invalid_message_request)), raises(ApiException)
101-
102-
# def test_create_message_unauthorized(self):
103-
# assert_that(calling(self.unauthorized_api_instance.create_message).with_args(
104-
# self.account_id, self.invalid_message_request)), raises(UnauthorizedException)
105-
106-
# @unittest.skip('The SDK catches incorrect content-type before making the request and attempts to create an ApiException,\
107-
# but the creation of the exception fails since there is no response body. This should probably create some\
108-
# kind of Client Exception instead, since this is not an actual API Exception.')
109-
# def test_create_message_invalid_media(self):
110-
# assert_that(calling(self.api_instance.create_message).with_args(
111-
# self.account_id, self.message_request, _content_type='application/xml')), raises(ApiException)
112-
113-
# def test_list_messages(self):
114-
# message_direction = ListMessageDirectionEnum("OUTBOUND")
115-
116-
# response = self.api_instance.list_messages_with_http_info(self.account_id, message_direction=message_direction)
117-
118-
# assert_that(response.status_code, equal_to(200))
119-
120-
# api_response = response.data
121-
# assert_that(api_response, instance_of(MessagesList))
122-
# assert_that(api_response, has_properties(
123-
# 'total_count', greater_than(0),
124-
# 'messages', instance_of(list)
125-
# ))
126-
127-
# assert_that(api_response.messages[0], instance_of(ListMessageItem))
128-
129-
# message = api_response.messages[0]
130-
# assert_that(message, has_properties(
131-
# 'account_id', self.account_id,
132-
# 'destination_tn', matches_regexp('^\\+[1-9]\\d{1,14}$'),
133-
# 'message_direction', ListMessageDirectionEnum("OUTBOUND"),
134-
# 'message_id', matches_regexp('^.+$'),
135-
# 'message_status', instance_of(MessageStatusEnum),
136-
# 'message_type', instance_of(MessageTypeEnum),
137-
# 'segment_count', greater_than(0),
138-
# 'source_tn', matches_regexp('^\\+[1-9]\\d{1,14}$'),
139-
# 'calling_number_country_a3', equal_to('USA')
140-
# ))
141-
# assert_that(message.receive_time, instance_of(datetime))
142-
143-
# def test_list_messages_bad_request(self):
144-
# assert_that(calling(self.api_instance.list_messages).with_args(
145-
# self.account_id), raises(ApiException))
146-
147-
# def test_list_messages_unauthorized(self):
148-
# assert_that(calling(self.unauthorized_api_instance.list_messages).with_args(
149-
# self.account_id), raises(UnauthorizedException))
98+
def test_create_message_bad_request(self):
99+
assert_that(calling(self.api_instance.create_message).with_args(
100+
self.account_id, self.invalid_message_request)), raises(ApiException)
101+
102+
def test_create_message_unauthorized(self):
103+
assert_that(calling(self.unauthorized_api_instance.create_message).with_args(
104+
self.account_id, self.invalid_message_request)), raises(UnauthorizedException)
105+
106+
@unittest.skip('The SDK catches incorrect content-type before making the request and attempts to create an ApiException,\
107+
but the creation of the exception fails since there is no response body. This should probably create some\
108+
kind of Client Exception instead, since this is not an actual API Exception.')
109+
def test_create_message_invalid_media(self):
110+
assert_that(calling(self.api_instance.create_message).with_args(
111+
self.account_id, self.message_request, _content_type='application/xml')), raises(ApiException)
112+
113+
def test_list_messages(self):
114+
message_direction = ListMessageDirectionEnum("OUTBOUND")
115+
116+
response = self.api_instance.list_messages_with_http_info(self.account_id, message_direction=message_direction)
117+
118+
assert_that(response.status_code, equal_to(200))
119+
120+
api_response = response.data
121+
assert_that(api_response, instance_of(MessagesList))
122+
assert_that(api_response, has_properties(
123+
'total_count', greater_than(0),
124+
'messages', instance_of(list)
125+
))
126+
127+
assert_that(api_response.messages[0], instance_of(ListMessageItem))
128+
129+
message = api_response.messages[0]
130+
assert_that(message, has_properties(
131+
'account_id', self.account_id,
132+
'destination_tn', matches_regexp('^\\+[1-9]\\d{1,14}$'),
133+
'message_direction', ListMessageDirectionEnum("OUTBOUND"),
134+
'message_id', matches_regexp('^.+$'),
135+
'message_status', instance_of(MessageStatusEnum),
136+
'message_type', instance_of(MessageTypeEnum),
137+
'segment_count', greater_than(0),
138+
'source_tn', matches_regexp('^\\+[1-9]\\d{1,14}$'),
139+
'calling_number_country_a3', equal_to('USA')
140+
))
141+
assert_that(message.receive_time, instance_of(datetime))
142+
143+
def test_list_messages_bad_request(self):
144+
assert_that(calling(self.api_instance.list_messages).with_args(
145+
self.account_id), raises(ApiException))
146+
147+
def test_list_messages_unauthorized(self):
148+
assert_that(calling(self.unauthorized_api_instance.list_messages).with_args(
149+
self.account_id), raises(UnauthorizedException))
150150

151151

152152
if __name__ == '__main__':

0 commit comments

Comments
 (0)