diff --git a/betfairlightweight/baseclient.py b/betfairlightweight/baseclient.py index 081224ea..a456b957 100644 --- a/betfairlightweight/baseclient.py +++ b/betfairlightweight/baseclient.py @@ -76,7 +76,7 @@ def __init__( self.username = username self.password = password self.app_key = app_key - self.certs = certs + self.certs = certs or "/certs" self.locale = locale self.cert_files = cert_files self.lightweight = lightweight @@ -158,10 +158,8 @@ def cert(self) -> Union[Tuple[str], str]: if self.cert_files is not None: return self.cert_files - certs = self.certs or "/certs/" - ssl_path = os.path.join(os.pardir, certs) try: - cert_path = os.listdir(ssl_path) + cert_path = os.listdir(self.certs) except FileNotFoundError as e: raise CertsError(str(e)) @@ -169,16 +167,16 @@ def cert(self) -> Union[Tuple[str], str]: for file in cert_path: ext = os.path.splitext(file)[-1] if ext in [".crt", ".cert"]: - cert = os.path.join(ssl_path, file) + cert = os.path.join(self.certs, file) elif ext == ".key": - key = os.path.join(ssl_path, file) + key = os.path.join(self.certs, file) elif ext == ".pem": - pem = os.path.join(ssl_path, file) + pem = os.path.join(self.certs, file) if cert and key: return (cert, key) if pem: return pem - msg = "Certificates not found in directory: '%s'" % ssl_path + msg = "Certificates not found in directory: '%s'" % self.certs hint = " (make sure .crt and .key pair or a single .pem is present)" raise CertsError(msg + hint) diff --git a/tests/test_baseclient.py b/tests/test_baseclient.py index f8d2a3f3..341972a8 100644 --- a/tests/test_baseclient.py +++ b/tests/test_baseclient.py @@ -14,7 +14,7 @@ def test_base_client_init(self): assert client.password == "password" assert client.app_key == "app_key" assert client.lightweight is True - assert client.certs is None + assert client.certs == "/certs" assert client.locale is None assert client._login_time is None assert client.session_token is None @@ -198,13 +198,13 @@ def test_client_certs_mocked(self, mock_listdir): [".DS_Store", "client-2048.crt", "client-2048.key"] ) assert self.client.cert == normpaths( - ["../fail/client-2048.crt", "../fail/client-2048.key"] + ["fail/client-2048.crt", "fail/client-2048.key"] ) @mock.patch("betfairlightweight.baseclient.os.listdir") def test_client_single_file_cert_mocked(self, mock_listdir): mock_listdir.return_value = normpaths([".DS_Store", "client-2048.pem"]) - assert self.client.cert == os.path.normpath("../fail/client-2048.pem") + assert self.client.cert == os.path.normpath("fail/client-2048.pem") @mock.patch("betfairlightweight.baseclient.os.listdir") def test_client_crt_key_preferred_over_pem_mocked(self, mock_listdir): @@ -212,7 +212,7 @@ def test_client_crt_key_preferred_over_pem_mocked(self, mock_listdir): [".DS_Store", "client-2048.crt", "client-2048.key", "client-2048.pem"] ) assert self.client.cert == normpaths( - ["../fail/client-2048.crt", "../fail/client-2048.key"] + ["fail/client-2048.crt", "fail/client-2048.key"] )