Skip to content

Commit 02a9d4e

Browse files
committed
Add tests
1 parent fbb4a65 commit 02a9d4e

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

mergin/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import typing
1818
import warnings
1919

20-
from .common import ClientError, LoginError, InvalidProject
20+
from .common import ClientError, LoginError, InvalidProject, ErrorCode
2121
from .merginproject import MerginProject
2222
from .client_pull import (
2323
download_file_finalize,

mergin/test/test_client.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
decode_token_data,
2020
TokenError,
2121
ServerType,
22+
ErrorCode
2223
)
2324
from ..client_push import push_project_async, push_project_cancel
2425
from ..client_pull import (
@@ -2629,3 +2630,35 @@ def test_editor_push(mc: MerginClient, mc2: MerginClient):
26292630
conflicted_file = project_file
26302631
# There is no conflicted qgs file
26312632
assert conflicted_file is None
2633+
2634+
2635+
def test_error_push_already_named_project(mc: MerginClient):
2636+
test_project = "test_push_already_existing"
2637+
project = API_USER + "/" + test_project
2638+
project_dir = os.path.join(TMP_DIR, test_project)
2639+
2640+
try:
2641+
mc.create_project_and_push(test_project, project_dir)
2642+
except ClientError as e:
2643+
print(e)
2644+
assert e.detail == 'Project with the same name already exists'
2645+
assert e.http_error == 409
2646+
assert e.http_method == 'POST'
2647+
assert e.url == 'https://test.dev.merginmaps.com/v1/project/test_plugin'
2648+
2649+
def test_error_projects_limit_hit(mcStorage: MerginClient):
2650+
test_project = "test_another_project_above_projects_limit"
2651+
test_project_fullname = STORAGE_WORKSPACE + "/" + test_project
2652+
2653+
project_dir = os.path.join(TMP_DIR, test_project, API_USER)
2654+
2655+
try:
2656+
mcStorage.create_project_and_push(test_project, project_dir)
2657+
except ClientError as e:
2658+
print("BLVAVBLA")
2659+
print(e)
2660+
assert e.server_code == ErrorCode.ProjectsLimitHit.value
2661+
assert e.detail == 'Project with the same name already exists'
2662+
assert e.http_error == 422
2663+
assert e.http_method == 'POST'
2664+
assert e.url == 'https://test.dev.merginmaps.com/v1/project/test_plugin'

0 commit comments

Comments
 (0)