mirror of
				https://github.com/peeringdb/peeringdb.git
				synced 2024-05-11 05:55:09 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			87 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			87 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import pytest
 | |
| import pytest_filedata
 | |
| import ipaddress
 | |
| 
 | |
| from peeringdb_server.inet import (
 | |
|     RdapLookup,
 | |
|     RdapNotFoundError,
 | |
|     renumber_ipaddress
 | |
| )
 | |
| 
 | |
| 
 | |
| def test_rdap_asn_lookup(rdap):
 | |
|     asn = rdap.get_asn(63311)
 | |
|     assert asn.raw
 | |
|     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):
 | |
|     with pytest_filedata.RequestsData("rdap"):
 | |
|         asn = rdap.get_asn(63311)
 | |
| 
 | |
| 
 | |
| @pytest_filedata.RequestsData("rdap")
 | |
| def test_arin0(rdap):
 | |
|     asn = rdap.get_asn(63311)
 | |
|     assert asn.emails == ['neteng@20c.com']
 | |
| 
 | |
| 
 | |
| def test_recurse_contacts(rdap):
 | |
|     asn = rdap.get_asn(3333)
 | |
|     assert rdap == asn._rdapc
 | |
|     assert len(asn.emails) > 1
 | |
|     assert len(rdap.history) > len(asn.emails)
 | |
| 
 | |
| def test_renumber_ipaddress():
 | |
|     ip4 = renumber_ipaddress(
 | |
|         ipaddress.ip_address(u"206.41.110.48"),
 | |
|         ipaddress.ip_network(u"206.41.110.0/24"),
 | |
|         ipaddress.ip_network(u"206.41.111.0/24"),
 | |
|     )
 | |
| 
 | |
|     assert ip4.compressed == u"206.41.111.48"
 | |
| 
 | |
|     ip6 = renumber_ipaddress(
 | |
|         ipaddress.ip_address(u"2001:504:41:110::20"),
 | |
|         ipaddress.ip_network(u"2001:504:41:110::/64"),
 | |
|         ipaddress.ip_network(u"2001:504:41:111::/64"),
 | |
|     )
 | |
| 
 | |
|     assert ip6.compressed == u"2001:504:41:111::20"
 | |
| 
 | |
|     with pytest.raises(ValueError):
 | |
|         renumber_ipaddress(
 | |
|             ipaddress.ip_address(u"2001:504:41:110::20"),
 | |
|             ipaddress.ip_network(u"206.41.110.0/24"),
 | |
|             ipaddress.ip_network(u"206.41.111.0/24"),
 | |
|         )
 | |
| 
 | |
|     with pytest.raises(ValueError):
 | |
|         renumber_ipaddress(
 | |
|             ipaddress.ip_address(u"2001:504:41:110::20"),
 | |
|             ipaddress.ip_network(u"2001:504:41:110::/64"),
 | |
|             ipaddress.ip_network(u"206.41.111.0/24"),
 | |
|         )
 | |
| 
 | |
|     with pytest.raises(ValueError):
 | |
|         renumber_ipaddress(
 | |
|             ipaddress.ip_address(u"206.41.110.48"),
 | |
|             ipaddress.ip_network(u"206.41.0.0/21"),
 | |
|             ipaddress.ip_network(u"206.41.111.0/24"),
 | |
|         )
 | |
| 
 | |
| 
 |