Skip to content

Commit d352c8c

Browse files
MarcelGeowonder-sk
authored andcommitted
Added workspace and client for testing available storage
1 parent b289c45 commit d352c8c

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ If you plan to run `mergin` command multiple times and you wish to avoid logging
140140
you can use "login" command to get authorization token.
141141
It will ask for password and then output environment variable with auth token. The returned token
142142
is not permanent - it will expire after several hours.
143-
```
143+
```bash
144144
$ mergin --username john login
145145
Password: topsecret
146146
Login successful!
@@ -160,15 +160,15 @@ it is possible to run other commands without specifying username/password.
160160
### Installing deps
161161

162162
Python 3.7+ required. Create `mergin/deps` folder where [geodiff](https://github.com/MerginMaps/geodiff) lib is supposed to be and install dependencies:
163-
```
163+
```bash
164164
rm -r mergin/deps
165165
mkdir mergin/deps
166166
pip install python-dateutil pytz
167167
pip install pygeodiff --target=mergin/deps
168168
```
169169

170170
For using mergin client with its dependencies packaged locally run:
171-
```
171+
```bash
172172
pip install wheel
173173
python3 setup.py sdist bdist_wheel
174174
mkdir -p mergin/deps
@@ -180,13 +180,15 @@ For using mergin client with its dependencies packaged locally run:
180180
### Tests
181181
For running test do:
182182

183-
```
183+
```bash
184184
cd mergin
185185
export TEST_MERGIN_URL=<url> # testing server
186186
export TEST_API_USERNAME=<username>
187187
export TEST_API_PASSWORD=<pwd>
188188
export TEST_API_USERNAME2=<username2>
189189
export TEST_API_PASSWORD2=<pwd2>
190+
# workspace name with controlled available storage space (e.g. 20MB), default value: testpluginstorage
191+
export TEST_STORAGE_WORKSPACE=<workspacename>
190192
pip install pytest pytest-cov coveralls
191193
pytest --cov-report html --cov=mergin mergin/test/
192194
```

mergin/test/test_client.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
TMP_DIR = tempfile.gettempdir()
5050
TEST_DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "test_data")
5151
CHANGED_SCHEMA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "modified_schema")
52+
STORAGE_WORKSPACE = os.environ.get("TEST_STORAGE_WORKSPACE", "testpluginstorage")
5253

5354

5455
@pytest.fixture(scope="function")
@@ -65,14 +66,21 @@ def mc2():
6566
return client
6667

6768

69+
@pytest.fixture(scope="function")
70+
def mcStorage():
71+
client = create_client(API_USER, USER_PWD)
72+
create_workspace_for_client(client, STORAGE_WORKSPACE)
73+
return client
74+
75+
6876
def create_client(user, pwd):
6977
assert SERVER_URL and SERVER_URL.rstrip("/") != "https://app.merginmaps.com" and user and pwd
7078
return MerginClient(SERVER_URL, login=user, password=pwd)
7179

7280

73-
def create_workspace_for_client(mc):
81+
def create_workspace_for_client(mc: MerginClient, workspace_name=None):
7482
try:
75-
mc.create_workspace(mc.username())
83+
mc.create_workspace(workspace_name or mc.username())
7684
except ClientError:
7785
return
7886

@@ -736,33 +744,34 @@ def test_set_editor_access(mc):
736744
assert API_USER2 not in access["writersnames"]
737745

738746

739-
def test_available_storage_validation(mc):
747+
def test_available_storage_validation(mcStorage):
740748
"""
741749
Testing of storage limit - applies to user pushing changes into own project (namespace matching username).
742750
This test also tests giving read and write access to another user. Additionally tests also uploading of big file.
743751
"""
744752
test_project = "test_available_storage_validation"
745-
test_project_fullname = API_USER + "/" + test_project
753+
test_project_fullname = STORAGE_WORKSPACE + "/" + test_project
746754

747755
# cleanups
748756
project_dir = os.path.join(TMP_DIR, test_project, API_USER)
749-
cleanup(mc, test_project_fullname, [project_dir])
757+
cleanup(mcStorage, test_project_fullname, [project_dir])
750758

751759
# create new (empty) project on server
752-
mc.create_project(test_project)
760+
# if namespace is not provided, function is creating project with username
761+
mcStorage.create_project(test_project_fullname)
753762

754763
# download project
755-
mc.download_project(test_project_fullname, project_dir)
764+
mcStorage.download_project(test_project_fullname, project_dir)
756765

757766
# get info about storage capacity
758767
storage_remaining = 0
759768

760-
if mc.server_type() == ServerType.OLD:
761-
user_info = mc.user_info()
769+
if mcStorage.server_type() == ServerType.OLD:
770+
user_info = mcStorage.user_info()
762771
storage_remaining = user_info["storage"] - user_info["disk_usage"]
763772
else:
764-
for workspace in mc.workspaces_list():
765-
if workspace["name"] == API_USER:
773+
for workspace in mcStorage.workspaces_list():
774+
if workspace["name"] == STORAGE_WORKSPACE:
766775
storage_remaining = workspace["storage"] - workspace["disk_usage"]
767776
break
768777

@@ -774,15 +783,15 @@ def test_available_storage_validation(mc):
774783
# try to upload
775784
got_right_err = False
776785
try:
777-
mc.push_project(project_dir)
786+
mcStorage.push_project(project_dir)
778787
except ClientError as e:
779788
# Expecting "You have reached a data limit" 400 server error msg.
780789
assert "You have reached a data limit" in str(e)
781790
got_right_err = True
782791
assert got_right_err
783792

784793
# Expecting empty project
785-
project_info = get_project_info(mc, API_USER, test_project)
794+
project_info = get_project_info(mcStorage, API_USER, test_project)
786795
assert project_info["version"] == "v0"
787796
assert project_info["disk_usage"] == 0
788797

0 commit comments

Comments
 (0)