Skip to content

Commit cc29f01

Browse files
committed
Update TLS test with pathlib
1 parent 340fea7 commit cc29f01

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

tests/test_tls.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import os
32
import ssl
43
import subprocess
54
import sys
@@ -32,18 +31,18 @@
3231
from sanic.worker.loader import CertLoader
3332

3433

35-
current_dir = os.path.dirname(os.path.realpath(__file__))
36-
localhost_dir = os.path.join(current_dir, "certs/localhost")
37-
password_dir = os.path.join(current_dir, "certs/password")
38-
sanic_dir = os.path.join(current_dir, "certs/sanic.example")
39-
invalid_dir = os.path.join(current_dir, "certs/invalid.nonexist")
40-
localhost_cert = os.path.join(localhost_dir, "fullchain.pem")
41-
localhost_key = os.path.join(localhost_dir, "privkey.pem")
42-
sanic_cert = os.path.join(sanic_dir, "fullchain.pem")
43-
sanic_key = os.path.join(sanic_dir, "privkey.pem")
34+
current_dir = Path(__file__).parent.resolve()
35+
localhost_dir = current_dir / "certs/localhost"
36+
password_dir = current_dir / "certs/password"
37+
sanic_dir = current_dir / "certs/sanic.example"
38+
invalid_dir = current_dir / "certs/invalid.nonexist"
39+
localhost_cert = localhost_dir / "fullchain.pem"
40+
localhost_key = localhost_dir / "privkey.pem"
41+
sanic_cert = sanic_dir / "fullchain.pem"
42+
sanic_key = sanic_dir / "privkey.pem"
4443
password_dict = {
45-
"cert": os.path.join(password_dir, "fullchain.pem"),
46-
"key": os.path.join(password_dir, "privkey.pem"),
44+
"cert": password_dir / "fullchain.pem",
45+
"key": password_dir / "privkey.pem",
4746
"password": "password",
4847
"names": ["localhost"],
4948
}
@@ -383,7 +382,7 @@ async def handler(request):
383382
app.test_client.get("/test", server_kwargs={"ssl": ssl_list})
384383

385384
assert "folder expected" in str(excinfo.value)
386-
assert sanic_cert in str(excinfo.value)
385+
assert str(sanic_cert) in str(excinfo.value)
387386

388387

389388
def test_missing_cert_path(app):

0 commit comments

Comments
 (0)