diff --git a/post-deployment/features/tango_tools.feature b/post-deployment/features/tango_tools.feature index e69e513b0476e700db752368abdce8c6d39473f5..836de112f05624801d8084e4334c994cd763d34a 100644 --- a/post-deployment/features/tango_tools.feature +++ b/post-deployment/features/tango_tools.feature @@ -10,3 +10,8 @@ Scenario: Test starting itango session Given the TANGO_HOST is defined in the environment When I call the itango3 command with parameter simple-prompt Then the return code is 0 + +Scenario: Test REST interface + Given the TANGO_HOST is defined in the environment + When I make a request with user tango-cs:tango to http://tango-base-tango-rest:8080/tango/rest/rc4/hosts/databaseds/10000/devices/sys/tg_test/1/attributes/boolean_scalar/value + Then the return code is 200 \ No newline at end of file diff --git a/post-deployment/tests/test_tango_tools.py b/post-deployment/tests/test_tango_tools.py index 109c8ca5ba453da4898d14e0c27854901e8e06e9..828c4c0a81cabf82e38c5f50da1350637d9c8d5f 100644 --- a/post-deployment/tests/test_tango_tools.py +++ b/post-deployment/tests/test_tango_tools.py @@ -4,6 +4,7 @@ import tango import logging import pytest import subprocess +import requests from pytest_bdd import given, scenario, then, when, parsers, scenarios @@ -28,11 +29,25 @@ def call_command(command, parameter): pytest.result = subprocess.run([command, "--"+parameter]) -@then('the return code is 0') -def check_return_code(): - """the result is 0.""" +@when(parsers.parse("I make a request with user {basic_auth} to {address}")) +def curl_rest(basic_auth, address): + """Request basic attribute from test device""" + pytest.result = subprocess.run(["curl", "--user", basic_auth, address]) + + url = address + auth_tuple = (basic_auth.split(':')[0], basic_auth.split(':')[1]) + + pytest.result = requests.get(url, auth=auth_tuple) + + +@then(parsers.parse('the return code is {expected_result}')) +def check_return_code(expected_result): + """the return code is as expected.""" # return_code = call_command.returncode - return_code = pytest.result.returncode - assert return_code == 0, "Function returned {}".format(pytest.result) + if expected_result == 200: + assert pytest.result.status_code == expected_result, "Curl returned {}, expected {}".format(pytest.result, expected_result) + else: + return_code = pytest.result.returncode + assert str(return_code) == str(expected_result), "Function returned {}, expected {}".format(pytest.result, expected_result) scenarios('../features/tango_tools.feature')