|
1 | 1 | import warnings |
2 | 2 | import django |
3 | | -from django import VERSION |
| 3 | +from django import VERSION as DJANGO_VERSION |
4 | 4 | from django.core.exceptions import ValidationError |
5 | 5 | from ipaddress import ( |
6 | 6 | IPv4Address, |
|
14 | 14 | ip_network, |
15 | 15 | ) |
16 | 16 | from netaddr import EUI |
| 17 | +import sys |
| 18 | + |
17 | 19 |
|
18 | 20 | from django.db import IntegrityError |
19 | 21 | from django.db.models import F |
|
40 | 42 | ) |
41 | 43 |
|
42 | 44 |
|
| 45 | +PYTHON_VERSION = (sys.version_info.major, sys.version_info.minor) |
| 46 | + |
| 47 | + |
43 | 48 | class BaseSqlTestCase(object): |
44 | 49 | select = u'SELECT "table"."id", "table"."field" FROM "table" ' |
45 | 50 |
|
@@ -144,7 +149,7 @@ def test_iexact_lookup(self): |
144 | 149 | ) |
145 | 150 |
|
146 | 151 | def test_search_lookup_fails(self): |
147 | | - if VERSION >= (2, 0): |
| 152 | + if DJANGO_VERSION >= (2, 0): |
148 | 153 | expected = FieldError |
149 | 154 | else: |
150 | 155 | expected = NotImplementedError |
@@ -483,6 +488,12 @@ def test_net_contained_network(self): |
483 | 488 | self.assertEqual(query.count(), 1) |
484 | 489 | self.assertEqual(query[0].field, ip_address('10.1.2.1')) |
485 | 490 |
|
| 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 | + |
486 | 497 |
|
487 | 498 | class TestCidrField(BaseCidrFieldTestCase, TestCase): |
488 | 499 | def setUp(self): |
@@ -779,7 +790,7 @@ def test_aggregate_network(self): |
779 | 790 |
|
780 | 791 | class TestConstraints(TestCase): |
781 | 792 |
|
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') |
783 | 794 | def test_check_constraint(self): |
784 | 795 | from test.models import ConstraintModel |
785 | 796 |
|
|
0 commit comments