Skip to content

Commit 479561f

Browse files
smoghe-bwclaude
andcommitted
Address remaining review comments: remove hamcrest, clean up test patterns
- Remove unnecessary assertion in smoke test (listed_ids check) - Replace all hamcrest matchers with plain assert statements in unit API tests - Remove dead make_instance(include_optional) pattern from 13 model tests Generated from Claude9 with Claude Code Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2561a10 commit 479561f

16 files changed

Lines changed: 231 additions & 363 deletions

test/smoke/test_endpoints_api.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ def listEndpoints(self):
8989
assert isinstance(response.data.data, list)
9090
assert len(response.data.data) > 0
9191

92-
listed_ids = [ep.endpoint_id for ep in response.data.data]
93-
assert self.endpoint_id in listed_ids
94-
9592
endpoint = response.data.data[0]
9693
assert isinstance(endpoint, Endpoints)
9794
assert isinstance(endpoint.endpoint_id, str)

test/unit/api/test_endpoints_api.py

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import unittest
1717
from datetime import datetime
1818

19-
from hamcrest import *
2019
from test.utils.env_variables import *
2120
from bandwidth import ApiClient, Configuration
2221
from bandwidth.api.endpoints_api import EndpointsApi
@@ -68,26 +67,26 @@ def test_create_endpoint(self) -> None:
6867
endpoint_body
6968
)
7069

71-
assert_that(response.status_code, equal_to(201))
72-
assert_that(response.data, instance_of(CreateEndpointResponse))
70+
assert response.status_code == 201
71+
assert isinstance(response.data, CreateEndpointResponse)
7372

74-
assert_that(response.data.links, instance_of(list))
75-
assert_that(len(response.data.links), greater_than(0))
76-
assert_that(response.data.links[0], instance_of(Link))
77-
assert_that(response.data.links[0].href, starts_with('http'))
78-
assert_that(response.data.links[0].rel, equal_to('endpoint'))
73+
assert isinstance(response.data.links, list)
74+
assert len(response.data.links) > 0
75+
assert isinstance(response.data.links[0], Link)
76+
assert response.data.links[0].href.startswith('http')
77+
assert response.data.links[0].rel == 'endpoint'
7978

80-
assert_that(response.data.data, instance_of(CreateEndpointResponseData))
81-
assert_that(response.data.data.endpoint_id, equal_to('e-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85'))
82-
assert_that(response.data.data.type, equal_to(EndpointTypeEnum.WEBRTC))
83-
assert_that(response.data.data.status, equal_to(EndpointStatusEnum.CONNECTED))
84-
assert_that(response.data.data.creation_timestamp, instance_of(datetime))
85-
assert_that(response.data.data.expiration_timestamp, instance_of(datetime))
86-
assert_that(response.data.data.token, equal_to('xxxxx.yyyyy.zzzzz'))
87-
assert_that(response.data.data.tag, equal_to('my-tag'))
88-
assert_that(response.data.data.devices, instance_of(list))
79+
assert isinstance(response.data.data, CreateEndpointResponseData)
80+
assert response.data.data.endpoint_id == 'e-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85'
81+
assert response.data.data.type == EndpointTypeEnum.WEBRTC
82+
assert response.data.data.status == EndpointStatusEnum.CONNECTED
83+
assert isinstance(response.data.data.creation_timestamp, datetime)
84+
assert isinstance(response.data.data.expiration_timestamp, datetime)
85+
assert response.data.data.token == 'xxxxx.yyyyy.zzzzz'
86+
assert response.data.data.tag == 'my-tag'
87+
assert isinstance(response.data.data.devices, list)
8988

90-
assert_that(response.data.errors, equal_to([]))
89+
assert response.data.errors == []
9190

9291
def test_delete_endpoint(self) -> None:
9392
"""Test case for delete_endpoint
@@ -99,7 +98,7 @@ def test_delete_endpoint(self) -> None:
9998
"ep-abc123"
10099
)
101100

102-
assert_that(response.status_code, equal_to(204))
101+
assert response.status_code == 204
103102

104103
def test_get_endpoint(self) -> None:
105104
"""Test case for get_endpoint
@@ -111,25 +110,25 @@ def test_get_endpoint(self) -> None:
111110
"ep-abc123"
112111
)
113112

114-
assert_that(response.status_code, equal_to(200))
115-
assert_that(response.data, instance_of(EndpointResponse))
113+
assert response.status_code == 200
114+
assert isinstance(response.data, EndpointResponse)
116115

