From c00dcc8efd316f3a8b47846d5cb2c25843be8aa1 Mon Sep 17 00:00:00 2001 From: agames4 Date: Sun, 24 Sep 2023 22:01:19 +0200 Subject: [PATCH] added ip test added test for validation the ip so for the port forwardings --- tests/test_forms.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_forms.py b/tests/test_forms.py index 15a236f6..9092b520 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -111,3 +111,33 @@ def test_good_macs(self, mac, validatemac): validatemac(mac) except ValidationError: pytest.fail() + + +class TestAddPortForwardForm: + + @pytest.fixture(scope="class") + def validate_ip(self): + def validate_ip(ip): + form = forms.AddPortForwardForm(data={ + "ip_address": ip, "source_port": 12, "dest_port": 12, "prot": "tcp"}) + ip = form.ip_address + + forms.ip_validatior(None, ip) + return validate_ip + + @pytest.mark.parametrize( + "ip", + [ + "1.1", + "0z:80:41:ae:fd:7e", + "0+:80:41:ae:fd:7e", + "awda ssfsfwa", + "a", + "ab", + "1000", + "1.6.7." + ], + ) + def test_bad_ip(self, ip, validate_ip): + with pytest.raises(ValidationError): + validate_ip(ip) \ No newline at end of file