From 1d883e08252e2e9f1f03071a7ceac8f139fcbc89 Mon Sep 17 00:00:00 2001 From: Andrea Grandi Date: Sun, 22 Mar 2015 16:46:16 +0000 Subject: [PATCH] Add two more tests for IPAddressField, checking the IPv4 and IPv6 protocols separately --- tests/test_fields.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/test_fields.py b/tests/test_fields.py index df25aba81..f6ccfffe0 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -539,6 +539,38 @@ class TestIPAddressField(FieldValues): field = serializers.IPAddressField() +class TestIPv4AddressField(FieldValues): + """ + Valid and invalid values for `IPAddressField` + """ + valid_inputs = { + '127.0.0.1': '127.0.0.1', + '192.168.33.255': '192.168.33.255', + } + invalid_inputs = { + '127001': ['Enter a valid IPv4 address.'], + '127.122.111.2231': ['Enter a valid IPv4 address.'], + } + outputs = {} + field = serializers.IPAddressField(protocol='IPv4') + + +class TestIPv6AddressField(FieldValues): + """ + Valid and invalid values for `IPAddressField` + """ + valid_inputs = { + '2001:0db8:85a3:0042:1000:8a2e:0370:7334': '2001:db8:85a3:42:1000:8a2e:370:7334', + '2001:cdba:0:0:0:0:3257:9652': '2001:cdba::3257:9652', + '2001:cdba::3257:9652': '2001:cdba::3257:9652' + } + invalid_inputs = { + '2001:::9652': ['Enter a valid IPv4 or IPv6 address.'], + '2001:0db8:85a3:0042:1000:8a2e:0370:73341': ['Enter a valid IPv4 or IPv6 address.'], + } + outputs = {} + field = serializers.IPAddressField(protocol='IPv6') + # Number types... class TestIntegerField(FieldValues):