Skip to content

Commit efc5fa8

Browse files
committed
Add test for IPv6 scopes
1 parent f7529f2 commit efc5fa8

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

test/tests/test_sql_fields.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import warnings
22
import django
3-
from django import VERSION
3+
from django import VERSION as DJANGO_VERSION
44
from django.core.exceptions import ValidationError
55
from ipaddress import (
66
IPv4Address,
@@ -14,6 +14,8 @@
1414
ip_network,
1515
)
1616
from netaddr import EUI
17+
import sys
18+
1719

1820
from django.db import IntegrityError
1921
from django.db.models import F
@@ -40,6 +42,9 @@
4042
)
4143

4244

45+
PYTHON_VERSION = (sys.version_info.major, sys.version_info.minor)
46+
47+
4348
class BaseSqlTestCase(object):
4449
select = u'SELECT "table"."id", "table"."field" FROM "table" '
4550

@@ -144,7 +149,7 @@ def test_iexact_lookup(self):
144149
)
145150

146151
def test_search_lookup_fails(self):
147-
if VERSION >= (2, 0):
152+
if DJANGO_VERSION >= (2, 0):
148153
expected = FieldError
149154
else:
150155
expected = NotImplementedError
@@ -483,6 +488,12 @@ def test_net_contained_network(self):
483488
self.assertEqual(query.count(), 1)
484489
self.assertEqual(query[0].field, ip_address('10.1.2.1'))
485490

491+
@skipIf(PYTHON_VERSION < (3, 9), 'Scopes were added in Python 3.9')
492+
def test_ipv6_strip_scope(self):
493+
instance = self.model.objects.create(field='2001:db8::1%foo')
494+
instance = self.model.objects.get(pk=instance.pk)
495+
self.assertEqual(str(instance.field), '2001:db8::1')
496+
486497

487498
class TestCidrField(BaseCidrFieldTestCase, TestCase):
488499
def setUp(self):
@@ -779,7 +790,7 @@ def test_aggregate_network(self):
779790

780791
class TestConstraints(TestCase):
781792

782-
@skipIf(VERSION < (4, 1), 'Check constraint validation is supported from django 4.1 onwards')
793+
@skipIf(DJANGO_VERSION < (4, 1), 'Check constraint validation is supported from django 4.1 onwards')
783794
def test_check_constraint(self):
784795
from test.models import ConstraintModel
785796

0 commit comments

Comments
 (0)