Skip to content

Commit

Permalink
Fix test and format
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinBuira committed Jul 30, 2024
1 parent 4ecab3f commit 6f2bb97
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
25 changes: 14 additions & 11 deletions mergin/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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"
Expand All @@ -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'
assert e.http_method == "POST"
assert e.url == "https://test.dev.merginmaps.com/v1/project/testpluginstorage"
25 changes: 13 additions & 12 deletions mergin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 6f2bb97

Please sign in to comment.