From 6f2bb97edd7600d8b4982f46eb1977ab3981536b Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Tue, 30 Jul 2024 13:31:19 +0200 Subject: [PATCH] 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"