summaryrefslogtreecommitdiff
path: root/smoketest/scripts
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2022-04-26 23:57:25 +0200
committerGitHub <noreply@github.com>2022-04-26 23:57:25 +0200
commit363ecfa46cdb8402ea71637717863f01b09f428b (patch)
tree979cf8c8318f42810f9ecca94446ae01d3d3f884 /smoketest/scripts
parentec3e1e43d24b823c5804ba80cdcbbfec25f7ea3a (diff)
parent846098fd8a2e2b7025f6976e26e8b21f4ebe2466 (diff)
downloadvyos-1x-363ecfa46cdb8402ea71637717863f01b09f428b.tar.gz
vyos-1x-363ecfa46cdb8402ea71637717863f01b09f428b.zip
Merge pull request #1304 from jestabro/arg-decorator-api-smoketest
smoketest: http: add decorator to suppress warnings locally
Diffstat (limited to 'smoketest/scripts')
-rw-r--r--smoketest/scripts/cli/base_vyostest_shim.py15
-rwxr-xr-xsmoketest/scripts/cli/test_service_https.py6
2 files changed, 18 insertions, 3 deletions
diff --git a/smoketest/scripts/cli/base_vyostest_shim.py b/smoketest/scripts/cli/base_vyostest_shim.py
index 1652aa0d6..7cfb53045 100644
--- a/smoketest/scripts/cli/base_vyostest_shim.py
+++ b/smoketest/scripts/cli/base_vyostest_shim.py
@@ -16,6 +16,7 @@ import os
import unittest
from time import sleep
+from typing import Type
from vyos.configsession import ConfigSession
from vyos.configsession import ConfigSessionError
@@ -85,3 +86,17 @@ class VyOSUnitTestSHIM:
print(f'\n\ncommand "{command}" returned:\n')
pprint.pprint(out)
return out
+
+# standard construction; typing suggestion: https://stackoverflow.com/a/70292317
+def ignore_warning(warning: Type[Warning]):
+ import warnings
+ from functools import wraps
+
+ def inner(f):
+ @wraps(f)
+ def wrapped(*args, **kwargs):
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore", category=warning)
+ return f(*args, **kwargs)
+ return wrapped
+ return inner
diff --git a/smoketest/scripts/cli/test_service_https.py b/smoketest/scripts/cli/test_service_https.py
index 9413d22d1..71fb3e177 100755
--- a/smoketest/scripts/cli/test_service_https.py
+++ b/smoketest/scripts/cli/test_service_https.py
@@ -15,16 +15,15 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import unittest
-import urllib3
from requests import request
+from urllib3.exceptions import InsecureRequestWarning
from base_vyostest_shim import VyOSUnitTestSHIM
+from base_vyostest_shim import ignore_warning
from vyos.util import read_file
from vyos.util import run
-urllib3.disable_warnings()
-
base_path = ['service', 'https']
pki_base = ['pki']
@@ -100,6 +99,7 @@ class TestHTTPSService(VyOSUnitTestSHIM.TestCase):
ret = run('sudo /usr/sbin/nginx -t')
self.assertEqual(ret, 0)
+ @ignore_warning(InsecureRequestWarning)
def test_api_auth(self):
vhost_id = 'example'
address = '127.0.0.1'