Skip to content

Commit fc98a22

Browse files
committed
Adds better test/implementation for deprecated functionality
1 parent e115be7 commit fc98a22

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

SoftLayer/API.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ def call(self, service, method, *args, **kwargs):
184184
}
185185

186186
if self.auth:
187-
if getattr(self.auth, "get_headers", None):
188-
warnings.warn("auth.get_headers() is deprecation and will be "
187+
extra_headers = self.auth.get_headers()
188+
if extra_headers:
189+
warnings.warn("auth.get_headers() is deprecated and will be "
189190
"removed in the next major version",
190191
DeprecationWarning)
191-
headers.update(self.auth.get_headers())
192+
headers.update(extra_headers)
192193

193-
if getattr(self.auth, "get_options", None):
194-
options = self.auth.get_options(options)
194+
options = self.auth.get_options(options)
195195

196196
return transports.make_xml_rpc_api_call(uri, method, args,
197197
**options)

SoftLayer/tests/deprecated_tests.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
:license: MIT, see LICENSE for more details.
66
"""
7+
import warnings
8+
79
import mock
810

911
import SoftLayer
@@ -24,10 +26,18 @@ def set_up(self):
2426

2527
@mock.patch('SoftLayer.transports.make_xml_rpc_api_call')
2628
def test_simple_call(self, make_xml_rpc_api_call):
27-
self.client['SERVICE'].METHOD()
28-
make_xml_rpc_api_call.assert_called_with(
29-
mock.ANY, mock.ANY, mock.ANY,
30-
headers={'deprecated': 'header'},
31-
proxy=mock.ANY,
32-
timeout=mock.ANY,
33-
http_headers=mock.ANY)
29+
with warnings.catch_warnings(record=True) as w:
30+
# Cause all warnings to always be triggered.
31+
warnings.simplefilter("always")
32+
33+
self.client['SERVICE'].METHOD()
34+
35+
make_xml_rpc_api_call.assert_called_with(
36+
mock.ANY, mock.ANY, mock.ANY,
37+
headers={'deprecated': 'header'},
38+
proxy=mock.ANY,
39+
timeout=mock.ANY,
40+
http_headers=mock.ANY)
41+
self.assertEqual(len(w), 1)
42+
self.assertEqual(w[0].category, DeprecationWarning)
43+
self.assertIn("deprecated", str(w[0].message))

0 commit comments

Comments
 (0)