Skip to content

Commit fbe0d8a

Browse files
committed
Make test_unit_irestcall.py work for Python < 3.6
1 parent 059ebfe commit fbe0d8a

File tree

1 file changed

+44
-22
lines changed

1 file changed

+44
-22
lines changed

tests/test_unit_irestcall.py

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import pytest
2+
import sys
23

34
from itoolkit import iToolKit
45
from itoolkit.rest.irestcall import iRestCall
56

67
from contextlib import contextmanager
7-
from urllib.parse import parse_qs
8+
if sys.version_info >= (3, 0):
9+
if sys.version_info >= (3, 6):
10+
from urllib.parse import parse_qs
11+
else:
12+
from urllib.parse import urlencode
13+
else:
14+
from urllib import urlencode
815

916
pytestmark = \
1017
pytest.mark.filterwarnings("ignore:.*iRestCall.*:DeprecationWarning")
@@ -24,28 +31,43 @@ def mock_http_urlopen(mocker):
2431
def assert_urlopen_params_correct(mock_urlopen, url, uid, pwd, db2='*LOCAL',
2532
ipc='*na', ctl='*here *cdata',
2633
xmlout=str(iRestCall.OUT_SIZE)):
27-
mock_urlopen.assert_called_once()
34+
# assert_called_once only available in Python 3.6+
35+
if sys.version_info >= (3, 6):
36+
mock_urlopen.assert_called_once()
37+
38+
args, kwargs = mock_urlopen.call_args
39+
40+
assert len(kwargs) == 0
41+
assert len(args) == 2
42+
43+
assert args[0] == url
44+
45+
data = {key.decode('utf-8'): value[0].decode('utf-8') for (key, value)
46+
in parse_qs(args[1]).items()}
47+
48+
exp_data = dict(
49+
uid=uid,
50+
pwd=pwd,
51+
db2=db2,
52+
ipc=ipc,
53+
ctl=ctl,
54+
xmlout=xmlout,
55+
xmlin=XMLIN + "\n",
56+
)
57+
assert data == exp_data
58+
else:
59+
mock_urlopen.assert_called_once_with(url, urlencode({
60+
'db2': db2,
61+
'uid': uid,
62+
'pwd': pwd,
63+
'ipc': ipc,
64+
'ctl': ctl,
65+
'xmlin': XMLIN + "\n",
66+
'xmlout': int(xmlout)
67+
}).encode("utf-8"))
68+
69+
2870

29-
args, kwargs = mock_urlopen.call_args
30-
31-
assert len(kwargs) == 0
32-
assert len(args) == 2
33-
34-
assert args[0] == url
35-
36-
data = {key.decode('utf-8'): value[0].decode('utf-8') for (key, value)
37-
in parse_qs(args[1]).items()}
38-
39-
exp_data = dict(
40-
uid=uid,
41-
pwd=pwd,
42-
db2=db2,
43-
ipc=ipc,
44-
ctl=ctl,
45-
xmlout=xmlout,
46-
xmlin=XMLIN + "\n",
47-
)
48-
assert data == exp_data
4971

5072

5173
def test_irestcall_transport_minimal(mocker):

0 commit comments

Comments
 (0)