Skip to content

Commit 70ce259

Browse files
committed
Ensure transports return a byte/str value
Fixes #39
1 parent 82cd178 commit 70ce259

8 files changed

+56
-25
lines changed

src/itoolkit/db2/idb2call.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ def call(self, itool):
7373
Returns:
7474
The XML returned from XMLSERVICE
7575
"""
76-
super(iDB2Call, self).call(itool)
76+
return super(iDB2Call, self).call(itool)

src/itoolkit/lib/ilibcall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ def call(self, itool):
4040
Returns:
4141
The XML returned from XMLSERVICE
4242
"""
43-
super(iLibCall, self).call(itool)
43+
return super(iLibCall, self).call(itool)

src/itoolkit/rest/irestcall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ def call(self, itool):
6161
Returns:
6262
The XML returned from XMLSERVICE
6363
"""
64-
super(iRestCall, self).call(itool)
64+
return super(iRestCall, self).call(itool)

tests/test_unit_idb2call.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
def test_idb2call_transport_minimal_callproc(database_callproc):
1616
transport = iDB2Call(database_callproc)
1717
tk = iToolKit()
18-
transport.call(tk)
18+
out = transport.call(tk)
19+
20+
assert isinstance(out, (bytes, str))
1921

2022
cursor = database_callproc.cursor()
2123

@@ -26,7 +28,9 @@ def test_idb2call_transport_minimal_callproc(database_callproc):
2628
def test_idb2call_transport_minimal_execute(database_execute):
2729
transport = iDB2Call(database_execute)
2830
tk = iToolKit()
29-
transport.call(tk)
31+
out = transport.call(tk)
32+
33+
assert isinstance(out, (bytes, str))
3034

3135
cursor = database_execute.cursor()
3236

@@ -48,7 +52,9 @@ class MockConn(object):
4852
conn = MockConn()
4953
transport = iDB2Call(conn)
5054
tk = iToolKit()
51-
transport.call(tk)
55+
out = transport.call(tk)
56+
57+
assert isinstance(out, (bytes, str))
5258

5359
Connection.assert_called_once_with(conn)
5460

@@ -74,7 +80,9 @@ class MockConn(object):
7480

7581
transport = iDB2Call(user, password)
7682
tk = iToolKit()
77-
transport.call(tk)
83+
out = transport.call(tk)
84+
85+
assert isinstance(out, (bytes, str))
7886

7987
kwargs = dict(database='*LOCAL', user=user, password=password)
8088
connect.assert_called_once_with(**kwargs)

tests/test_unit_irestcall.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
def mock_http_urlopen(mocker):
2323
mock_urlopen = mocker.patch('itoolkit.transport.http.urlopen')
2424
mock_response = mocker.Mock()
25-
mock_response.read.side_effect = XMLIN.encode('utf-8')
25+
mock_response.read.side_effect = (XMLIN.encode('utf-8'),)
2626
mock_urlopen.return_value = mock_response
2727

2828
return mock_urlopen
@@ -66,9 +66,6 @@ def assert_urlopen_params_correct(mock_urlopen, url, uid, pwd, db2='*LOCAL',
6666
'xmlout': int(xmlout)
6767
}).encode("utf-8"))
6868

69-
70-
71-
7269

7370
def test_irestcall_transport_minimal(mocker):
7471
mock_urlopen = mock_http_urlopen(mocker)
@@ -79,7 +76,9 @@ def test_irestcall_transport_minimal(mocker):
7976

8077
transport = iRestCall(url, user, password)
8178
tk = iToolKit()
82-
transport.call(tk)
79+
out = transport.call(tk)
80+
81+
assert isinstance(out, (bytes, str))
8382

8483
assert_urlopen_params_correct(
8584
mock_urlopen,
@@ -100,7 +99,9 @@ def test_irestcall_transport_without_password(mocker, monkeypatch):
10099

101100
transport = iRestCall(url, user, password)
102101
tk = iToolKit()
103-
transport.call(tk)
102+
out = transport.call(tk)
103+
104+
assert isinstance(out, (bytes, str))
104105

105106
assert_urlopen_params_correct(
106107
mock_urlopen,
@@ -120,7 +121,9 @@ def test_irestcall_transport_with_database(mocker):
120121

121122
transport = iRestCall(url, user, password, idb2=database)
122123
tk = iToolKit()
123-
transport.call(tk)
124+
out = transport.call(tk)
125+
126+
assert isinstance(out, (bytes, str))
124127

125128
assert_urlopen_params_correct(
126129
mock_urlopen,
@@ -141,7 +144,9 @@ def test_irestcall_transport_with_ipc(mocker):
141144

142145
transport = iRestCall(url, user, password, ipc=ipc)
143146
tk = iToolKit()
144-
transport.call(tk)
147+
out = transport.call(tk)
148+
149+
assert isinstance(out, (bytes, str))
145150

146151
assert_urlopen_params_correct(
147152
mock_urlopen,
@@ -162,7 +167,9 @@ def test_irestcall_transport_with_ctl(mocker):
162167

163168
transport = iRestCall(url, user, password, ictl=ctl)
164169
tk = iToolKit()
165-
transport.call(tk)
170+
out = transport.call(tk)
171+
172+
assert isinstance(out, (bytes, str))
166173

167174
assert_urlopen_params_correct(
168175
mock_urlopen,
@@ -198,7 +205,9 @@ def allow_deprecated():
198205
with allow_deprecated():
199206
transport = iRestCall(url, user, password, isiz=size)
200207
tk = iToolKit()
201-
transport.call(tk)
208+
out = transport.call(tk)
209+
210+
assert isinstance(out, (bytes, str))
202211
assert len(recwarn) == 2
203212
assert isinstance(recwarn[0].category, type(DeprecationWarning))
204213
assert isinstance(recwarn[1].category, type(DeprecationWarning))

tests/test_unit_transport_database.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
def test_database_transport_callproc(database_callproc):
66
transport = DatabaseTransport(database_callproc)
77
tk = iToolKit()
8-
transport.call(tk)
8+
out = transport.call(tk)
9+
10+
assert isinstance(out, (bytes, str))
911

1012
cursor = database_callproc.cursor()
1113

@@ -16,7 +18,9 @@ def test_database_transport_callproc(database_callproc):
1618
def test_database_transport_execute(database_execute):
1719
transport = DatabaseTransport(database_execute)
1820
tk = iToolKit()
19-
transport.call(tk)
21+
out = transport.call(tk)
22+
23+
assert isinstance(out, (bytes, str))
2024

2125
cursor = database_execute.cursor()
2226

@@ -28,7 +32,9 @@ def test_database_transport_execute_schema(database_execute):
2832
schema = 'MYSCHEMA'
2933
transport = DatabaseTransport(database_execute, schema=schema)
3034
tk = iToolKit()
31-
transport.call(tk)
35+
out = transport.call(tk)
36+
37+
assert isinstance(out, (bytes, str))
3238

3339
cursor = database_execute.cursor()
3440

@@ -43,7 +49,9 @@ def test_database_transport_callproc_schema(database_execute):
4349
schema = 'MYSCHEMA'
4450
transport = DatabaseTransport(database_execute, schema=schema)
4551
tk = iToolKit()
46-
transport.call(tk)
52+
out = transport.call(tk)
53+
54+
assert isinstance(out, (bytes, str))
4755

4856
cursor = database_execute.cursor()
4957

tests/test_unit_transport_http.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
def mock_http_urlopen(mocker):
1818
mock_urlopen = mocker.patch('itoolkit.transport.http.urlopen')
1919
mock_response = mocker.Mock()
20-
mock_response.read.side_effect = XMLIN.encode('utf-8')
20+
mock_response.read.side_effect = (XMLIN.encode('utf-8'), )
2121
mock_urlopen.return_value = mock_response
2222

2323
return mock_urlopen
@@ -71,7 +71,9 @@ def test_http_transport_minimal(mocker):
7171

7272
transport = HttpTransport(url, user, password)
7373
tk = iToolKit()
74-
transport.call(tk)
74+
out = transport.call(tk)
75+
76+
assert isinstance(out, (bytes, str))
7577

7678
assert_urlopen_params_correct(
7779
mock_urlopen,
@@ -91,7 +93,9 @@ def test_http_transport_with_database(mocker):
9193

9294
transport = HttpTransport(url, user, password, database=database)
9395
tk = iToolKit()
94-
transport.call(tk)
96+
out = transport.call(tk)
97+
98+
assert isinstance(out, (bytes, str))
9599

96100
assert_urlopen_params_correct(
97101
mock_urlopen,

tests/test_unit_transport_ssh.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ def test_ssh_transport_minimal(mocker):
2323

2424
transport = SshTransport(ssh_client)
2525
tk = iToolKit()
26-
transport.call(tk)
26+
out = transport.call(tk)
27+
28+
assert isinstance(out, (bytes, str))
2729

2830
command = "/QOpenSys/pkgs/bin/xmlservice-cli"
2931
ssh_client.exec_command.assert_called_once_with(command)

0 commit comments

Comments
 (0)