From 5bfde6ceae5af9c47c7a86a6ee1d9fb180b39b54 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Fri, 2 Oct 2020 10:22:43 +0300 Subject: otgnet stubs --- testenv/tests/validators/test_net.py | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'testenv/tests/validators/test_net.py') diff --git a/testenv/tests/validators/test_net.py b/testenv/tests/validators/test_net.py index 486154fc..d3d4703b 100644 --- a/testenv/tests/validators/test_net.py +++ b/testenv/tests/validators/test_net.py @@ -20,6 +20,7 @@ # ========================================================================== # +from typing import List from typing import Any import pytest @@ -27,8 +28,10 @@ import pytest from kvmd.validators import ValidatorError from kvmd.validators.net import valid_ip_or_host from kvmd.validators.net import valid_ip +from kvmd.validators.net import valid_net from kvmd.validators.net import valid_rfc_host from kvmd.validators.net import valid_port +from kvmd.validators.net import valid_ports_list from kvmd.validators.net import valid_mac from kvmd.validators.net import valid_ssl_ciphers @@ -86,6 +89,37 @@ def test_fail__valid_ip(arg: Any) -> None: print(valid_ip(arg)) +# ===== +@pytest.mark.parametrize("arg", [ + "127.0.0.0/24 ", + "8.8.8.8/31", + "::/16", + "::ffff:0:0:0/96", + "64:ff9b::/96", +]) +def test_ok__valid_net(arg: Any) -> None: + assert valid_net(arg) == arg.strip() + + +@pytest.mark.parametrize("arg", [ + "127.0.0.1/33", + "127.0.0.1/0", + "127.0.0.1/", + "127.0.0.1", + "8.8.8.8//31", + "ya.ru", + "1", + "1.1.1", + "1.1.1.", + ":", + "", + None, +]) +def test_fail__valid_net(arg: Any) -> None: + with pytest.raises(ValidatorError): + print(valid_net(arg)) + + # ===== @pytest.mark.parametrize("arg", [ "yandex.ru ", @@ -124,6 +158,26 @@ def test_fail__valid_port(arg: Any) -> None: print(valid_port(arg)) +# ===== +@pytest.mark.parametrize("arg, retval", [ + ("", []), + (",, , ", []), + ("0 ", [0]), + ("1,", [1]), + ("22,23", [22, 23]), + ("80,443,443,", [80, 443, 443]), + (65535, [65535]), +]) +def test_ok__valid_ports_list(arg: Any, retval: List[int]) -> None: + assert valid_ports_list(arg) == retval + + +@pytest.mark.parametrize("arg", ["test", "13,test", None, 1.1]) +def test_fail__valid_ports_list(arg: Any) -> None: + with pytest.raises(ValidatorError): + print(valid_ports_list(arg)) + + # ===== @pytest.mark.parametrize("arg", [ " 00:00:00:00:00:00 ", -- cgit v1.2.3