aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric Ollivier <cedric.ollivier@orange.com>2019-11-30 13:19:08 +0000
committerGerrit Code Review <gerrit@opnfv.org>2019-11-30 13:19:08 +0000
commit2458049812df6f142a781d98d33c8270800becb4 (patch)
treed3fe05b5a45e0f988f22b7b725e3ae3af7c33795
parenta9216e7d1ede61830386b356046507cc4b0e3634 (diff)
parent3fbd1085b8fe00e05b4bd71f0e27798242d3e159 (diff)
Merge "Postprocess the TestAPI href returned" into stable/hunter
-rw-r--r--xtesting/core/testcase.py11
-rw-r--r--xtesting/tests/unit/core/test_testcase.py6
-rw-r--r--xtesting/tests/unit/utils/test_decorators.py2
3 files changed, 12 insertions, 7 deletions
diff --git a/xtesting/core/testcase.py b/xtesting/core/testcase.py
index b8d4e4de..ab82ecfc 100644
--- a/xtesting/core/testcase.py
+++ b/xtesting/core/testcase.py
@@ -237,13 +237,14 @@ class TestCase(object):
headers=self._headers)
req.raise_for_status()
if urllib.parse.urlparse(url).scheme != "file":
- res_url = req.json()["href"]
- if env.get('TEST_DB_EXT_URL'):
- res_url = res_url.replace(
- env.get('TEST_DB_URL'), env.get('TEST_DB_EXT_URL'))
+ # href must be postprocessed as OPNFV testapi is misconfigured
+ # (localhost is returned)
+ uid = re.sub(r'^.*/api/v1/results/*', '', req.json()["href"])
+ netloc = env.get('TEST_DB_EXT_URL') if env.get(
+ 'TEST_DB_EXT_URL') else env.get('TEST_DB_URL')
self.__logger.info(
"The results were successfully pushed to DB: \n\n%s\n",
- res_url)
+ os.path.join(netloc, uid))
except AssertionError:
self.__logger.exception(
"Please run test before publishing the results")
diff --git a/xtesting/tests/unit/core/test_testcase.py b/xtesting/tests/unit/core/test_testcase.py
index 80e9d8cf..f3b2d512 100644
--- a/xtesting/tests/unit/core/test_testcase.py
+++ b/xtesting/tests/unit/core/test_testcase.py
@@ -151,12 +151,14 @@ class TestCaseTesting(unittest.TestCase):
self.test.stop_time).strftime('%Y-%m-%d %H:%M:%S'),
"version": "master"}
+ @mock.patch('os.path.join', return_value='')
+ @mock.patch('re.sub', return_value='')
@mock.patch('requests.post')
- def _test_pushdb_version(self, mock_function=None, **kwargs):
+ def _test_pushdb_version(self, *args, **kwargs):
payload = self._get_data()
payload["version"] = kwargs.get("version", "unknown")
self.assertEqual(self.test.push_to_db(), testcase.TestCase.EX_OK)
- mock_function.assert_called_once_with(
+ args[0].assert_called_once_with(
os.environ['TEST_DB_URL'],
data=json.dumps(payload, sort_keys=True),
headers=self._headers)
diff --git a/xtesting/tests/unit/utils/test_decorators.py b/xtesting/tests/unit/utils/test_decorators.py
index c08a7ea3..2810df15 100644
--- a/xtesting/tests/unit/utils/test_decorators.py
+++ b/xtesting/tests/unit/utils/test_decorators.py
@@ -85,6 +85,8 @@ class DecoratorsTesting(unittest.TestCase):
test = self._get_testcase()
self.assertEqual(test.run(), testcase.TestCase.EX_OK)
+ @mock.patch('os.path.join')
+ @mock.patch('re.sub')
@mock.patch('requests.post')
def test_http_shema(self, *args):
os.environ['TEST_DB_URL'] = 'http://127.0.0.1'