Working
This commit is contained in:
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
25
tests/test_ip_info.py
Normal file
25
tests/test_ip_info.py
Normal file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from app.ip_info import (
|
||||
get_ip_information,
|
||||
get_autonomous_system_number,
|
||||
get_prefix_information,
|
||||
)
|
||||
|
||||
|
||||
def test_get_ip_information() -> None:
|
||||
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:
|
||||
as_info = "AS5089 Virgin Media Limited"
|
||||
as_number = get_autonomous_system_number(as_info)
|
||||
assert as_number == "AS5089"
|
||||
|
||||
|
||||
def test_get_prefix_information() -> None:
|
||||
autonomous_system = "AS109"
|
||||
prefixes = get_prefix_information(autonomous_system)
|
||||
assert "144.254.0.0/16" in prefixes
|
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# 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)
|
||||
|
34
tests/test_query_normalisation.py
Normal file
34
tests/test_query_normalisation.py
Normal file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from app.query_normalisation import is_ip_address, resolve_domain_name, get_public_ip
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def test_resolve_domain_name_true() -> None:
|
||||
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:
|
||||
domain_name = "hrrijoresdo.com"
|
||||
assert not resolve_domain_name(domain_name)
|
||||
|
||||
|
||||
def test_get_public_ip() -> None:
|
||||
public_ip = get_public_ip()
|
||||
assert is_ip_address(public_ip)
|
Reference in New Issue
Block a user