Add requirements and docstrings

This commit is contained in:
2022-06-25 20:39:00 +01:00
parent 51a0c28bcf
commit b8b4a8be4b
8 changed files with 25 additions and 0 deletions

View File

@ -8,18 +8,21 @@ from app.ip_info import (
def test_get_ip_information() -> None:
"""TEST: ensure that the IP information API is working correctly."""
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:
"""TEST: ensure that AS information is parsed into AS number correctly."""
as_info = "AS5089 Virgin Media Limited"
as_number = get_autonomous_system_number(as_info)
assert as_number == "AS5089"
def test_get_prefix_information() -> None:
"""TEST: ensure that advertised prefixes are retrieved correctly."""
autonomous_system = "AS109"
prefixes = get_prefix_information(autonomous_system)
assert "144.254.0.0/16" in prefixes

View File

@ -4,31 +4,37 @@ from app.query_normalisation import is_ip_address, resolve_domain_name, get_publ
def test_is_ip_address_true() -> None:
"""TEST: Verifies if a given query is a valid IPv4 address."""
test_query = "1.2.3.4"
assert is_ip_address(test_query)
def test_is_ip_address_false_ip() -> None:
"""TEST: Verifies that None is returned if an invalid IP is given."""
test_query = "256.315.16.23"
assert not is_ip_address(test_query)
def test_is_ip_address_false_fqdn() -> None:
"""TEST: Verifies that None is returned if a domain name is given."""
test_query = "google.com"
assert not is_ip_address(test_query)
def test_resolve_domain_name_true() -> None:
"""TEST: Verifies that DNS resolution is working correctly."""
domain_name = "one.one.one.one"
expected_results = ["1.1.1.1", "1.0.0.1"] # Could resolve to either IP
assert resolve_domain_name(domain_name) in expected_results
def test_resolve_domain_name_false() -> None:
"""TEST: Verifiees that a non-existent domain is not resolved."""
domain_name = "hrrijoresdo.com"
assert not resolve_domain_name(domain_name)
def test_get_public_ip() -> None:
"""TEST: Verifies that the current public IP is retrieved correctly."""
public_ip = get_public_ip()
assert is_ip_address(public_ip)