File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -388,7 +388,7 @@ def server_type(self):
388388 elif stype == "saas" :
389389 self ._server_type = ServerType .SAAS
390390 except ClientError as e :
391- if getattr (e , "status_code " , None ) == 404 :
391+ if getattr (e , "http_error " , None ) == 404 :
392392 self ._server_type = ServerType .OLD
393393 else :
394394 raise
Original file line number Diff line number Diff line change 1111import sqlite3
1212import glob
1313
14+ from unittest .mock import patch , Mock
15+
1416from .. import InvalidProject
1517from ..client import (
1618 MerginClient ,
@@ -3008,3 +3010,19 @@ def test_validate_auth(mc: MerginClient):
30083010 # this should pass and not raise an error, as the client is able to re-login
30093011 with pytest .raises (LoginError ):
30103012 mc_auth_token_login_wrong_password .validate_auth ()
3013+
3014+
3015+ def test_server_type (mc ):
3016+ """Test mc.server_type() method"""
3017+ # success
3018+ assert mc .server_type () == ServerType .SAAS
3019+ mc ._server_type = None
3020+ with patch ("mergin.client.MerginClient.get" ) as mock_client_get :
3021+ # 404
3022+ mock_client_get .side_effect = ClientError (detail = "Not found" , http_error = 404 )
3023+ assert mc .server_type () == ServerType .OLD
3024+ mc ._server_type = None
3025+ # 503
3026+ mock_client_get .side_effect = ClientError (detail = "Service unavailable" , http_error = 503 )
3027+ with pytest .raises (ClientError , match = "Service unavailable" ):
3028+ mc .server_type ()
You can’t perform that action at this time.
0 commit comments