Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fields: replace IPy dependency with ipaddress module #293

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions mirrors/fields.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from IPy import IP

from django import forms
from django.core import validators
from django.core.exceptions import ValidationError
from django.db import models

from ipaddress import ip_address, ip_interface

def IP(address):
if '/' not in address:
return ip_address(address)
return ip_interface(address)

class IPNetworkFormField(forms.Field):
def to_python(self, value):
Expand Down
14 changes: 13 additions & 1 deletion mirrors/tests/test_mirrorrsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@


TEST_IPV6 = "2a0b:4342:1a31:410::"
TEST_IPV6_MASK = "2a0b:4342:1a31:410::/64"
TEST_IPV4 = "8.8.8.8"
TEST_IPV4_MASK = "192.168.1.0/24"


class MirrorRsyncTest(TransactionTestCase):
Expand All @@ -20,12 +22,22 @@ def test_ipv6(self):
self.assertEqual(str(mirrorrsync), TEST_IPV6)
mirrorrsync.delete()

def test_ipv6_mask(self):
mirrorsync = MirrorRsync.objects.create(ip=TEST_IPV6_MASK, mirror=self.mirror)
self.assertEqual(str(mirrorsync), TEST_IPV6_MASK)
mirrorsync.delete()

def test_ipv4(self):
mirrorrsync = MirrorRsync.objects.create(ip=TEST_IPV4, mirror=self.mirror)
self.assertEqual(str(mirrorrsync), TEST_IPV4)
mirrorrsync.delete()

def test_ipv4_mask(self):
mirrorrsync = MirrorRsync.objects.create(ip=TEST_IPV4_MASK, mirror=self.mirror)
self.assertEqual(str(mirrorrsync), TEST_IPV4_MASK)
mirrorrsync.delete()

def test_invalid(self):
with self.assertRaises(ValueError) as e:
MirrorRsync.objects.create(ip="8.8.8.8.8", mirror=self.mirror)
self.assertIn('IPv4 Address with more than 4 bytes', str(e.exception))
self.assertIn('does not appear to be an IPv4 or IPv6 address', str(e.exception))
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
-e git+git://github.com/fredj/cssmin.git@master#egg=cssmin
Django==3.2.7
IPy==1.1
Markdown==3.3.4
bencode.py==4.0.0
django-countries==7.2.1
Expand Down