diff --git a/tests/ft/app/test_app.py b/tests/ft/app/test_app.py index 59c8763a..b51d0638 100644 --- a/tests/ft/app/test_app.py +++ b/tests/ft/app/test_app.py @@ -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): diff --git a/tests/ft/driver/test_driver.py b/tests/ft/driver/test_driver.py index b28bed60..da06d5e6 100644 --- a/tests/ft/driver/test_driver.py +++ b/tests/ft/driver/test_driver.py @@ -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): diff --git a/tests/ft/neuron/api.py b/tests/ft/neuron/api.py index ee9cf9a1..14a51712 100644 --- a/tests/ft/neuron/api.py +++ b/tests/ft/neuron/api.py @@ -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