Get schema Test

This commit is contained in:
Amin Ben Romdhane 2024-02-19 12:05:10 +01:00
parent ff8deafeae
commit 7c81a706e9
5 changed files with 458 additions and 6 deletions

View file

@ -27,6 +27,9 @@ exec_cmd ubus wait_for bbfdm
# Test ubus bbfdm 'get' method
./test/python-test-cases/python/validate_ubus_get_method.py test/python-test-cases/json/ubus_get_method.json
# Test ubus bbfdm 'instances' method
./test/python-test-cases/python/validate_ubus_schema_method.py test/python-test-cases/json/ubus_schema_method.json
supervisorctl stop all
supervisorctl status

View file

@ -1,8 +1,26 @@
{
"object": "bbfdm",
"test-cases": [
"get": [
{
"description": "Test-Case-1: Get Parameter with correct path",
"description": "Get Value for '' path (proto usp)",
"input": {
"path": "",
"optional": {"format": "raw", "proto": "usp"}
},
"expected_error": 0,
"output": {}
},
{
"description": "Get Value for '' path (proto cwmp)",
"input": {
"path": "",
"optional": {"format": "raw", "proto": "cwmp"}
},
"expected_error": 0,
"output": {}
},
{
"description": "Get Value for 'Device.DeviceInfo.Manufacturer' path (proto usp)",
"input": {
"path": "Device.DeviceInfo.Manufacturer",
"optional": {"format": "raw", "proto": "usp"}
@ -19,13 +37,55 @@
}
},
{
"description": "Test-Case-2: Get Parameter with wrong path",
"description": "Get Value for 'Device.DeviceInfo.Manufacturer' path (proto cwmp)",
"input": {
"path": "Device.DeviceInfo.Manufacturer",
"optional": {"format": "raw", "proto": "cwmp"}
},
"expected_error": 0,
"output": {
"results": [
{
"path": "Device.DeviceInfo.Manufacturer",
"data": "iopsys",
"type": "xsd:string"
}
]
}
},
{
"description": "Get Value for 'Device.DeviceInfo.Manufacture' path (proto usp)",
"input": {
"path": "Device.DeviceInfo.Manufacture",
"optional": {"format": "raw", "proto": "usp"}
},
"expected_error": 7026,
"output": {}
"output": {
"results": [
{
"path": "Device.DeviceInfo.Manufacture",
"fault": 7026,
"fault_msg": "Path is not present in the data model schema"
}
]
}
},
{
"description": "Get Value for 'Device.DeviceInfo.Manufacture' path (proto cwmp)",
"input": {
"path": "Device.DeviceInfo.Manufacture",
"optional": {"format": "raw", "proto": "cwmp"}
},
"expected_error": 9005,
"output": {
"results": [
{
"path": "Device.DeviceInfo.Manufacture",
"fault": 9005,
"fault_msg": "Invalid parameter name"
}
]
}
}
]
}

View file

@ -0,0 +1,302 @@
{
"object": "bbfdm",
"schema": [
{
"description": "Schema for empty path with first_level=true (proto usp)",
"input": {
"path": "",
"first_level": true,
"optional": {"proto": "usp"}
},
"expected_error": 7026,
"output": {
"results": []
}
},
{
"description": "Schema for empty path with first_level=false (proto usp)",
"input": {
"path": "",
"first_level": false,
"optional": {"proto": "usp"}
},
"expected_error": 7026,
"output": {
"results": []
}
},
{
"description": "Schema for 'Device.' path with first_level=true (proto usp)",
"input": {
"path": "Device.",
"first_level": true,
"optional": {"proto": "usp"}
},
"expected_error": 0,
"output": {}
},
{
"description": "Schema for 'Device.' path with first_level=false (proto usp)",
"input": {
"path": "Device.",
"first_level": false,
"optional": {"proto": "usp"}
},
"expected_error": 0,
"output": {}
},
{
"description": "Schema for 'Device.DeviceInfo.' path with first_level=true (proto usp)",
"input": {
"path": "Device.DeviceInfo.",
"first_level": true,
"optional": {"proto": "usp"}
},
"expected_error": 0,
"output": {}
},
{
"description": "Schema for 'Device.DeviceInfo.' path with first_level=false (proto usp)",
"input": {
"path": "Device.DeviceInfo.",
"first_level": false,
"optional": {"proto": "usp"}
},
"expected_error": 0,
"output": {}
},
{
"description": "Schema for 'Device.DeviceInfo.Manufacturer' path with first_level=true (proto usp)",
"input": {
"path": "Device.DeviceInfo.Manufacturer",
"first_level": true,
"optional": {"proto": "usp"}
},
"expected_error": 7026,
"output": {
"results": []
}
},
{
"description": "Schema for 'Device.DeviceInfo.Manufacturer' path with first_level=false (proto usp)",
"input": {
"path": "Device.DeviceInfo.Manufacturer",
"first_level": false,
"optional": {"proto": "usp"}
},
"expected_error": 7026,
"output": {
"results": []
}
},
{
"description": "Schema for 'Device.DeviceInfo.' & 'Device.Time.' & 'Device.WiFi.Radio.' path with first_level=true (proto usp)",
"input": {
"path": "Device.DeviceInfo.",
"paths": ["Device.Time.", "Device.WiFi.Radio."],
"first_level": true,
"optional": {"proto": "usp"}
},
"expected_error": 0,
"output": {}
},
{
"description": "Schema for 'Device.DeviceInfo.' & 'Device.Time.' & 'Device.WiFi.Radio.' path with first_level=false (proto usp)",
"input": {
"path": "Device.DeviceInfo.",
"paths": ["Device.Time.", "Device.WiFi.Radio."],
"first_level": false,
"optional": {"proto": "usp"}
},
"expected_error": 0,
"output": {}
},
{
"description": "Schema for 'Device.Time.' & 'Device.WiFi.Radio.' path with first_level=true (proto usp)",
"input": {
"paths": ["Device.Time.", "Device.WiFi.Radio."],
"first_level": true,
"optional": {"proto": "usp"}
},
"expected_error": 0,
"output": {}
},
{
"description": "Schema for 'Device.Time.' & 'Device.WiFi.Radio.' path with first_level=false (proto usp)",
"input": {
"paths": ["Device.Time.", "Device.WiFi.Radio."],
"first_level": false,
"optional": {"proto": "usp"}
},
"expected_error": 0,
"output": {}
},
{
"description": "Schema for 'Device.DeviceIn' path with first_level=true (proto usp)",
"input": {
"path": "Device.DeviceIn",
"first_level": true,
"optional": {"proto": "usp"}
},
"expected_error": 7026,
"output": {
"results": []
}
},
{
"description": "Schema for 'Device.DeviceInfo.' path with first_level=false (proto usp)",
"input": {
"path": "Device.DeviceIn",
"first_level": false,
"optional": {"proto": "usp"}
},
"expected_error": 7026,
"output": {
"results": []
}
},
{
"description": "Get Name for empty path with first_level=true (proto cwmp)",
"input": {
"path": "",
"first_level": true,
"optional": {"proto": "cwmp"}
},
"expected_error": 0,
"output": {
"results": [
{
"path": "Device.",
"data": "0",
"type": "xsd:object"
}
]
}
},
{
"description": "Get Name for empty path with first_level=false (proto cwmp)",
"input": {
"path": "",
"first_level": false,
"optional": {"proto": "cwmp"}
},
"expected_error": 0,
"output": {}
},
{
"description": "Get Name for 'Device.' with first_level=true (proto cwmp)",
"input": {
"path": "Device.",
"first_level": true,
"optional": {"proto": "cwmp"}
},
"expected_error": 0,
"output": {}
},
{
"description": "Get Name for 'Device.' path with first_level=false (proto cwmp)",
"input": {
"path": "Device.",
"first_level": false,
"optional": {"proto": "cwmp"}
},
"expected_error": 0,
"output": {}
},
{
"description": "Get Name for 'Device.DeviceInfo.' with first_level=true (proto cwmp)",
"input": {
"path": "Device.DeviceInfo.",
"first_level": true,
"optional": {"proto": "cwmp"}
},
"expected_error": 0,
"output": {}
},
{
"description": "Get Name for 'Device.DeviceInfo.' path with first_level=false (proto cwmp)",
"input": {
"path": "Device.DeviceInfo.",
"first_level": false,
"optional": {"proto": "cwmp"}
},
"expected_error": 0,
"output": {}
},
{
"description": "Get Name for 'Device.DeviceInfo.Manufacturer' with first_level=true (proto cwmp)",
"input": {
"path": "Device.DeviceInfo.Manufacturer",
"first_level": true,
"optional": {"proto": "cwmp"}
},
"expected_error": 9003,
"output": {
"results": [
{
"path": "Device.DeviceInfo.Manufacturer",
"fault": 9003,
"fault_msg": "Invalid arguments"
}
]
}
},
{
"description": "Get Name for 'Device.DeviceInfo.Manufacturer' path with first_level=false (proto cwmp)",
"input": {
"path": "Device.DeviceInfo.Manufacturer",
"first_level": false,
"optional": {"proto": "cwmp"}
},
"expected_error": 0,
"output": {
"results": [
{
"path": "Device.DeviceInfo.Manufacturer",
"data": "0",
"type": "xsd:string"
}
]
}
},
{
"description": "Get Name for 'Device.DeviceInfo.Manuf' with first_level=true (proto cwmp)",
"input": {
"path": "Device.DeviceInfo.Manuf",
"first_level": true,
"optional": {"proto": "cwmp"}
},
"expected_error": 9005,
"output": {
"results": [
{
"path": "Device.DeviceInfo.Manuf",
"fault": 9005,
"fault_msg": "Invalid parameter name"
}
]
}
},
{
"description": "Get Name for 'Device.DeviceInfo.Manufac' path with first_level=false (proto cwmp)",
"input": {
"path": "Device.DeviceInfo.Manufac",
"first_level": false,
"optional": {"proto": "cwmp"}
},
"expected_error": 9005,
"output": {
"results": [
{
"path": "Device.DeviceInfo.Manufac",
"fault": 9005,
"fault_msg": "Invalid parameter name"
}
]
}
}
]
}

View file

@ -30,7 +30,14 @@ def run_test(args):
print("FAIL: " + args.description)
return
if "fault" in out["results"][0] and out["results"][0]["fault"] != args.expected_error:
res_len = len(out["results"])
fault = out["results"][0]["fault"] if res_len and "fault" in out["results"][0] else 0
if fault != args.expected_error:
print("FAIL: " + args.description)
return
if args.expected_error == 0 and res_len == 0:
print("FAIL: " + args.description)
return
@ -55,7 +62,7 @@ if __name__ == "__main__":
with open(test_arguments_file, 'r') as f:
test_arguments_data = json.load(f)
service_name = test_arguments_data.get("object", "bbfdm")
args_list = [TestArguments(**test_case, service=service_name) for test_case in test_arguments_data["test-cases"]]
args_list = [TestArguments(**test_case, service=service_name) for test_case in test_arguments_data["get"]]
except FileNotFoundError:
print("File not found:", test_arguments_file)
sys.exit(1)

View file

@ -0,0 +1,80 @@
#!/usr/bin/python3
import sys
import ubus
import json
class TestArguments:
"""
Class to hold test arguments.
"""
def __init__(self, description, service, input, expected_error, output):
self.description = description
self.service = service
self.input = input
self.expected_error = expected_error
self.output = output
def run_test(args):
"""
Run a single test.
"""
print("Running: " + args.description)
out = ubus.call(args.service, "schema", args.input)
if isinstance(out, list) and out:
out = out[0]
else:
print("FAIL: " + args.description)
return
res_len = len(out["results"])
fault = out["results"][0]["fault"] if res_len and "fault" in out["results"][0] else 0
if fault != args.expected_error:
print("FAIL: " + args.description)
return
if args.expected_error == 0 and res_len == 0:
print("FAIL: " + args.description)
return
# Check if output matches expected output
if args.output != {}:
print(out)
if out == args.output:
print("PASS: " + args.description)
else:
print("FAIL: " + args.description)
else:
print("PASS: " + args.description)
if __name__ == "__main__":
# Check for correct command line arguments
if len(sys.argv) != 2:
print("Usage: {} <test_arguments_json>".format(sys.argv[0]))
sys.exit(1)
test_arguments_file = sys.argv[1]
try:
with open(test_arguments_file, 'r') as f:
test_arguments_data = json.load(f)
service_name = test_arguments_data.get("object", "bbfdm")
args_list = [TestArguments(**test_case, service=service_name) for test_case in test_arguments_data["schema"]]
except FileNotFoundError:
print("File not found:", test_arguments_file)
sys.exit(1)
except json.JSONDecodeError as e:
print("Error parsing JSON:", e)
sys.exit(1)
ubus.connect()
# Run tests for each set of arguments
for args in args_list:
run_test(args)
ubus.disconnect()