Skip to content

maint: improves ip_address module #239

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

Merged
merged 1 commit into from
Mar 11, 2023
Merged
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
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

::: validators.iban

<!-- ::: validators.ip_address -->
::: validators.ip_address

::: validators.length

Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 103 additions & 0 deletions tests/test_ip_address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
"""Test IP Address."""
# -*- coding: utf-8 -*-

# external
import pytest

# local
from validators import ipv4, ipv6, ValidationFailure


@pytest.mark.parametrize(
("address",),
[
("127.0.0.1",),
("123.5.77.88",),
("12.12.12.12",),
# w/ cidr
("127.0.0.1/0",),
("123.5.77.88/8",),
("12.12.12.12/32",),
],
)
def test_returns_true_on_valid_ipv4_address(address: str):
"""Test returns true on valid ipv4 address."""
assert ipv4(address)
assert not ipv6(address)


@pytest.mark.parametrize(
("address",),
[
# leading zeroes error-out from Python 3.9.5
# ("100.100.033.033",),
("900.200.100.75",),
("0127.0.0.1",),
("abc.0.0.1",),
# w/ cidr
("1.1.1.1/-1",),
("1.1.1.1/33",),
("1.1.1.1/foo",),
],
)
def test_returns_failed_validation_on_invalid_ipv4_address(address: str):
"""Test returns failed validation on invalid ipv4 address."""
assert isinstance(ipv4(address), ValidationFailure)


@pytest.mark.parametrize(
("address",),
[
("::",),
("::1",),
("1::",),
("dead:beef:0:0:0:0000:42:1",),
("abcd:ef::42:1",),
("0:0:0:0:0:ffff:1.2.3.4",),
("::192.168.30.2",),
("0000:0000:0000:0000:0000::",),
("0:a:b:c:d:e:f::",),
# w/ cidr
("::1/128",),
("::1/0",),
("dead:beef:0:0:0:0:42:1/8",),
("abcd:ef::42:1/32",),
("0:0:0:0:0:ffff:1.2.3.4/16",),
("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64",),
("::192.168.30.2/128",),
],
)
def test_returns_true_on_valid_ipv6_address(address: str):
"""Test returns true on valid ipv6 address."""
assert ipv6(address)
assert not ipv4(address)


@pytest.mark.parametrize(
("address",),
[
("abc.0.0.1",),
("abcd:1234::123::1",),
("1:2:3:4:5:6:7:8:9",),
("1:2:3:4:5:6:7:8::",),
("1:2:3:4:5:6:7::8:9",),
("abcd::1ffff",),
("1111:",),
(":8888",),
(":1.2.3.4",),
("18:05",),
(":",),
(":1:2:",),
(":1:2::",),
("::1:2::",),
("8::1:2::9",),
("02001:0000:1234:0000:0000:C1C0:ABCD:0876",),
# w/ cidr
("::1/129",),
("::1/-1",),
("::1/foo",),
],
)
def test_returns_failed_validation_on_invalid_ipv6_address(address: str):
"""Test returns failed validation on invalid ipv6 address."""
assert isinstance(ipv6(address), ValidationFailure)
25 changes: 0 additions & 25 deletions tests/test_ipv4.py

This file was deleted.

25 changes: 0 additions & 25 deletions tests/test_ipv4_cidr.py

This file was deleted.

42 changes: 0 additions & 42 deletions tests/test_ipv6.py

This file was deleted.

31 changes: 0 additions & 31 deletions tests/test_ipv6_cidr.py

This file was deleted.

4 changes: 1 addition & 3 deletions validators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .hashes import md5, sha1, sha224, sha256, sha512
from .i18n import fi_business_id, fi_ssn
from .iban import iban
from .ip_address import ipv4, ipv4_cidr, ipv6, ipv6_cidr
from .ip_address import ipv4, ipv6
from .length import length
from .mac_address import mac_address
from .slug import slug
Expand All @@ -29,9 +29,7 @@
"fi_business_id",
"fi_ssn",
"iban",
"ipv4_cidr",
"ipv4",
"ipv6_cidr",
"ipv6",
"jcb",
"length",
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy