File tree Expand file tree Collapse file tree 2 files changed +27
-5
lines changed
Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -380,14 +380,18 @@ def server_type(self):
380380 try :
381381 resp = self .get ("/config" , validate_auth = False )
382382 config = json .load (resp )
383- if config ["server_type" ] == "ce" :
383+ stype = config .get ("server_type" )
384+ if stype == "ce" :
384385 self ._server_type = ServerType .CE
385- elif config [ "server_type" ] == "ee" :
386+ elif stype == "ee" :
386387 self ._server_type = ServerType .EE
387- elif config [ "server_type" ] == "saas" :
388+ elif stype == "saas" :
388389 self ._server_type = ServerType .SAAS
389- except (ClientError , KeyError ):
390- self ._server_type = ServerType .OLD
390+ except ClientError as e :
391+ if getattr (e , "http_error" , None ) == 404 :
392+ self ._server_type = ServerType .OLD
393+ else :
394+ raise
391395
392396 return self ._server_type
393397
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