Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions mergin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,18 @@ def server_type(self):
try:
resp = self.get("/config", validate_auth=False)
config = json.load(resp)
if config["server_type"] == "ce":
stype = config.get("server_type")
if stype == "ce":
self._server_type = ServerType.CE
elif config["server_type"] == "ee":
elif stype == "ee":
self._server_type = ServerType.EE
elif config["server_type"] == "saas":
elif stype == "saas":
self._server_type = ServerType.SAAS
except (ClientError, KeyError):
self._server_type = ServerType.OLD
except ClientError as e:
if getattr(e, "http_error", None) == 404:
self._server_type = ServerType.OLD
else:
raise

return self._server_type

Expand Down
18 changes: 18 additions & 0 deletions mergin/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import sqlite3
import glob

from unittest.mock import patch, Mock

from .. import InvalidProject
from ..client import (
MerginClient,
Expand Down Expand Up @@ -3008,3 +3010,19 @@ def test_validate_auth(mc: MerginClient):
# this should pass and not raise an error, as the client is able to re-login
with pytest.raises(LoginError):
mc_auth_token_login_wrong_password.validate_auth()


def test_server_type(mc):
"""Test mc.server_type() method"""
# success
assert mc.server_type() == ServerType.SAAS
mc._server_type = None
with patch("mergin.client.MerginClient.get") as mock_client_get:
# 404
mock_client_get.side_effect = ClientError(detail="Not found", http_error=404)
assert mc.server_type() == ServerType.OLD
mc._server_type = None
# 503
mock_client_get.side_effect = ClientError(detail="Service unavailable", http_error=503)
with pytest.raises(ClientError, match="Service unavailable"):
mc.server_type()
Loading