From 6844f1a46294e6f0efbb53798bbbd7b2c47ee128 Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Tue, 9 Jul 2024 12:37:19 +0200 Subject: [PATCH 01/17] Improve ClientError exception to not rely on text message --- mergin/client.py | 41 ++++++++++++++++++++++------------------- mergin/common.py | 21 ++++++++++++++++++++- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/mergin/client.py b/mergin/client.py index d949a46..0e9a124 100644 --- a/mergin/client.py +++ b/mergin/client.py @@ -205,19 +205,21 @@ def _do_request(self, request): try: return self.opener.open(request) except urllib.error.HTTPError as e: - if e.headers.get("Content-Type", "") == "application/problem+json": - info = json.load(e) - err_detail = info.get("detail") + server_code = None + server_response = None + if e.headers.get("Content-Type", "") == "application/json": + server_response = json.load(e) + err_detail = server_response.get("detail") + server_code = server_response.get("code") else: err_detail = e.read().decode("utf-8") - error_msg = ( - f"HTTP Error: {e.code} {e.reason}\n" - f"URL: {request.get_full_url()}\n" - f"Method: {request.get_method()}\n" - f"Detail: {err_detail}" - ) - raise ClientError(error_msg) + raise ClientError(detail=err_detail, + url=request.get_full_url(), + server_code=server_code, + server_response= server_response, + http_error=e.code, + http_method=request.get_method()) except urllib.error.URLError as e: # e.g. when DNS resolution fails (no internet connection?) raise ClientError("Error requesting " + request.full_url + ": " + str(e)) @@ -429,9 +431,10 @@ def create_workspace(self, workspace_name): try: self.post("/v1/workspace", params, {"Content-Type": "application/json"}) - except Exception as e: - detail = f"Workspace name: {workspace_name}" - raise ClientError(str(e), detail) + except ClientError as e: + e.extra = f"Workspace name: {workspace_name}" + raise e + def create_project(self, project_name, is_public=False, namespace=None): """ @@ -478,9 +481,9 @@ def create_project(self, project_name, is_public=False, namespace=None): namespace = self.username() try: self.post(f"/v1/project/{namespace}", params, {"Content-Type": "application/json"}) - except Exception as e: - detail = f"Namespace: {namespace}, project name: {project_name}" - raise ClientError(str(e), detail) + except ClientError as e: + e.extra = f"Namespace: {namespace}, project name: {project_name}" + raise e def create_project_and_push(self, project_name, directory, is_public=False, namespace=None): """ @@ -776,9 +779,9 @@ def set_project_access(self, project_path, access): try: request = urllib.request.Request(url, data=json.dumps(params).encode(), headers=json_headers, method="PUT") self._do_request(request) - except Exception as e: - detail = f"Project path: {project_path}" - raise ClientError(str(e), detail) + except ClientError as e: + e.extra = f"Project path: {project_path}" + raise e def add_user_permissions_to_project(self, project_path, usernames, permission_level): """ diff --git a/mergin/common.py b/mergin/common.py index bc75870..4217af2 100644 --- a/mergin/common.py +++ b/mergin/common.py @@ -11,7 +11,26 @@ class ClientError(Exception): - pass + def __init__(self, detail, url=None, server_code=None, server_response=None, http_error=None,http_method=None): + self.detail = detail + self.url = url + self.http_error = http_error + self.http_method = http_method + + self.server_code = server_code + self.server_response = server_response + + self.extra = None + + def __str__(self): + return ( + f"Detail: {self.detail}\n" + f"HTTP Error: {self.http_error}\n" if self.http_error else None + f"URL: {self.url}\n" if self.url else None + f"Method: {self.http_method}\n" if self.http_method else None + f"{self.extra}\n" if self.extra else None + ) + class LoginError(Exception): From afb9c68e7d7c3b71db9db8b154047fdc0b217e24 Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Tue, 9 Jul 2024 13:35:38 +0200 Subject: [PATCH 02/17] Fix error on multiline string --- mergin/common.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/mergin/common.py b/mergin/common.py index 4217af2..f154462 100644 --- a/mergin/common.py +++ b/mergin/common.py @@ -23,14 +23,12 @@ def __init__(self, detail, url=None, server_code=None, server_response=None, htt self.extra = None def __str__(self): - return ( - f"Detail: {self.detail}\n" - f"HTTP Error: {self.http_error}\n" if self.http_error else None - f"URL: {self.url}\n" if self.url else None - f"Method: {self.http_method}\n" if self.http_method else None - f"{self.extra}\n" if self.extra else None - ) - + return f"Detail: {self.detail}\n" \ + + f"HTTP Error: {self.http_error}\n" if self.http_error else None \ + + f"URL: {self.url}\n" if self.url else None \ + + f"Method: {self.http_method}\n" if self.http_method else None \ + + f"{self.extra}\n" if self.extra else None + class LoginError(Exception): From 090ab02fa31cf4e2a31ff1c62f4828d5e031762f Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Tue, 9 Jul 2024 14:15:35 +0200 Subject: [PATCH 03/17] Apply code style format --- mergin/client.py | 15 ++++++++------- mergin/common.py | 35 +++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/mergin/client.py b/mergin/client.py index 0e9a124..7e8d861 100644 --- a/mergin/client.py +++ b/mergin/client.py @@ -214,12 +214,14 @@ def _do_request(self, request): else: err_detail = e.read().decode("utf-8") - raise ClientError(detail=err_detail, - url=request.get_full_url(), - server_code=server_code, - server_response= server_response, - http_error=e.code, - http_method=request.get_method()) + raise ClientError( + detail=err_detail, + url=request.get_full_url(), + server_code=server_code, + server_response=server_response, + http_error=e.code, + http_method=request.get_method(), + ) except urllib.error.URLError as e: # e.g. when DNS resolution fails (no internet connection?) raise ClientError("Error requesting " + request.full_url + ": " + str(e)) @@ -435,7 +437,6 @@ def create_workspace(self, workspace_name): e.extra = f"Workspace name: {workspace_name}" raise e - def create_project(self, project_name, is_public=False, namespace=None): """ Create new project repository in user namespace on Mergin Maps server. diff --git a/mergin/common.py b/mergin/common.py index f154462..f906072 100644 --- a/mergin/common.py +++ b/mergin/common.py @@ -11,24 +11,31 @@ class ClientError(Exception): - def __init__(self, detail, url=None, server_code=None, server_response=None, http_error=None,http_method=None): - self.detail = detail - self.url = url - self.http_error = http_error - self.http_method = http_method + def __init__(self, detail, url=None, server_code=None, server_response=None, http_error=None, http_method=None): + self.detail = detail + self.url = url + self.http_error = http_error + self.http_method = http_method - self.server_code = server_code - self.server_response = server_response + self.server_code = server_code + self.server_response = server_response - self.extra = None + self.extra = None def __str__(self): - return f"Detail: {self.detail}\n" \ - + f"HTTP Error: {self.http_error}\n" if self.http_error else None \ - + f"URL: {self.url}\n" if self.url else None \ - + f"Method: {self.http_method}\n" if self.http_method else None \ - + f"{self.extra}\n" if self.extra else None - + return ( + f"Detail: {self.detail}\n" + f"HTTP Error: {self.http_error}\n" + if self.http_error + else ( + None + f"URL: {self.url}\n" + if self.url + else ( + None + f"Method: {self.http_method}\n" + if self.http_method + else None + f"{self.extra}\n" if self.extra else None + ) + ) + ) class LoginError(Exception): From 7883e8a194fed74cb65962395fe4f27e787944de Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Wed, 10 Jul 2024 10:42:23 +0200 Subject: [PATCH 04/17] Adress PR comment: use enum over simple string --- mergin/common.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mergin/common.py b/mergin/common.py index f906072..8c492ae 100644 --- a/mergin/common.py +++ b/mergin/common.py @@ -1,5 +1,5 @@ import os - +from enum import Enum CHUNK_SIZE = 100 * 1024 * 1024 @@ -10,6 +10,11 @@ this_dir = os.path.dirname(os.path.realpath(__file__)) +# Error code from the public API, add to the end of enum as we handle more eror +class ErrorCode(Enum): + ProjectsLimitHit = "ProjectsLimitHit" + + class ClientError(Exception): def __init__(self, detail, url=None, server_code=None, server_response=None, http_error=None, http_method=None): self.detail = detail From 9c7fd959b376d1c4aa760252ed7f42278a43e841 Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Wed, 10 Jul 2024 13:10:13 +0200 Subject: [PATCH 05/17] Sometimes the server responde with a content-type of application/json or application/problem+json e.g : -create project conflit : Error 409 with content-type application/problem+json -projects limit hit : Error 422 with content-type application/json We need to handle both case as they return slightly different structure --- mergin/client.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mergin/client.py b/mergin/client.py index 7e8d861..48b19a9 100644 --- a/mergin/client.py +++ b/mergin/client.py @@ -211,6 +211,9 @@ def _do_request(self, request): server_response = json.load(e) err_detail = server_response.get("detail") server_code = server_response.get("code") + elif e.headers.get("Content-Type", "") == "application/problem+json": + server_response = json.load(e) + err_detail = server_response.get("detail") else: err_detail = e.read().decode("utf-8") From 34fd1adb183fb00ec3665747496ee8a4f3630d59 Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Wed, 10 Jul 2024 14:49:35 +0200 Subject: [PATCH 06/17] clean up : avoid nesting if to generate string representation --- mergin/common.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/mergin/common.py b/mergin/common.py index 8c492ae..178da90 100644 --- a/mergin/common.py +++ b/mergin/common.py @@ -28,19 +28,16 @@ def __init__(self, detail, url=None, server_code=None, server_response=None, htt self.extra = None def __str__(self): - return ( - f"Detail: {self.detail}\n" + f"HTTP Error: {self.http_error}\n" - if self.http_error - else ( - None + f"URL: {self.url}\n" - if self.url - else ( - None + f"Method: {self.http_method}\n" - if self.http_method - else None + f"{self.extra}\n" if self.extra else None - ) - ) - ) + string_res = f"Detail: {self.detail}\n" + if self.http_error: + string_res += f"HTTP Error: {self.http_error}\n" + if self.url: + string_res += f"URL: {self.url}\n" + if self.http_method: + string_res += f"Method: {self.http_method}\n" + if self.extra: + string_res += f"{self.extra}\n" + return string_res class LoginError(Exception): From fbb4a65a04323057bb7948896987d1ca3c41ef78 Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Wed, 17 Jul 2024 12:00:44 +0200 Subject: [PATCH 07/17] Add LimitStorageHit error to enum --- mergin/common.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mergin/common.py b/mergin/common.py index 178da90..297ec3e 100644 --- a/mergin/common.py +++ b/mergin/common.py @@ -13,6 +13,7 @@ # Error code from the public API, add to the end of enum as we handle more eror class ErrorCode(Enum): ProjectsLimitHit = "ProjectsLimitHit" + StorageLimitHit = "StorageLimitHit" class ClientError(Exception): From 02a9d4e4009e757560eeb8d87afedda80a532181 Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Mon, 29 Jul 2024 14:35:14 +0200 Subject: [PATCH 08/17] Add tests --- mergin/client.py | 2 +- mergin/test/test_client.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/mergin/client.py b/mergin/client.py index 48b19a9..66f6be6 100644 --- a/mergin/client.py +++ b/mergin/client.py @@ -17,7 +17,7 @@ import typing import warnings -from .common import ClientError, LoginError, InvalidProject +from .common import ClientError, LoginError, InvalidProject, ErrorCode from .merginproject import MerginProject from .client_pull import ( download_file_finalize, diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index c08db02..e5c313e 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -19,6 +19,7 @@ decode_token_data, TokenError, ServerType, + ErrorCode ) from ..client_push import push_project_async, push_project_cancel from ..client_pull import ( @@ -2629,3 +2630,35 @@ def test_editor_push(mc: MerginClient, mc2: MerginClient): conflicted_file = project_file # There is no conflicted qgs file assert conflicted_file is None + + +def test_error_push_already_named_project(mc: MerginClient): + test_project = "test_push_already_existing" + project = API_USER + "/" + test_project + project_dir = os.path.join(TMP_DIR, test_project) + + try: + mc.create_project_and_push(test_project, project_dir) + except ClientError as e: + print(e) + assert e.detail == 'Project with the same name already exists' + assert e.http_error == 409 + assert e.http_method == 'POST' + assert e.url == 'https://test.dev.merginmaps.com/v1/project/test_plugin' + +def test_error_projects_limit_hit(mcStorage: MerginClient): + test_project = "test_another_project_above_projects_limit" + test_project_fullname = STORAGE_WORKSPACE + "/" + test_project + + project_dir = os.path.join(TMP_DIR, test_project, API_USER) + + try: + mcStorage.create_project_and_push(test_project, project_dir) + except ClientError as e: + print("BLVAVBLA") + print(e) + assert e.server_code == ErrorCode.ProjectsLimitHit.value + assert e.detail == 'Project with the same name already exists' + assert e.http_error == 422 + assert e.http_method == 'POST' + assert e.url == 'https://test.dev.merginmaps.com/v1/project/test_plugin' \ No newline at end of file From 4ecab3f3adbc84d0601b2ad46190baf76cecb1f3 Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Mon, 29 Jul 2024 14:45:28 +0200 Subject: [PATCH 09/17] Add utility function bytes_to_human_size --- mergin/utils.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mergin/utils.py b/mergin/utils.py index 0848a29..e9cab29 100644 --- a/mergin/utils.py +++ b/mergin/utils.py @@ -275,3 +275,21 @@ def is_mergin_config(path: str) -> bool: """Check if the given path is for file mergin-config.json""" filename = os.path.basename(path).lower() return filename == "mergin-config.json" + +def bytes_to_human_size(bytes: int): + """ + Convert bytes to human readable size + example : + bytes_to_human_size(5600000) -> "5.3 MB" + """ + precision = 1; + if ( bytes < 1e-5 ): + return "0.0 MB"; + elif ( bytes < 1024.0 * 1024.0 ): + return f"{round( bytes / 1024.0, precision )} KB"; + elif ( bytes < 1024.0 * 1024.0 * 1024.0 ): + return f"{round( bytes / 1024.0 / 1024.0, precision)} MB"; + elif ( bytes < 1024.0 * 1024.0 * 1024.0 * 1024.0 ): + return f"{round( bytes / 1024.0 / 1024.0 / 1024.0, precision )} GB"; + else: + return f"{round( bytes / 1024.0 / 1024.0 / 1024.0 / 1024.0, precision )} TB"; From 6f2bb97edd7600d8b4982f46eb1977ab3981536b Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Tue, 30 Jul 2024 13:31:19 +0200 Subject: [PATCH 10/17] Fix test and format --- mergin/test/test_client.py | 25 ++++++++++++++----------- mergin/utils.py | 25 +++++++++++++------------ 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index e5c313e..99ce2de 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -19,7 +19,7 @@ decode_token_data, TokenError, ServerType, - ErrorCode + ErrorCode, ) from ..client_push import push_project_async, push_project_cancel from ..client_pull import ( @@ -2637,14 +2637,15 @@ def test_error_push_already_named_project(mc: MerginClient): project = API_USER + "/" + test_project project_dir = os.path.join(TMP_DIR, test_project) - try: + try: mc.create_project_and_push(test_project, project_dir) except ClientError as e: print(e) - assert e.detail == 'Project with the same name already exists' + assert e.detail == "Project with the same name already exists" assert e.http_error == 409 - assert e.http_method == 'POST' - assert e.url == 'https://test.dev.merginmaps.com/v1/project/test_plugin' + assert e.http_method == "POST" + assert e.url == "https://test.dev.merginmaps.com/v1/project/test_plugin" + def test_error_projects_limit_hit(mcStorage: MerginClient): test_project = "test_another_project_above_projects_limit" @@ -2653,12 +2654,14 @@ def test_error_projects_limit_hit(mcStorage: MerginClient): project_dir = os.path.join(TMP_DIR, test_project, API_USER) try: - mcStorage.create_project_and_push(test_project, project_dir) + mcStorage.create_project_and_push(test_project_fullname, project_dir) except ClientError as e: - print("BLVAVBLA") - print(e) assert e.server_code == ErrorCode.ProjectsLimitHit.value - assert e.detail == 'Project with the same name already exists' + assert ( + e.detail + == "Maximum number of projects is reached. Please upgrade your subscription\ + to create new projects (ProjectsLimitHit)" + ) assert e.http_error == 422 - assert e.http_method == 'POST' - assert e.url == 'https://test.dev.merginmaps.com/v1/project/test_plugin' \ No newline at end of file + assert e.http_method == "POST" + assert e.url == "https://test.dev.merginmaps.com/v1/project/testpluginstorage" diff --git a/mergin/utils.py b/mergin/utils.py index e9cab29..7b6c9f9 100644 --- a/mergin/utils.py +++ b/mergin/utils.py @@ -276,20 +276,21 @@ def is_mergin_config(path: str) -> bool: filename = os.path.basename(path).lower() return filename == "mergin-config.json" + def bytes_to_human_size(bytes: int): """ - Convert bytes to human readable size - example : + Convert bytes to human readable size + example : bytes_to_human_size(5600000) -> "5.3 MB" """ - precision = 1; - if ( bytes < 1e-5 ): - return "0.0 MB"; - elif ( bytes < 1024.0 * 1024.0 ): - return f"{round( bytes / 1024.0, precision )} KB"; - elif ( bytes < 1024.0 * 1024.0 * 1024.0 ): - return f"{round( bytes / 1024.0 / 1024.0, precision)} MB"; - elif ( bytes < 1024.0 * 1024.0 * 1024.0 * 1024.0 ): - return f"{round( bytes / 1024.0 / 1024.0 / 1024.0, precision )} GB"; + precision = 1 + if bytes < 1e-5: + return "0.0 MB" + elif bytes < 1024.0 * 1024.0: + return f"{round( bytes / 1024.0, precision )} KB" + elif bytes < 1024.0 * 1024.0 * 1024.0: + return f"{round( bytes / 1024.0 / 1024.0, precision)} MB" + elif bytes < 1024.0 * 1024.0 * 1024.0 * 1024.0: + return f"{round( bytes / 1024.0 / 1024.0 / 1024.0, precision )} GB" else: - return f"{round( bytes / 1024.0 / 1024.0 / 1024.0 / 1024.0, precision )} TB"; + return f"{round( bytes / 1024.0 / 1024.0 / 1024.0 / 1024.0, precision )} TB" From 2b6955d6c5ea1443b4ea8016021079a916f77430 Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Wed, 31 Jul 2024 13:16:59 +0200 Subject: [PATCH 11/17] Fix error in the test because of line split --- mergin/test/test_client.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index 99ce2de..e966603 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -2659,8 +2659,7 @@ def test_error_projects_limit_hit(mcStorage: MerginClient): assert e.server_code == ErrorCode.ProjectsLimitHit.value assert ( e.detail - == "Maximum number of projects is reached. Please upgrade your subscription\ - to create new projects (ProjectsLimitHit)" + == "Maximum number of projects is reached. Please upgrade your subscription to create new projects (ProjectsLimitHit)" ) assert e.http_error == 422 assert e.http_method == "POST" From 33509987a6d680d9abbb30fccd93f19a739ee621 Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Tue, 6 Aug 2024 14:45:18 +0200 Subject: [PATCH 12/17] Always handle json server response the same way whatever the content-type --- mergin/client.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/mergin/client.py b/mergin/client.py index 66f6be6..f8e1551 100644 --- a/mergin/client.py +++ b/mergin/client.py @@ -205,17 +205,11 @@ def _do_request(self, request): try: return self.opener.open(request) except urllib.error.HTTPError as e: - server_code = None - server_response = None - if e.headers.get("Content-Type", "") == "application/json": - server_response = json.load(e) - err_detail = server_response.get("detail") - server_code = server_response.get("code") - elif e.headers.get("Content-Type", "") == "application/problem+json": - server_response = json.load(e) - err_detail = server_response.get("detail") - else: - err_detail = e.read().decode("utf-8") + server_response = json.load(e) + + # We first to try to get the value from the response otherwise we set a default value + err_detail = server_response.get("detail", e.read().decode("utf-8")) + server_code = server_response.get("code", None) raise ClientError( detail=err_detail, From c4e9dbe21a2ee8cfc08781823a739b04146c83ee Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Tue, 27 Aug 2024 10:51:41 +0200 Subject: [PATCH 13/17] Adress PR comment on tests --- mergin/test/test_client.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index e966603..c72f5e4 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -2637,14 +2637,12 @@ def test_error_push_already_named_project(mc: MerginClient): project = API_USER + "/" + test_project project_dir = os.path.join(TMP_DIR, test_project) - try: + with pytest.raises(ClientError) as e: mc.create_project_and_push(test_project, project_dir) - except ClientError as e: - print(e) - assert e.detail == "Project with the same name already exists" - assert e.http_error == 409 - assert e.http_method == "POST" - assert e.url == "https://test.dev.merginmaps.com/v1/project/test_plugin" + assert e.detail == "Project with the same name already exists" + assert e.http_error == 409 + assert e.http_method == "POST" + assert e.url == f"{mc.url}v1/project/test_plugin" def test_error_projects_limit_hit(mcStorage: MerginClient): @@ -2653,14 +2651,13 @@ def test_error_projects_limit_hit(mcStorage: MerginClient): project_dir = os.path.join(TMP_DIR, test_project, API_USER) - try: + with pytest.raises(ClientError) as e: mcStorage.create_project_and_push(test_project_fullname, project_dir) - except ClientError as e: - assert e.server_code == ErrorCode.ProjectsLimitHit.value - assert ( - e.detail - == "Maximum number of projects is reached. Please upgrade your subscription to create new projects (ProjectsLimitHit)" - ) - assert e.http_error == 422 - assert e.http_method == "POST" - assert e.url == "https://test.dev.merginmaps.com/v1/project/testpluginstorage" + assert e.server_code == ErrorCode.ProjectsLimitHit.value + assert ( + e.detail + == "Maximum number of projects is reached. Please upgrade your subscription to create new projects (ProjectsLimitHit)" + ) + assert e.http_error == 422 + assert e.http_method == "POST" + assert e.url == "https://test.dev.merginmaps.com/v1/project/testpluginstorage" From 621c5ffe2bbfc3103894ee6f63b26a88ea963551 Mon Sep 17 00:00:00 2001 From: "marcel.kocisek" Date: Mon, 2 Sep 2024 16:33:51 +0200 Subject: [PATCH 14/17] Update testing server --- .github/workflows/autotests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/autotests.yml b/.github/workflows/autotests.yml index 8997abd..50b5660 100644 --- a/.github/workflows/autotests.yml +++ b/.github/workflows/autotests.yml @@ -1,7 +1,7 @@ name: Auto Tests on: [push] env: - TEST_MERGIN_URL: https://test.dev.merginmaps.com/ + TEST_MERGIN_URL: https://app.dev.merginmaps.com/ TEST_API_USERNAME: test_plugin TEST_API_PASSWORD: ${{ secrets.MERGINTEST_API_PASSWORD }} TEST_API_USERNAME2: test_plugin2 From 3c2976da62e83aeb659fbeeb30509aeef4547ae6 Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Mon, 2 Sep 2024 17:27:20 +0200 Subject: [PATCH 15/17] Fix misuse of pytest library --- mergin/test/test_client.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index c72f5e4..95e8800 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -2639,10 +2639,10 @@ def test_error_push_already_named_project(mc: MerginClient): with pytest.raises(ClientError) as e: mc.create_project_and_push(test_project, project_dir) - assert e.detail == "Project with the same name already exists" - assert e.http_error == 409 - assert e.http_method == "POST" - assert e.url == f"{mc.url}v1/project/test_plugin" + assert e.value.detail == "Project with the same name already exists" + assert e.value.http_error == 409 + assert e.value.http_method == "POST" + assert e.value.url == f"{mc.url}v1/project/test_plugin" def test_error_projects_limit_hit(mcStorage: MerginClient): @@ -2653,11 +2653,11 @@ def test_error_projects_limit_hit(mcStorage: MerginClient): with pytest.raises(ClientError) as e: mcStorage.create_project_and_push(test_project_fullname, project_dir) - assert e.server_code == ErrorCode.ProjectsLimitHit.value + assert e.value.server_code == ErrorCode.ProjectsLimitHit.value assert ( - e.detail + e.value.detail == "Maximum number of projects is reached. Please upgrade your subscription to create new projects (ProjectsLimitHit)" ) - assert e.http_error == 422 - assert e.http_method == "POST" - assert e.url == "https://test.dev.merginmaps.com/v1/project/testpluginstorage" + assert e.value.http_error == 422 + assert e.value.http_method == "POST" + assert e.value.url == f"{mcStorage.url}v1/project/testpluginstorage" From 00e55cbd02ebae51799e3af6f46f751665e5ef28 Mon Sep 17 00:00:00 2001 From: "marcel.kocisek" Date: Mon, 2 Sep 2024 18:07:44 +0200 Subject: [PATCH 16/17] Fix for available storage project --- mergin/test/test_client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index 95e8800..b9d1f60 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -797,7 +797,7 @@ def test_available_storage_validation(mcStorage): assert got_right_err # Expecting empty project - project_info = get_project_info(mcStorage, API_USER, test_project) + project_info = get_project_info(mcStorage, STORAGE_WORKSPACE, test_project) assert project_info["version"] == "v0" assert project_info["disk_usage"] == 0 @@ -873,6 +873,8 @@ def get_project_info(mc, namespace, project_name): """ projects = mc.projects_list(flag="created") test_project_list = [p for p in projects if p["name"] == project_name and p["namespace"] == namespace] + print(namespace) + print(test_project_list) assert len(test_project_list) == 1 return test_project_list[0] From dd16754d4c30c1968556933a9b4b74eda6393fee Mon Sep 17 00:00:00 2001 From: "marcel.kocisek" Date: Mon, 2 Sep 2024 18:09:34 +0200 Subject: [PATCH 17/17] Final cleanup --- mergin/test/test_client.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index b9d1f60..d19d519 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -873,8 +873,6 @@ def get_project_info(mc, namespace, project_name): """ projects = mc.projects_list(flag="created") test_project_list = [p for p in projects if p["name"] == project_name and p["namespace"] == namespace] - print(namespace) - print(test_project_list) assert len(test_project_list) == 1 return test_project_list[0]