Skip to content

Commit 59e04fe

Browse files
committed
Fix 'http_error' & add test
1 parent 6971a24 commit 59e04fe

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

mergin/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

mergin/test/test_client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import sqlite3
1212
import glob
1313

14+
from unittest.mock import patch, Mock
15+
1416
from .. import InvalidProject
1517
from ..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()

0 commit comments

Comments
 (0)