Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve issues with tests #78

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tests/test_client_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ async def test_protocol_factory_bad_url():
"""Test calling `pytak.protocol_factory()` with a bad URL."""
test_url1: str = "udp:localhost"
config: dict = {"COT_URL": test_url1}
with pytest.raises(Exception):
await pytak.protocol_factory(config)
with pytest.warns(SyntaxWarning, match="Invalid COT_URL"):
with pytest.raises(Exception):
await pytak.protocol_factory(config)


@pytest.mark.asyncio
Expand Down
23 changes: 12 additions & 11 deletions tests/test_pref_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,35 @@
__copyright__ = "Copyright Sensors & Signals LLC https://www.snstac.com"
__license__ = "Apache License, Version 2.0"

__folder__ = os.path.dirname(__file__)

def test_load_preferences() -> None:
"""Test loading a preferences file."""
test_pref: str = "tests/data/test_pref.pref"
prefs: dict = pytak.functions.load_preferences(test_pref, "tests/data")
test_pref: str = __folder__ + "/data/test_pref.pref"
prefs: dict = pytak.functions.load_preferences(test_pref, __folder__ + "/data")
assert all(prefs)


def test_load_connectString2url() -> None:
"""Test converting a TAK connectString to a URL"""
test_pref: str = "tests/data/test_pref.pref"
prefs: dict = pytak.functions.load_preferences(test_pref, "tests/data")
test_pref: str = __folder__ + "/data/test_pref.pref"
prefs: dict = pytak.functions.load_preferences(test_pref, __folder__ + "/data")
connect_string: str = prefs.get("connect_string")
url: str = pytak.functions.connectString2url(connect_string)
assert url == "ssl://takserver.example.com:8089"


def test_load_cert() -> None:
cert: list = pytak.crypto_functions.load_cert(
"tests/data/test_user_cert.p12", "atakatak"
__folder__ + "/data/test_user_cert.p12", "atakatak"
)
assert len(cert) == 3


def test_load_convert_cert():
"""Test converting P12 certs to a PEM certs."""
test_pref: str = "tests/data/test_pref.pref"
prefs: dict = pytak.functions.load_preferences(test_pref, "tests/data")
test_pref: str = __folder__ + "/data/test_pref.pref"
prefs: dict = pytak.functions.load_preferences(test_pref, __folder__ + "/data")

client_password: str = prefs.get("client_password")
assert client_password
Expand All @@ -76,23 +77,23 @@ def test_load_convert_cert():
assert os.path.exists(cert_pem_path)
assert os.path.exists(ca_pem_path)

with open("tests/data/test_pk.pem", "rb+") as tpk_fd:
with open(__folder__ + "/data/test_pk.pem", "rb+") as tpk_fd:
test_pk = tpk_fd.read()
with open(pk_pem_path, "rb+") as pk_fd:
assert pk_fd.read() == test_pk

with open("tests/data/test_user_cert.pem", "rb+") as tc_fd:
with open(__folder__ + "/data/test_user_cert.pem", "rb+") as tc_fd:
test_cert = tc_fd.read()
with open(cert_pem_path, "rb+") as ck_fd:
assert ck_fd.read() == test_cert

with open("tests/data/test_ca_cert.pem", "rb+") as tc_fd:
with open(__folder__ + "/data/test_ca_cert.pem", "rb+") as tc_fd:
test_cert = tc_fd.read()
with open(ca_pem_path, "rb+") as ck_fd:
assert ck_fd.read() == test_cert


def test_read_read_pref_package():
pref_package = "tests/data/test_pref_package.zip"
pref_package = __folder__ + "/data/test_pref_package.zip"
prefs = pytak.client_functions.read_pref_package(pref_package)
assert all(prefs)