117-
assert_that(response.data.links, instance_of(list))
118-
assert_that(len(response.data.links), greater_than(0))
119-
assert_that(response.data.links[0], instance_of(Link))
120-
assert_that(response.data.links[0].href, starts_with('http'))
121-
assert_that(response.data.links[0].rel, equal_to('self'))
116+
assert isinstance(response.data.links, list)
117+
assert len(response.data.links) > 0
118+
assert isinstance(response.data.links[0], Link)
119+
assert response.data.links[0].href.startswith('http')
120+
assert response.data.links[0].rel == 'self'
122121

123-
assert_that(response.data.data, instance_of(Endpoint))
124-
assert_that(response.data.data.endpoint_id, equal_to('e-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85'))
125-
assert_that(response.data.data.type, equal_to(EndpointTypeEnum.WEBRTC))
126-
assert_that(response.data.data.status, equal_to(EndpointStatusEnum.CONNECTED))
127-
assert_that(response.data.data.creation_timestamp, instance_of(datetime))
128-
assert_that(response.data.data.expiration_timestamp, instance_of(datetime))
129-
assert_that(response.data.data.tag, equal_to('my-tag'))
130-
assert_that(response.data.data.devices, equal_to([]))
122+
assert isinstance(response.data.data, Endpoint)
123+
assert response.data.data.endpoint_id == 'e-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85'
124+
assert response.data.data.type == EndpointTypeEnum.WEBRTC
125+
assert response.data.data.status == EndpointStatusEnum.CONNECTED
126+
assert isinstance(response.data.data.creation_timestamp, datetime)
127+
assert isinstance(response.data.data.expiration_timestamp, datetime)
128+
assert response.data.data.tag == 'my-tag'
129+
assert response.data.data.devices == []
131130

132-
assert_that(response.data.errors, equal_to([]))
131+
assert response.data.errors == []
133132

