test: add node with setting ft

This commit is contained in:
eeff
2024-01-09 16:11:30 +08:00
parent dbe72f50bc
commit dd33b42a32
3 changed files with 73 additions and 2 deletions
+35
View File
@@ -24,6 +24,41 @@ class TestDriver:
assert 200 == response.status_code
assert error.NEU_ERR_SUCCESS == response.json()['error']
@description(given="running neuron", when="add app node with wrong setting", then="should fail")
@pytest.mark.parametrize('node,plugin', [('mqtt-test', config.PLUGIN_MQTT)])
def test_create_app_node_with_wrong_setting(self, node, plugin):
params = {"client-id": "neuron_aBcDeF"}
response = api.add_node(node=node, plugin=plugin, params=params)
assert 400 == response.status_code
assert error.NEU_ERR_NODE_SETTING_INVALID == response.json()['error']
response = api.get_nodes_state(node)
assert 404 == response.status_code
assert error.NEU_ERR_NODE_NOT_EXIST == response.json()['error']
@description(given="running neuron", when="add app node with correct setting", then="should success")
@pytest.mark.parametrize('node,plugin', [('mqtt-test', config.PLUGIN_MQTT)])
def test_create_app_node_with_correct_setting(self, node, plugin):
params = {
"client-id": "neuron_aBcDeF",
"qos": 0,
"format": 0,
"write-req-topic": f"/neuron/{node}/write/req",
"write-resp-topic": f"/neuron/{node}/write/resp",
"offline-cache": False,
"host": "broker.emqx.io",
"port": 1883,
"ssl": False
}
response = api.add_node(node=node, plugin=plugin, params=params)
assert 200 == response.status_code
assert error.NEU_ERR_SUCCESS == response.json()['error']
response = api.get_nodes_state(node)
assert 200 == response.status_code
assert config.NEU_NODE_STATE_RUNNING == response.json()['running']
api.del_node(node)
@description(given="app node with subscriptions", when="delete node", then="should success")
@pytest.mark.parametrize('app,plugin', [('mqtt', config.PLUGIN_MQTT)])
def test_delete_app(self, app, plugin):
+33
View File
@@ -15,6 +15,39 @@ class TestDriver:
assert 200 == response.status_code
assert error.NEU_ERR_SUCCESS == response.json()['error']
@description(given="running neuron", when="add driver node with wrong setting", then="should fail")
@pytest.mark.parametrize('node,plugin', [('modbus-01', config.PLUGIN_MODBUS_TCP)])
def test_create_node_with_wrong_setting(self, node, plugin):
params = {"connection_mode": 0}
response = api.add_node(node=node, plugin=plugin, params=params)
assert 400 == response.status_code
assert error.NEU_ERR_NODE_SETTING_INVALID == response.json()['error']
response = api.get_nodes_state(node)
assert 404 == response.status_code
assert error.NEU_ERR_NODE_NOT_EXIST == response.json()['error']
@description(given="running neuron", when="add driver node with correct setting", then="should success")
@pytest.mark.parametrize('node,plugin', [('modbus-01', config.PLUGIN_MODBUS_TCP)])
def test_create_node_with_correct_setting(self, node, plugin):
params = {
"connection_mode": 0,
"transport_mode": 0,
"interval": 20,
"host": "127.0.0.1",
"port": 502,
"timeout": 3000,
"max_retries": 2
}
response = api.add_node(node=node, plugin=plugin, params=params)
assert 200 == response.status_code
assert error.NEU_ERR_SUCCESS == response.json()['error']
response = api.get_nodes_state(node)
assert 200 == response.status_code
assert config.NEU_NODE_STATE_RUNNING == response.json()['running']
api.del_node(node)
@description(given="created node", when="get node state", then="state is init")
@pytest.mark.parametrize('node', ['modbus-tcp-1', 'modbus-rtu-1'])
def test_node_init(self, node):
+5 -2
View File
@@ -58,8 +58,11 @@ def change_log_level(json, jwt=config.default_jwt):
@gen_check
def add_node(node, plugin, jwt=config.default_jwt):
return requests.post(url=config.BASE_URL + '/api/v2/node', headers={"Authorization": jwt}, json={"name": node, "plugin": plugin})
def add_node(node, plugin, params=None, jwt=config.default_jwt):
body = {"name": node, "plugin": plugin}
if params:
body["params"] = params
return requests.post(url=config.BASE_URL + '/api/v2/node', headers={"Authorization": jwt}, json=body)
@gen_check