Skip to content

Commit e268fcf

Browse files
authored
Merge pull request #78 from jwdinius/resolve-issues-with-tests
Resolve issues with tests
2 parents 9daf20d + 386f8e7 commit e268fcf

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

tests/test_client_functions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ async def test_protocol_factory_bad_url():
145145
"""Test calling `pytak.protocol_factory()` with a bad URL."""
146146
test_url1: str = "udp:localhost"
147147
config: dict = {"COT_URL": test_url1}
148-
with pytest.raises(Exception):
149-
await pytak.protocol_factory(config)
148+
with pytest.warns(SyntaxWarning, match="Invalid COT_URL"):
149+
with pytest.raises(Exception):
150+
await pytak.protocol_factory(config)
150151

151152

152153
@pytest.mark.asyncio

tests/test_pref_packages.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,35 @@
2828
__copyright__ = "Copyright Sensors & Signals LLC https://www.snstac.com"
2929
__license__ = "Apache License, Version 2.0"
3030

31+
__folder__ = os.path.dirname(__file__)
3132

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

3839

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

4748

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

5455

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

6061
client_password: str = prefs.get("client_password")
6162
assert client_password
@@ -76,23 +77,23 @@ def test_load_convert_cert():
7677
assert os.path.exists(cert_pem_path)
7778
assert os.path.exists(ca_pem_path)
7879

79-
with open("tests/data/test_pk.pem", "rb+") as tpk_fd:
80+
with open(__folder__ + "/data/test_pk.pem", "rb+") as tpk_fd:
8081
test_pk = tpk_fd.read()
8182
with open(pk_pem_path, "rb+") as pk_fd:
8283
assert pk_fd.read() == test_pk
8384

84-
with open("tests/data/test_user_cert.pem", "rb+") as tc_fd:
85+
with open(__folder__ + "/data/test_user_cert.pem", "rb+") as tc_fd:
8586
test_cert = tc_fd.read()
8687
with open(cert_pem_path, "rb+") as ck_fd:
8788
assert ck_fd.read() == test_cert
8889

89-
with open("tests/data/test_ca_cert.pem", "rb+") as tc_fd:
90+
with open(__folder__ + "/data/test_ca_cert.pem", "rb+") as tc_fd:
9091
test_cert = tc_fd.read()
9192
with open(ca_pem_path, "rb+") as ck_fd:
9293
assert ck_fd.read() == test_cert
9394

9495

9596
def test_read_read_pref_package():
96-
pref_package = "tests/data/test_pref_package.zip"
97+
pref_package = __folder__ + "/data/test_pref_package.zip"
9798
prefs = pytak.client_functions.read_pref_package(pref_package)
9899
assert all(prefs)

0 commit comments

Comments
 (0)