pypilot/tests/test_ip_info.py

29 lines
937 B
Python
Raw Normal View History

2022-06-25 20:28:57 +01:00
#!/usr/bin/env python3
2022-06-25 20:50:11 +01:00
from app.ip_info import ( # pragma: no cover
2022-06-25 20:28:57 +01:00
get_ip_information,
get_autonomous_system_number,
get_prefix_information,
)
def test_get_ip_information() -> None:
2022-06-25 20:39:00 +01:00
"""TEST: ensure that the IP information API is working correctly."""
2022-06-25 20:28:57 +01:00
test_query = "1.2.3.4"
ip_info = get_ip_information(test_query)
assert ip_info.get("status") == "success" and ip_info.get("query") == test_query
def test_get_autonomous_system_number() -> None:
2022-06-25 20:39:00 +01:00
"""TEST: ensure that AS information is parsed into AS number correctly."""
2022-06-25 20:28:57 +01:00
as_info = "AS5089 Virgin Media Limited"
as_number = get_autonomous_system_number(as_info)
assert as_number == "AS5089"
def test_get_prefix_information() -> None:
2022-06-25 20:39:00 +01:00
"""TEST: ensure that advertised prefixes are retrieved correctly."""
2022-06-25 20:28:57 +01:00
autonomous_system = "AS109"
prefixes = get_prefix_information(autonomous_system)
assert "144.254.0.0/16" in prefixes