From 831c72dbe5d64b468eb2089ecdd3cce24a584f59 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Thu, 15 Feb 2024 15:03:13 +0100 Subject: [PATCH 1/3] Fix unit-tests. related to internal ticket CURA-11406 --- tests/TestOAuth2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestOAuth2.py b/tests/TestOAuth2.py index 09fa555af4..82d138a71e 100644 --- a/tests/TestOAuth2.py +++ b/tests/TestOAuth2.py @@ -97,7 +97,7 @@ def test__parseJWTNoRefreshToken(): mock_reply = Mock() # The user profile that the service should respond with. mock_reply.error = Mock(return_value = QNetworkReply.NetworkError.NoError) http_mock = Mock() - http_mock.get = lambda url, headers_dict, callback, error_callback: callback(mock_reply) + http_mock.get = lambda url, headers_dict, callback, error_callback, timeout: callback(mock_reply) http_mock.readJSON = Mock(return_value = {"data": {"user_id": "id_ego_or_superego", "username": "Ghostkeeper"}}) with patch("UM.TaskManagement.HttpRequestManager.HttpRequestManager.getInstance", MagicMock(return_value = http_mock)): From 58f8eae80cd84cf0112a4d851a842f3ff36cc430 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Thu, 15 Feb 2024 15:45:49 +0100 Subject: [PATCH 2/3] Fix more unit-tests. related to internal ticket CURA-11406 --- tests/TestOAuth2.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/TestOAuth2.py b/tests/TestOAuth2.py index 82d138a71e..c7985e39f3 100644 --- a/tests/TestOAuth2.py +++ b/tests/TestOAuth2.py @@ -119,8 +119,8 @@ def test__parseJWTFailOnRefresh(): mock_reply = Mock() # The response that the request should give, containing an error about it failing to authenticate. mock_reply.error = Mock(return_value = QNetworkReply.NetworkError.AuthenticationRequiredError) # The reply is 403: Authentication required, meaning the server responded with a "Can't do that, Dave". http_mock = Mock() - http_mock.get = lambda url, headers_dict, callback, error_callback: callback(mock_reply) - http_mock.post = lambda url, data, headers_dict, callback, error_callback: callback(mock_reply) + http_mock.get = lambda url, headers_dict, callback, error_callback, timeout: callback(mock_reply) + http_mock.post = lambda url, data, headers_dict, callback, error_callback, timeout: callback(mock_reply) with patch("UM.TaskManagement.HttpRequestManager.HttpRequestManager.readJSON", Mock(return_value = {"error_description": "Mock a failed request!"})): with patch("UM.TaskManagement.HttpRequestManager.HttpRequestManager.getInstance", MagicMock(return_value = http_mock)): @@ -142,7 +142,7 @@ def test__parseJWTSucceedOnRefresh(): mock_reply_failure = Mock() mock_reply_failure.error = Mock(return_value = QNetworkReply.NetworkError.AuthenticationRequiredError) http_mock = Mock() - def mock_get(url, headers_dict, callback, error_callback): + def mock_get(url, headers_dict, callback, error_callback, timeout): if(headers_dict == {"Authorization": "Bearer beep"}): callback(mock_reply_success) else: @@ -181,8 +181,8 @@ def test_refreshAccessTokenFailed(): mock_reply = Mock() # The response that the request should give, containing an error about it failing to authenticate. mock_reply.error = Mock(return_value = QNetworkReply.NetworkError.AuthenticationRequiredError) # The reply is 403: Authentication required, meaning the server responded with a "Can't do that, Dave". http_mock = Mock() - http_mock.get = lambda url, headers_dict, callback, error_callback: callback(mock_reply) - http_mock.post = lambda url, data, headers_dict, callback, error_callback: callback(mock_reply) + http_mock.get = lambda url, headers_dict, callback, error_callback, timeout: callback(mock_reply) + http_mock.post = lambda url, data, headers_dict, callback, error_callback, timeout: callback(mock_reply) with patch("UM.TaskManagement.HttpRequestManager.HttpRequestManager.readJSON", Mock(return_value = {"error_description": "Mock a failed request!"})): with patch("UM.TaskManagement.HttpRequestManager.HttpRequestManager.getInstance", MagicMock(return_value = http_mock)): @@ -263,7 +263,7 @@ def test_loginAndLogout() -> None: mock_reply = Mock() # The user profile that the service should respond with. mock_reply.error = Mock(return_value = QNetworkReply.NetworkError.NoError) http_mock = Mock() - http_mock.get = lambda url, headers_dict, callback, error_callback: callback(mock_reply) + http_mock.get = lambda url, headers_dict, callback, error_callback, timeout: callback(mock_reply) http_mock.readJSON = Mock(return_value = {"data": {"user_id": "di_resu", "username": "Emanresu"}}) # Let the service think there was a successful response From 77823a9c122331e24496c75be34c6365b2bf37b0 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Thu, 15 Feb 2024 16:01:32 +0100 Subject: [PATCH 3/3] Fix more unit-tests II. related to internal ticket CURA-11406 --- tests/TestOAuth2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/TestOAuth2.py b/tests/TestOAuth2.py index c7985e39f3..41edaebbf7 100644 --- a/tests/TestOAuth2.py +++ b/tests/TestOAuth2.py @@ -120,7 +120,7 @@ def test__parseJWTFailOnRefresh(): mock_reply.error = Mock(return_value = QNetworkReply.NetworkError.AuthenticationRequiredError) # The reply is 403: Authentication required, meaning the server responded with a "Can't do that, Dave". http_mock = Mock() http_mock.get = lambda url, headers_dict, callback, error_callback, timeout: callback(mock_reply) - http_mock.post = lambda url, data, headers_dict, callback, error_callback, timeout: callback(mock_reply) + http_mock.post = lambda url, data, headers_dict, callback, error_callback, urgent, timeout: callback(mock_reply) with patch("UM.TaskManagement.HttpRequestManager.HttpRequestManager.readJSON", Mock(return_value = {"error_description": "Mock a failed request!"})): with patch("UM.TaskManagement.HttpRequestManager.HttpRequestManager.getInstance", MagicMock(return_value = http_mock)): @@ -182,7 +182,7 @@ def test_refreshAccessTokenFailed(): mock_reply.error = Mock(return_value = QNetworkReply.NetworkError.AuthenticationRequiredError) # The reply is 403: Authentication required, meaning the server responded with a "Can't do that, Dave". http_mock = Mock() http_mock.get = lambda url, headers_dict, callback, error_callback, timeout: callback(mock_reply) - http_mock.post = lambda url, data, headers_dict, callback, error_callback, timeout: callback(mock_reply) + http_mock.post = lambda url, data, headers_dict, callback, error_callback, urgent, timeout: callback(mock_reply) with patch("UM.TaskManagement.HttpRequestManager.HttpRequestManager.readJSON", Mock(return_value = {"error_description": "Mock a failed request!"})): with patch("UM.TaskManagement.HttpRequestManager.HttpRequestManager.getInstance", MagicMock(return_value = http_mock)):