Postprocess the TestAPI href returned 03/69203/2
authorCédric Ollivier <cedric.ollivier@orange.com>
Sat, 30 Nov 2019 09:44:46 +0000 (10:44 +0100)
committerCédric Ollivier <cedric.ollivier@orange.com>
Sat, 30 Nov 2019 10:03:03 +0000 (11:03 +0100)
[1] returned http://localhost:8082

[1] https://build.opnfv.org/ci/job/airship-opnfv-functest-healthcheck-latest-connection_check-run/58/console

Change-Id: Ifc0e37a97442193a77762ecc2928b100e27028cd
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
xtesting/core/testcase.py
xtesting/tests/unit/core/test_testcase.py
xtesting/tests/unit/utils/test_decorators.py

index 58de9f4..9ccd437 100644 (file)
@@ -237,13 +237,14 @@ class TestCase():
                 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")
index 80e9d8c..4ecedd9 100644 (file)
@@ -151,12 +151,13 @@ class TestCaseTesting(unittest.TestCase):
                 self.test.stop_time).strftime('%Y-%m-%d %H:%M:%S'),
             "version": "master"}
 
+    @mock.patch('re.sub')
     @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)
index c08a7ea..25acd68 100644 (file)
@@ -85,6 +85,7 @@ class DecoratorsTesting(unittest.TestCase):
         test = self._get_testcase()
         self.assertEqual(test.run(), testcase.TestCase.EX_OK)
 
+    @mock.patch('re.sub')
     @mock.patch('requests.post')
     def test_http_shema(self, *args):
         os.environ['TEST_DB_URL'] = 'http://127.0.0.1'