mirror of
https://github.com/emqx/neuron.git
synced 2026-10-17 04:40:42 +08:00
restful: support querying nodes by multiple plugins
This commit is contained in:
@@ -94,11 +94,13 @@ def del_node(node, jwt=config.default_jwt):
|
||||
return requests.delete(url=config.BASE_URL + '/api/v2/node', headers={"Authorization": jwt}, json={"name": node})
|
||||
|
||||
|
||||
def get_nodes(type, jwt=config.default_jwt, group=""):
|
||||
if group == "":
|
||||
return requests.get(url=config.BASE_URL + '/api/v2/node', headers={"Authorization": jwt}, params={"type": type})
|
||||
else:
|
||||
return requests.get(url=config.BASE_URL + '/api/v2/node?group=' + group, headers={"Authorization": jwt}, params={"type": type})
|
||||
def get_nodes(type, jwt=config.default_jwt, group="", plugins=None):
|
||||
params = {"type": type}
|
||||
if plugins:
|
||||
params["plugin"] = ",".join(plugins)
|
||||
if group != "":
|
||||
params["group"] = group
|
||||
return requests.get(url=config.BASE_URL + '/api/v2/node', headers={"Authorization": jwt}, params=params)
|
||||
|
||||
|
||||
def get_nodes_by_tags(type, tags, jwt=config.default_jwt):
|
||||
|
||||
@@ -59,6 +59,33 @@ class TestNode:
|
||||
assert 200 == response.status_code
|
||||
assert "mqtt" == response.json()['nodes'][0]["name"]
|
||||
|
||||
@description(given="a driver node", when="get driver node by single plugin", then="get success")
|
||||
def test_get_driver_by_single_plugin(self):
|
||||
response = api.get_nodes(type=NEU_NODE_DRIVER, plugins=[PLUGIN_MODBUS_TCP])
|
||||
assert 200 == response.status_code
|
||||
assert 1 == len(response.json()['nodes'])
|
||||
assert "modbus-tcp" == response.json()['nodes'][0]["name"]
|
||||
|
||||
@description(given="driver and app nodes", when="get driver nodes by multiple plugins", then="get success")
|
||||
def test_get_driver_by_multiple_plugins(self):
|
||||
response = api.get_nodes(type=NEU_NODE_DRIVER, plugins=[PLUGIN_MODBUS_TCP, PLUGIN_MODBUS_RTU])
|
||||
assert 200 == response.status_code
|
||||
assert 1 == len(response.json()['nodes'])
|
||||
assert "modbus-tcp" == response.json()['nodes'][0]["name"]
|
||||
|
||||
@description(given="driver node and non-existent plugin", when="get driver node by plugins with unmatched", then="get success")
|
||||
def test_get_driver_by_plugin_with_unmatched(self):
|
||||
response = api.get_nodes(type=NEU_NODE_DRIVER, plugins=[PLUGIN_MODBUS_TCP, "non-existent-plugin"])
|
||||
assert 200 == response.status_code
|
||||
assert 1 == len(response.json()['nodes'])
|
||||
assert "modbus-tcp" == response.json()['nodes'][0]["name"]
|
||||
|
||||
@description(given="driver node", when="get driver node by plugins no match", then="get empty")
|
||||
def test_get_driver_by_plugin_no_match(self):
|
||||
response = api.get_nodes(type=NEU_NODE_DRIVER, plugins=[PLUGIN_MODBUS_RTU])
|
||||
assert 200 == response.status_code
|
||||
assert [] == response.json()['nodes']
|
||||
|
||||
@description(given="existent driver node", when="update the node name to empty string", then="update failed")
|
||||
def test_update_node_name_to_empty(self):
|
||||
response = api.update_node(node="modbus-tcp", new_name="")
|
||||
|
||||
Reference in New Issue
Block a user