22from yoti_python_sandbox .tests .conftest import PEM_FILE_PATH
33from yoti_python_sandbox .token import YotiTokenRequest
44from yoti_python_sandbox .token import YotiTokenResponse
5+ from .mocks import mocked_request_failed_sandbox_token
6+ from ..sandbox_exception import SandboxException
57
68try :
7- from unittest . mock import patch
9+ from unittest import mock
810except ImportError :
9- from mock import patch
11+ import mock
1012
1113import pytest
1214
@@ -36,7 +38,7 @@ def test_builder_should_build_client():
3638 assert isinstance (client , SandboxClient )
3739
3840
39- @patch ("yoti_python_sandbox.client.SandboxClient" )
41+ @mock . patch ("yoti_python_sandbox.client.SandboxClient" )
4042def test_client_should_return_token_from_sandbox (sandbox_client_mock ):
4143 sandbox_client_mock .setup_profile_share .return_value = YotiTokenResponse (
4244 "some-token"
@@ -48,3 +50,23 @@ def test_client_should_return_token_from_sandbox(sandbox_client_mock):
4850 response = sandbox_client_mock .setup_profile_share (token_request )
4951
5052 assert response .token == "some-token"
53+
54+
55+ @mock .patch ("yoti_python_sdk.http.SignedRequest.execute" , side_effect = mocked_request_failed_sandbox_token )
56+ def test_client_should_bubble_sandbox_exception (_ ):
57+ client = (
58+ SandboxClient .builder ()
59+ .for_application ("some_app" )
60+ .with_pem_file (PEM_FILE_PATH )
61+ .with_sandbox_url ("https://localhost" )
62+ .build ()
63+ )
64+
65+ token_request = (
66+ YotiTokenRequest .builder ().with_remember_me_id ("remember_me_pls" ).build ()
67+ )
68+
69+ with pytest .raises (SandboxException ) as ex :
70+ client .setup_sharing_profile (token_request )
71+ assert isinstance (ex .value , SandboxException )
72+ assert ex .value .text == "Org not found"
0 commit comments