From 82cd178f717bea6ed88b2f134f566f7b3a543d7b Mon Sep 17 00:00:00 2001 From: Kevin Adler Date: Tue, 28 May 2019 13:02:12 -0500 Subject: [PATCH 1/2] Fix unit tests affected by #37 Fixes #38 --- tests/test_unit_transport_database.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_unit_transport_database.py b/tests/test_unit_transport_database.py index 9059329..1529f1e 100644 --- a/tests/test_unit_transport_database.py +++ b/tests/test_unit_transport_database.py @@ -36,7 +36,7 @@ def test_database_transport_execute_schema(database_execute): cursor.__iter__.assert_called_once() assert len(cursor.execute.call_args[0]) > 0 - assert schema in cursor.execute.call_args[0][1] # argument 0 is self + assert schema in cursor.execute.call_args[0][0] def test_database_transport_callproc_schema(database_execute): @@ -51,4 +51,4 @@ def test_database_transport_callproc_schema(database_execute): cursor.__iter__.assert_called_once() assert len(cursor.execute.call_args[0]) > 0 - assert schema in cursor.execute.call_args[0][1] # argument 0 is self + assert schema in cursor.execute.call_args[0][0] From 70ce259778cc85edbb3a420c5b0dba333eec1cfa Mon Sep 17 00:00:00 2001 From: Kevin Adler Date: Tue, 28 May 2019 14:06:10 -0500 Subject: [PATCH 2/2] Ensure transports return a byte/str value Fixes #39 --- src/itoolkit/db2/idb2call.py | 2 +- src/itoolkit/lib/ilibcall.py | 2 +- src/itoolkit/rest/irestcall.py | 2 +- tests/test_unit_idb2call.py | 16 +++++++++++---- tests/test_unit_irestcall.py | 29 ++++++++++++++++++--------- tests/test_unit_transport_database.py | 16 +++++++++++---- tests/test_unit_transport_http.py | 10 ++++++--- tests/test_unit_transport_ssh.py | 4 +++- 8 files changed, 56 insertions(+), 25 deletions(-) diff --git a/src/itoolkit/db2/idb2call.py b/src/itoolkit/db2/idb2call.py index bf5ce4c..cf83aa0 100644 --- a/src/itoolkit/db2/idb2call.py +++ b/src/itoolkit/db2/idb2call.py @@ -73,4 +73,4 @@ def call(self, itool): Returns: The XML returned from XMLSERVICE """ - super(iDB2Call, self).call(itool) + return super(iDB2Call, self).call(itool) diff --git a/src/itoolkit/lib/ilibcall.py b/src/itoolkit/lib/ilibcall.py index 044a9fe..b8dbc26 100644 --- a/src/itoolkit/lib/ilibcall.py +++ b/src/itoolkit/lib/ilibcall.py @@ -40,4 +40,4 @@ def call(self, itool): Returns: The XML returned from XMLSERVICE """ - super(iLibCall, self).call(itool) + return super(iLibCall, self).call(itool) diff --git a/src/itoolkit/rest/irestcall.py b/src/itoolkit/rest/irestcall.py index 41c8928..2f44ae7 100644 --- a/src/itoolkit/rest/irestcall.py +++ b/src/itoolkit/rest/irestcall.py @@ -61,4 +61,4 @@ def call(self, itool): Returns: The XML returned from XMLSERVICE """ - super(iRestCall, self).call(itool) + return super(iRestCall, self).call(itool) diff --git a/tests/test_unit_idb2call.py b/tests/test_unit_idb2call.py index 295eda1..7207bdf 100644 --- a/tests/test_unit_idb2call.py +++ b/tests/test_unit_idb2call.py @@ -15,7 +15,9 @@ def test_idb2call_transport_minimal_callproc(database_callproc): transport = iDB2Call(database_callproc) tk = iToolKit() - transport.call(tk) + out = transport.call(tk) + + assert isinstance(out, (bytes, str)) cursor = database_callproc.cursor() @@ -26,7 +28,9 @@ def test_idb2call_transport_minimal_callproc(database_callproc): def test_idb2call_transport_minimal_execute(database_execute): transport = iDB2Call(database_execute) tk = iToolKit() - transport.call(tk) + out = transport.call(tk) + + assert isinstance(out, (bytes, str)) cursor = database_execute.cursor() @@ -48,7 +52,9 @@ class MockConn(object): conn = MockConn() transport = iDB2Call(conn) tk = iToolKit() - transport.call(tk) + out = transport.call(tk) + + assert isinstance(out, (bytes, str)) Connection.assert_called_once_with(conn) @@ -74,7 +80,9 @@ class MockConn(object): transport = iDB2Call(user, password) tk = iToolKit() - transport.call(tk) + out = transport.call(tk) + + assert isinstance(out, (bytes, str)) kwargs = dict(database='*LOCAL', user=user, password=password) connect.assert_called_once_with(**kwargs) diff --git a/tests/test_unit_irestcall.py b/tests/test_unit_irestcall.py index 5f42ef5..cbeb327 100644 --- a/tests/test_unit_irestcall.py +++ b/tests/test_unit_irestcall.py @@ -22,7 +22,7 @@ def mock_http_urlopen(mocker): mock_urlopen = mocker.patch('itoolkit.transport.http.urlopen') mock_response = mocker.Mock() - mock_response.read.side_effect = XMLIN.encode('utf-8') + mock_response.read.side_effect = (XMLIN.encode('utf-8'),) mock_urlopen.return_value = mock_response return mock_urlopen @@ -66,9 +66,6 @@ def assert_urlopen_params_correct(mock_urlopen, url, uid, pwd, db2='*LOCAL', 'xmlout': int(xmlout) }).encode("utf-8")) - - - def test_irestcall_transport_minimal(mocker): mock_urlopen = mock_http_urlopen(mocker) @@ -79,7 +76,9 @@ def test_irestcall_transport_minimal(mocker): transport = iRestCall(url, user, password) tk = iToolKit() - transport.call(tk) + out = transport.call(tk) + + assert isinstance(out, (bytes, str)) assert_urlopen_params_correct( mock_urlopen, @@ -100,7 +99,9 @@ def test_irestcall_transport_without_password(mocker, monkeypatch): transport = iRestCall(url, user, password) tk = iToolKit() - transport.call(tk) + out = transport.call(tk) + + assert isinstance(out, (bytes, str)) assert_urlopen_params_correct( mock_urlopen, @@ -120,7 +121,9 @@ def test_irestcall_transport_with_database(mocker): transport = iRestCall(url, user, password, idb2=database) tk = iToolKit() - transport.call(tk) + out = transport.call(tk) + + assert isinstance(out, (bytes, str)) assert_urlopen_params_correct( mock_urlopen, @@ -141,7 +144,9 @@ def test_irestcall_transport_with_ipc(mocker): transport = iRestCall(url, user, password, ipc=ipc) tk = iToolKit() - transport.call(tk) + out = transport.call(tk) + + assert isinstance(out, (bytes, str)) assert_urlopen_params_correct( mock_urlopen, @@ -162,7 +167,9 @@ def test_irestcall_transport_with_ctl(mocker): transport = iRestCall(url, user, password, ictl=ctl) tk = iToolKit() - transport.call(tk) + out = transport.call(tk) + + assert isinstance(out, (bytes, str)) assert_urlopen_params_correct( mock_urlopen, @@ -198,7 +205,9 @@ def allow_deprecated(): with allow_deprecated(): transport = iRestCall(url, user, password, isiz=size) tk = iToolKit() - transport.call(tk) + out = transport.call(tk) + + assert isinstance(out, (bytes, str)) assert len(recwarn) == 2 assert isinstance(recwarn[0].category, type(DeprecationWarning)) assert isinstance(recwarn[1].category, type(DeprecationWarning)) diff --git a/tests/test_unit_transport_database.py b/tests/test_unit_transport_database.py index 1529f1e..26320a5 100644 --- a/tests/test_unit_transport_database.py +++ b/tests/test_unit_transport_database.py @@ -5,7 +5,9 @@ def test_database_transport_callproc(database_callproc): transport = DatabaseTransport(database_callproc) tk = iToolKit() - transport.call(tk) + out = transport.call(tk) + + assert isinstance(out, (bytes, str)) cursor = database_callproc.cursor() @@ -16,7 +18,9 @@ def test_database_transport_callproc(database_callproc): def test_database_transport_execute(database_execute): transport = DatabaseTransport(database_execute) tk = iToolKit() - transport.call(tk) + out = transport.call(tk) + + assert isinstance(out, (bytes, str)) cursor = database_execute.cursor() @@ -28,7 +32,9 @@ def test_database_transport_execute_schema(database_execute): schema = 'MYSCHEMA' transport = DatabaseTransport(database_execute, schema=schema) tk = iToolKit() - transport.call(tk) + out = transport.call(tk) + + assert isinstance(out, (bytes, str)) cursor = database_execute.cursor() @@ -43,7 +49,9 @@ def test_database_transport_callproc_schema(database_execute): schema = 'MYSCHEMA' transport = DatabaseTransport(database_execute, schema=schema) tk = iToolKit() - transport.call(tk) + out = transport.call(tk) + + assert isinstance(out, (bytes, str)) cursor = database_execute.cursor() diff --git a/tests/test_unit_transport_http.py b/tests/test_unit_transport_http.py index d115ed8..ad0a416 100644 --- a/tests/test_unit_transport_http.py +++ b/tests/test_unit_transport_http.py @@ -17,7 +17,7 @@ def mock_http_urlopen(mocker): mock_urlopen = mocker.patch('itoolkit.transport.http.urlopen') mock_response = mocker.Mock() - mock_response.read.side_effect = XMLIN.encode('utf-8') + mock_response.read.side_effect = (XMLIN.encode('utf-8'), ) mock_urlopen.return_value = mock_response return mock_urlopen @@ -71,7 +71,9 @@ def test_http_transport_minimal(mocker): transport = HttpTransport(url, user, password) tk = iToolKit() - transport.call(tk) + out = transport.call(tk) + + assert isinstance(out, (bytes, str)) assert_urlopen_params_correct( mock_urlopen, @@ -91,7 +93,9 @@ def test_http_transport_with_database(mocker): transport = HttpTransport(url, user, password, database=database) tk = iToolKit() - transport.call(tk) + out = transport.call(tk) + + assert isinstance(out, (bytes, str)) assert_urlopen_params_correct( mock_urlopen, diff --git a/tests/test_unit_transport_ssh.py b/tests/test_unit_transport_ssh.py index 5c7894d..6d9dd96 100644 --- a/tests/test_unit_transport_ssh.py +++ b/tests/test_unit_transport_ssh.py @@ -23,7 +23,9 @@ def test_ssh_transport_minimal(mocker): transport = SshTransport(ssh_client) tk = iToolKit() - transport.call(tk) + out = transport.call(tk) + + assert isinstance(out, (bytes, str)) command = "/QOpenSys/pkgs/bin/xmlservice-cli" ssh_client.exec_command.assert_called_once_with(command)