Skip to content

Commit

Permalink
WIP: begin unit test for validate_taskdef_meta() rockstor#2355
Browse files Browse the repository at this point in the history
  • Loading branch information
FroggyFlox committed Feb 26, 2023
1 parent fe71be8 commit 691f194
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 2 deletions.
39 changes: 39 additions & 0 deletions src/rockstor/storageadmin/fixtures/test_config_backup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[
{
"model": "storageadmin.pool",
"pk": 2,
"fields": {
"name": "rock-pool",
"uuid": "3d60105b-abae-456f-bbd1-a5f410295e9c",
"size": 5242880,
"raid": "single",
"toc": "2023-02-26T19:46:33.066Z",
"compression": "no",
"mnt_options": null,
"role": null
}
},
{
"model": "storageadmin.share",
"pk": 3,
"fields": {
"pool": 2,
"qgroup": "0/301",
"pqgroup": "2015/136",
"name": "test_share01",
"uuid": null,
"size": 5242880,
"owner": "root",
"group": "root",
"perms": "755",
"toc": "2023-02-26T19:46:33.136Z",
"subvol_name": "test_share01",
"replica": false,
"compression_algo": null,
"rusage": 16,
"eusage": 16,
"pqgroup_rusage": 16,
"pqgroup_eusage": 16
}
}
]
64 changes: 62 additions & 2 deletions src/rockstor/storageadmin/tests/test_config_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,26 @@
validate_install_config,
validate_update_config,
validate_service_status,
validate_taskdef_meta,
)

"""
Fixture creation instructions:
System needs 1 non system pool 'rock-pool', at any raid level.
- Create 1 share named 'test_share01'
poetry run django-admin dumpdata storageadmin.pool storageadmin.share \
--natural-foreign --indent 4 > \
src/rockstor/storageadmin/fixtures/test_config_backup.json
export DJANGO_SETTINGS_MODULE="settings"
cd src/rockstor && poetry run test -v 2 -p test_config_backup.py
"""

class ConfigBackupTests(APITestMixin):
# Proposed fixture = "test_config-backup" was "fix2.json"
fixtures = ["test_api.json"]
fixtures = ["test_api.json", "test_config_backup.json"]
BASE_URL = "/api/config-backup"
sa_ml = [
{
Expand Down Expand Up @@ -1138,6 +1152,18 @@ class ConfigBackupTests(APITestMixin):
"model": "smart_manager.servicestatus",
"pk": 32,
},
# {
# "fields": {
# "name": "snap_daily_ts01",
# "task_type": "snapshot",
# "json_meta": "{\"writable\": true, \"visible\": true, \"prefix\": \"snap_daily_ts01\", \"share\": \"2\", \"max_count\": \"4\"}",
# "enabled": False,
# "crontab": "42 3 * * *",
# "crontabwindow": "*-*-*-*-*-*"
# },
# "model": "smart_manager.taskdefinition",
# "pk": 1,
# }
]

@classmethod
Expand Down Expand Up @@ -1793,3 +1819,37 @@ def test_validate_service_status(self):
"returned = {}.\n "
"expected = {}.".format(ret, o),
)

def test_validate_taskdef_meta(self):
"""
Input as per sm_ml above:
The share in question is test_share01, which has:
- an ID of 2 in sa_ml above
- an ID of 3 in the test_config_backup.json fixture
"""
task_type = ["snapshot"] # list as will receive appends later on
taskdef_meta = [{
"writable": True,
"visible": True,
"prefix": "snap_daily_ts01",
"share": "2",
"max_count": "4"
}]

out = [{
"writable": True,
"visible": True,
"prefix": "snap_daily_ts01",
"share": "3",
"max_count": "4"
}]

for t, m, o in zip(task_type, taskdef_meta, out):
ret = validate_taskdef_meta(self.sa_ml, m, t)
self.assertEqual(
ret,
o,
msg="Unexpected validate_taskdef_meta() result:\n "
"returned = {}.\n "
"expected = {}.".format(ret, o),
)

0 comments on commit 691f194

Please sign in to comment.