From 56c180cf5d08173c68ffdd00edc6dfc257235e30 Mon Sep 17 00:00:00 2001
From: Adriaan de Beer <adriaan@spaceadvisory.com>
Date: Thu, 1 Oct 2020 15:43:24 +0000
Subject: [PATCH] ST-456 Request sent using run_context

---
 post-deployment/features/tango_tools.feature |  2 +-
 post-deployment/tests/test_tango_tools.py    | 11 +++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/post-deployment/features/tango_tools.feature b/post-deployment/features/tango_tools.feature
index 836de112..cac0436e 100644
--- a/post-deployment/features/tango_tools.feature
+++ b/post-deployment/features/tango_tools.feature
@@ -13,5 +13,5 @@ Scenario: Test starting itango session
 
 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
+  When I make a request with user tango-cs:tango to http://tango-base-tango-rest:8080/tango/rest/rc4/hosts/TANGO_HOST/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 828c4c0a..8591669d 100644
--- a/post-deployment/tests/test_tango_tools.py
+++ b/post-deployment/tests/test_tango_tools.py
@@ -30,22 +30,25 @@ def call_command(command, parameter):
 
 
 @when(parsers.parse("I make a request with user {basic_auth} to {address}"))
-def curl_rest(basic_auth, address):
+def curl_rest(run_context, basic_auth, address):
     """Request basic attribute from test device"""
     pytest.result = subprocess.run(["curl", "--user", basic_auth, address])
     
-    url = address
+    url = address.replace('TANGO_HOST',run_context.TANGO_HOST.split(':')[0])
+    logging.info("Request sent to {}".format(url))
+    
     auth_tuple = (basic_auth.split(':')[0], basic_auth.split(':')[1])
 
     pytest.result = requests.get(url, auth=auth_tuple)
+    logging.info("Result text: {}".format(pytest.result.text))
 
 
 @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
-    if expected_result == 200:
-        assert pytest.result.status_code == expected_result, "Curl returned {}, expected {}".format(pytest.result, expected_result)
+    if expected_result == '200':
+        assert pytest.result.status_code == int(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)
-- 
GitLab