RELEASE: Version 1.0 (#3)
This commit is contained in:
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
30
tests/test_ip_info.py
Normal file
30
tests/test_ip_info.py
Normal file
@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""MODULE: Provides test cases for app/ip_info.py."""
|
||||
|
||||
from app.ip_info import ( # pragma: no cover
|
||||
get_ip_information,
|
||||
get_autonomous_system_number,
|
||||
get_prefix_information,
|
||||
)
|
||||
|
||||
|
||||
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
|
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""MODULE: Provides test cases for app/main.py."""
|
||||
|
||||
# from app.ip import is_ip_address
|
||||
|
||||
|
||||
# def test_is_ip_address_true() -> None:
|
||||
# test_query = "1.2.3.4"
|
||||
# assert is_ip_address(test_query)
|
||||
|
||||
|
||||
# def test_is_ip_address_false_ip() -> None:
|
||||
# test_query = "256.315.16.23"
|
||||
# assert not is_ip_address(test_query)
|
||||
|
||||
|
||||
# def test_is_ip_address_false_fqdn() -> None:
|
||||
# test_query = "google.com"
|
||||
# assert not is_ip_address(test_query)
|
||||
|
46
tests/test_query_normalisation.py
Normal file
46
tests/test_query_normalisation.py
Normal file
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""MODULE: Provides test cases for app/query_normalisation.py."""
|
||||
|
||||
from app.query_normalisation import ( # pragma: no cover
|
||||
is_ip_address,
|
||||
resolve_domain_name,
|
||||
get_public_ip,
|
||||
)
|
||||
|
||||
|
||||
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)
|
Reference in New Issue
Block a user