134133
def test_list_endpoints(self) -> None:
135134
"""Test case for list_endpoints
@@ -140,33 +139,33 @@ def test_list_endpoints(self) -> None:
140139
BW_ACCOUNT_ID
141140
)
142141

143-
assert_that(response.status_code, equal_to(200))
144-
assert_that(response.data, instance_of(ListEndpointsResponse))
145-
146-
assert_that(response.data.links, instance_of(list))
147-
assert_that(len(response.data.links), greater_than(0))
148-
assert_that(response.data.links[0], instance_of(Link))
149-
assert_that(response.data.links[0].href, starts_with('http'))
150-
assert_that(response.data.links[0].rel, equal_to('self'))
151-
152-
assert_that(response.data.page.page_size, equal_to(2))
153-
assert_that(response.data.page.total_elements, equal_to(10))
154-
assert_that(response.data.page.total_pages, equal_to(5))
155-
assert_that(response.data.page.page_number, equal_to(0))
156-
157-
assert_that(response.data.data, instance_of(list))
158-
assert_that(len(response.data.data), equal_to(2))
159-
assert_that(response.data.data[0], instance_of(Endpoints))
160-
assert_that(response.data.data[0].endpoint_id, equal_to('e-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85'))
161-
assert_that(response.data.data[0].type, equal_to(EndpointTypeEnum.WEBRTC))
162-
assert_that(response.data.data[0].status, equal_to(EndpointStatusEnum.CONNECTED))
163-
assert_that(response.data.data[0].tag, equal_to('my-tag'))
164-
assert_that(response.data.data[0].creation_timestamp, instance_of(datetime))
165-
assert_that(response.data.data[0].expiration_timestamp, instance_of(datetime))
166-
assert_that(response.data.data[1].endpoint_id, equal_to('e-2cb0-4a07-b215-b22865662d85-15ac29a2-1331029c'))
167-
assert_that(response.data.data[1].tag, equal_to('my-tag'))
168-
169-
assert_that(response.data.errors, equal_to([]))
142+
assert response.status_code == 200
143+
assert isinstance(response.data, ListEndpointsResponse)
144+
145+
assert isinstance(response.data.links, list)
146+
assert len(response.data.links) > 0
147+
assert isinstance(response.data.links[0], Link)
148+
assert response.data.links[0].href.startswith('http')
149+
assert response.data.links[0].rel == 'self'
150+
151+
assert response.data.page.page_size == 2
152+
assert response.data.page.total_elements == 10
153+
assert response.data.page.total_pages == 5
154+
assert response.data.page.page_number == 0
155+
156+
assert isinstance(response.data.data, list)
157+
assert len(response.data.data) == 2
158+
assert isinstance(response.data.data[0], Endpoints)
159+
assert response.data.data[0].endpoint_id == 'e-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85'
160+
assert response.data.data[0].type == EndpointTypeEnum.WEBRTC
161+
assert response.data.data[0].status == EndpointStatusEnum.CONNECTED
162+
assert response.data.data[0].tag == 'my-tag'
163+
assert isinstance(response.data.data[0].creation_timestamp, datetime)
164+
assert isinstance(response.data.data[0].expiration_timestamp, datetime)
165+
assert response.data.data[1].endpoint_id == 'e-2cb0-4a07-b215-b22865662d85-15ac29a2-1331029c'
166+
assert response.data.data[1].tag == 'my-tag'
167+
168+
assert response.data.errors == []
170169

171170

172171
if __name__ == '__main__':

test/unit/models/test_create_endpoint_request_base.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,19 @@ def setUp(self):
2828
def tearDown(self):
2929
pass
3030

31-
def make_instance(self, include_optional) -> CreateEndpointRequestBase:
32-
"""Test CreateEndpointRequestBase
33-
include_optional is a boolean, when False only required
34-
params are included, when True both required and
35-
optional params are included """
36-
if include_optional:
37-
return CreateEndpointRequestBase(
38-
type=EndpointTypeEnum.WEBRTC,
39-
direction=EndpointDirectionEnum.BIDIRECTIONAL,
40-
event_callback_url='https://example.com/callback',
41-
event_fallback_url='https://example.com/fallback',
42-
tag='test-request'
43-
)
44-
else:
45-
return CreateEndpointRequestBase(
46-
type=EndpointTypeEnum.WEBRTC,
47-
direction=EndpointDirectionEnum.BIDIRECTIONAL
48-
)
31+
def make_instance(self) -> CreateEndpointRequestBase:
32+
"""Test CreateEndpointRequestBase"""
33+
return CreateEndpointRequestBase(
34+
type=EndpointTypeEnum.WEBRTC,
35+
direction=EndpointDirectionEnum.BIDIRECTIONAL,
36+
event_callback_url='https://example.com/callback',
37+
event_fallback_url='https://example.com/fallback',
38+
tag='test-request'
39+
)
4940

5041
def testCreateEndpointRequestBase(self):
5142
"""Test CreateEndpointRequestBase"""
52-
instance = self.make_instance(True)
43+
instance = self.make_instance()
5344
assert instance is not None
5445
assert isinstance(instance, CreateEndpointRequestBase)
5546
assert instance.type == EndpointTypeEnum.WEBRTC

test/unit/models/test_create_endpoint_response.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ def setUp(self):
3232
def tearDown(self):
3333
pass
3434

35-
def make_instance(self, include_optional) -> CreateEndpointResponse:
36-
"""Test CreateEndpointResponse
37-
include_optional is a boolean, when False only required
38-
params are included, when True both required and
39-
optional params are included """
35+
def make_instance(self) -> CreateEndpointResponse:
36+
"""Test CreateEndpointResponse"""
4037
return CreateEndpointResponse(
4138
links=[
4239
Link(href='https://api.bandwidth.com/endpoint-123', rel='self')
@@ -54,7 +51,7 @@ def make_instance(self, include_optional) -> CreateEndpointResponse:
5451

5552
def testCreateEndpointResponse(self):
5653
"""Test CreateEndpointResponse"""
57-
instance = self.make_instance(True)
54+
instance = self.make_instance()
5855
assert instance is not None
5956
assert isinstance(instance, CreateEndpointResponse)
6057
assert isinstance(instance.links, list)

test/unit/models/test_create_endpoint_response_data.py

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,29 @@ def setUp(self):
3131
def tearDown(self):
3232
pass
3333

34-
def make_instance(self, include_optional) -> CreateEndpointResponseData:
35-
"""Test CreateEndpointResponseData
36-
include_optional is a boolean, when False only required
37-
params are included, when True both required and
38-
optional params are included """
39-
if include_optional:
40-
return CreateEndpointResponseData(
41-
endpoint_id='e-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85',
42-
type=EndpointTypeEnum.WEBRTC,
43-
status=EndpointStatusEnum.CONNECTED,
44-
creation_timestamp=datetime(2026, 1, 15, 10, 0, 0),
45-
expiration_timestamp=datetime(2026, 1, 16, 10, 0, 0),
46-
tag='my-tag',
47-
devices=[
48-
Device(
49-
device_id='device-456',
50-
device_name='Test Device',
51-
status=DeviceStatusEnum.CONNECTED,
52-
creation_timestamp=datetime(2026, 1, 15, 10, 0, 0)
53-
)
54-
],
55-
token='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.test.token'
56-
)
57-
else:
58-
return CreateEndpointResponseData(
59-
endpoint_id='e-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85',
60-
type=EndpointTypeEnum.WEBRTC,
61-
status=EndpointStatusEnum.CONNECTED,
62-
creation_timestamp=datetime(2026, 1, 15, 10, 0, 0),
63-
expiration_timestamp=datetime(2026, 1, 16, 10, 0, 0),
64-
token='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.test.token'
65-
)
34+
def make_instance(self) -> CreateEndpointResponseData:
35+
"""Test CreateEndpointResponseData"""
36+
return CreateEndpointResponseData(
37+
endpoint_id='e-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85',
38+
type=EndpointTypeEnum.WEBRTC,
39+
status=EndpointStatusEnum.CONNECTED,
40+
creation_timestamp=datetime(2026, 1, 15, 10, 0, 0),
41+
expiration_timestamp=datetime(2026, 1, 16, 10, 0, 0),
42+
tag='my-tag',
43+
devices=[
44+
Device(
45+
device_id='device-456',
46+
device_name='Test Device',
47+
status=DeviceStatusEnum.CONNECTED,
48+
creation_timestamp=datetime(2026, 1, 15, 10, 0, 0)
49+
)
50+
],
51+
token='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.test.token'
52+
)
6653

6754
def testCreateEndpointResponseData(self):
6855
"""Test CreateEndpointResponseData"""
69-
instance = self.make_instance(True)
56+
instance = self.make_instance()
7057
assert instance is not None
7158
assert isinstance(instance, CreateEndpointResponseData)
7259
assert instance.endpoint_id == 'e-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85'

test/unit/models/test_create_web_rtc_connection_request.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,23 @@ def setUp(self):
2828
def tearDown(self):
2929
pass
3030

31-
def make_instance(self, include_optional) -> CreateWebRtcConnectionRequest:
32-
"""Test CreateWebRtcConnectionRequest
33-
include_optional is a boolean, when False only required
34-
params are included, when True both required and
35-
optional params are included """
36-
if include_optional:
37-
return CreateWebRtcConnectionRequest(
38-
type=EndpointTypeEnum.WEBRTC,
39-
direction=EndpointDirectionEnum.BIDIRECTIONAL,
40-
event_callback_url='https://example.com/callback',
41-
event_fallback_url='https://example.com/fallback',
42-
tag='test-webrtc',
43-
connection_metadata={
44-
'key1': 'value1',
45-
'key2': 'value2'
46-
}
47-
)
48-
else:
49-
return CreateWebRtcConnectionRequest(
50-
type=EndpointTypeEnum.WEBRTC,
51-
direction=EndpointDirectionEnum.BIDIRECTIONAL
52-
)
31+
def make_instance(self) -> CreateWebRtcConnectionRequest:
32+
"""Test CreateWebRtcConnectionRequest"""
33+
return CreateWebRtcConnectionRequest(
34+
type=EndpointTypeEnum.WEBRTC,
35+
direction=EndpointDirectionEnum.BIDIRECTIONAL,
36+
event_callback_url='https://example.com/callback',
37+
event_fallback_url='https://example.com/fallback',
38+
tag='test-webrtc',
39+
connection_metadata={
40+
'key1': 'value1',
41+
'key2': 'value2'
42+
}
43+
)
5344

5445
def testCreateWebRtcConnectionRequest(self):
5546
"""Test CreateWebRtcConnectionRequest"""
56-
instance = self.make_instance(True)
47+
instance = self.make_instance()
5748
assert instance is not None
5849
assert isinstance(instance, CreateWebRtcConnectionRequest)
5950
assert instance.type == EndpointTypeEnum.WEBRTC

test/unit/models/test_device.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,18 @@ def setUp(self):
2828
def tearDown(self):
2929
pass
3030

31-
def make_instance(self, include_optional) -> Device:
32-
"""Test Device
33-
include_optional is a boolean, when False only required
34-
params are included, when True both required and
35-
optional params are included """
36-
if include_optional:
37-
return Device(
38-
device_id='device-abc-123',
39-
device_name='My Test Device',
40-
status=DeviceStatusEnum.CONNECTED,
41-
creation_timestamp=datetime(2026, 1, 15, 10, 0, 0)
42-
)
43-
else:
44-
return Device(
45-
device_id='device-abc-123',
46-
status=DeviceStatusEnum.CONNECTED,
47-
creation_timestamp=datetime(2026, 1, 15, 10, 0, 0)
48-
)
31+
def make_instance(self) -> Device:
32+
"""Test Device"""
33+
return Device(
34+
device_id='device-abc-123',
35+
device_name='My Test Device',
36+
status=DeviceStatusEnum.CONNECTED,
37+
creation_timestamp=datetime(2026, 1, 15, 10, 0, 0)
38+
)
4939

5040
def testDevice(self):
5141
"""Test Device"""
52-
instance = self.make_instance(True)
42+
instance = self.make_instance()
5343
assert instance is not None
5444
assert isinstance(instance, Device)
5545
assert instance.device_id == 'device-abc-123'

0 commit comments

Comments
 (0)