1818from bandwidth .models .endpoint_type_enum import EndpointTypeEnum
1919from bandwidth .models .endpoint_direction_enum import EndpointDirectionEnum
2020from bandwidth .models .endpoint_status_enum import EndpointStatusEnum
21- from bandwidth .exceptions import ApiException
21+ from bandwidth .exceptions import UnauthorizedException , ForbiddenException , NotFoundException
2222from test .utils .env_variables import *
2323
2424
@@ -34,9 +34,20 @@ def setUpClass(cls) -> None:
3434 api_client = ApiClient (configuration )
3535 cls .endpoints_api_instance = EndpointsApi (api_client )
3636
37- cls .unauthorized_api_instance = EndpointsApi (ApiClient ())
37+ unauthorized_configuration = Configuration (
38+ username = 'bad_username' ,
39+ password = 'bad_password'
40+ )
41+ cls .unauthorized_api_instance = EndpointsApi (ApiClient (unauthorized_configuration ))
42+
43+ forbidden_configuration = Configuration (
44+ username = FORBIDDEN_USERNAME ,
45+ password = FORBIDDEN_PASSWORD
46+ )
47+ cls .forbidden_api_instance = EndpointsApi (ApiClient (forbidden_configuration ))
3848
3949 cls .account_id = BW_ACCOUNT_ID
50+ cls .test_endpoint_id = 'endpoint-id'
4051
4152 def createEndpoint (self ):
4253 create_request = CreateWebRtcConnectionRequest (
@@ -150,19 +161,86 @@ def test_steps(self):
150161 for name , step in self ._steps ():
151162 step ()
152163
164+ def assertApiException (self , context , expected_status_code : int ):
165+ assert_that (context .exception , has_properties (
166+ 'status' , expected_status_code ,
167+ ))
168+
153169 def test_create_endpoint_unauthorized (self ):
154170 create_request = CreateWebRtcConnectionRequest (
155171 type = EndpointTypeEnum .WEBRTC ,
156172 direction = EndpointDirectionEnum .BIDIRECTIONAL
157173 )
158174
159- with self .assertRaises (ApiException ) as context :
175+ with self .assertRaises (UnauthorizedException ) as context :
160176 self .unauthorized_api_instance .create_endpoint (
161177 self .account_id ,
162178 create_request
163179 )
164180
165- assert_that (context .exception .status , equal_to (401 ))
181+ self .assertApiException (context , 401 )
182+
183+ def test_create_endpoint_forbidden (self ):
184+ create_request = CreateWebRtcConnectionRequest (
185+ type = EndpointTypeEnum .WEBRTC ,
186+ direction = EndpointDirectionEnum .BIDIRECTIONAL
187+ )
188+
189+ with self .assertRaises (ForbiddenException ) as context :
190+ self .forbidden_api_instance .create_endpoint (
191+ self .account_id ,
192+ create_request
193+ )
194+
195+ self .assertApiException (context , 403 )
196+
197+ def test_list_endpoints_unauthorized (self ):
198+ with self .assertRaises (UnauthorizedException ) as context :
199+ self .unauthorized_api_instance .list_endpoints (self .account_id )
200+
201+ self .assertApiException (context , 401 )
202+
203+ def test_list_endpoints_forbidden (self ):
204+ with self .assertRaises (ForbiddenException ) as context :
205+ self .forbidden_api_instance .list_endpoints (self .account_id )
206+
207+ self .assertApiException (context , 403 )
208+
209+ def test_get_endpoint_unauthorized (self ):
210+ with self .assertRaises (UnauthorizedException ) as context :
211+ self .unauthorized_api_instance .get_endpoint (self .account_id , self .test_endpoint_id )
212+
213+ self .assertApiException (context , 401 )
214+
215+ def test_get_endpoint_forbidden (self ):
216+ with self .assertRaises (ForbiddenException ) as context :
217+ self .forbidden_api_instance .get_endpoint (self .account_id , self .test_endpoint_id )
218+
219+ self .assertApiException (context , 403 )
220+
221+ def test_get_endpoint_not_found (self ):
222+ with self .assertRaises (NotFoundException ) as context :
223+ self .endpoints_api_instance .get_endpoint (self .account_id , self .test_endpoint_id )
224+
225+ self .assertApiException (context , 404 )
226+
227+ def test_delete_endpoint_unauthorized (self ):
228+ with self .assertRaises (UnauthorizedException ) as context :
229+ self .unauthorized_api_instance .delete_endpoint (self .account_id , self .test_endpoint_id )
230+
231+ self .assertApiException (context , 401 )
232+
233+ def test_delete_endpoint_forbidden (self ):
234+ with self .assertRaises (ForbiddenException ) as context :
235+ self .forbidden_api_instance .delete_endpoint (self .account_id , self .test_endpoint_id )
236+
237+ self .assertApiException (context , 403 )
238+
239+ def test_delete_endpoint_not_found (self ):
240+ with self .assertRaises (NotFoundException ) as context :
241+ self .endpoints_api_instance .delete_endpoint (self .account_id , self .test_endpoint_id )
242+
243+ self .assertApiException (context , 404 )
166244
167245
168246if __name__ == '__main__' :
0 commit comments