Socialify

Folder ..

Viewing test_ip.py
35 lines (29 loc) • 955.0 B

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from edify.library import ipv4
from edify.library import ipv6

# Generate ipv4 dictionary
ipv4_dict = {
    "192.168.0.1": True,
    "244.232.123.233": True,
    "363.232.123.233": False,
    "234.234234.234.234": False,
    "12.12.12.12.12": False,
    "0.0.0.0": True,
    "987.987.987.987": False,
}

# Generate ipv6 dictionary
ipv6_dict = {
    "2001:0db8:85a3:0000:0000:8a2e:0370:7334": True,
    "2001:db8:85a3:0:0:8a2e:370:7334": True,
    "2001:db8:85a3::8a2e:370:7334": True,
    "2001:db8:85a3:0:0:8A2E:370:7334": True,
    "2001:db8:85a3:0:0:8a2e:370:7334:": False,
    "2001:db8:85a3:0:0:8a2e:370:7334:7334": False,
    "2001:db8:85a3:0:0:8a2e:370:7334:7334:7334": False,
    "2001:db8:85a3:0:0:8a2e:370:7334:7334:7334:7334": False,
}


def test_ipv4():
    for ip, expectation in ipv4_dict.items():
        assert ipv4(ip) == expectation


def test_ipv6():
    for ip, expectation in ipv6_dict.items():
        assert ipv6(ip) == expectation