1
0
mirror of https://github.com/peeringdb/peeringdb.git synced 2024-05-11 05:55:09 +00:00
Files
peeringdb-peeringdb/tests/test_inet.py

82 lines
2.1 KiB
Python
Raw Normal View History

2018-11-08 19:45:21 +00:00
import pytest
2019-02-22 22:23:09 +00:00
import pytest_filedata
import ipaddress
2019-12-05 16:57:52 +00:00
from peeringdb_server.inet import RdapLookup, RdapNotFoundError, renumber_ipaddress
2018-11-08 19:45:21 +00:00
def test_rdap_asn_lookup(rdap):
asn = rdap.get_asn(63311)
2020-04-15 10:49:53 +00:00
assert asn.data
2018-11-08 19:45:21 +00:00
assert asn.name
assert asn.emails
assert asn.org_name
assert asn.org_address
def test_rdap_asn_lookup_not_found(rdap):
with pytest.raises(RdapNotFoundError):
rdap.get_asn(65535)
def test_rdap_asn_lookup_not_found(rdap):
with pytest.raises(RdapNotFoundError):
rdap.get_asn(9999999)
def test_mocker(rdap):
2019-02-22 22:38:24 +00:00
with pytest_filedata.RequestsData("rdap"):
2018-11-08 19:45:21 +00:00
asn = rdap.get_asn(63311)
2019-02-22 22:23:09 +00:00
@pytest_filedata.RequestsData("rdap")
2018-11-08 19:45:21 +00:00
def test_arin0(rdap):
asn = rdap.get_asn(63311)
2019-12-05 16:57:52 +00:00
assert asn.emails == ["neteng@20c.com"]
2018-11-08 19:45:21 +00:00
def test_recurse_contacts(rdap):
asn = rdap.get_asn(3333)
assert rdap == asn._rdapc
assert len(asn.emails) > 1
assert len(rdap.history) > 1
2019-12-05 16:57:52 +00:00
def test_renumber_ipaddress():
ip4 = renumber_ipaddress(
ipaddress.ip_address("206.41.110.48"),
ipaddress.ip_network("206.41.110.0/24"),
ipaddress.ip_network("206.41.111.0/24"),
)
assert ip4.compressed == "206.41.111.48"
ip6 = renumber_ipaddress(
ipaddress.ip_address("2001:504:41:110::20"),
ipaddress.ip_network("2001:504:41:110::/64"),
ipaddress.ip_network("2001:504:41:111::/64"),
)
assert ip6.compressed == "2001:504:41:111::20"
with pytest.raises(ValueError):
renumber_ipaddress(
ipaddress.ip_address("2001:504:41:110::20"),
ipaddress.ip_network("206.41.110.0/24"),
ipaddress.ip_network("206.41.111.0/24"),
)
with pytest.raises(ValueError):
renumber_ipaddress(
ipaddress.ip_address("2001:504:41:110::20"),
ipaddress.ip_network("2001:504:41:110::/64"),
ipaddress.ip_network("206.41.111.0/24"),
)
with pytest.raises(ValueError):
renumber_ipaddress(
ipaddress.ip_address("206.41.110.48"),
ipaddress.ip_network("206.41.0.0/21"),
ipaddress.ip_network("206.41.111.0/24"),
)