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

Use builtin importlib.resources. #66

Merged
merged 2 commits into from
Apr 15, 2024
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
9 changes: 4 additions & 5 deletions bankid/certutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
import subprocess
from typing import Tuple

import importlib_resources
import pathlib
import importlib.resources

from bankid.certs import get_test_cert_p12
from bankid.exceptions import BankIDError

_TEST_CERT_PASSWORD = "qwerty123"


def resolve_cert_path(file: str) -> str:
ref = importlib_resources.files("bankid.certs") / file
with importlib_resources.as_file(ref) as path:
return str(path)
def resolve_cert_path(file: str) -> pathlib.Path:
return importlib.resources.files("bankid.certs").joinpath(file)


def create_bankid_test_server_cert_and_key(destination_path: str) -> Tuple[str]:
Expand Down
1 change: 0 additions & 1 deletion docs/get_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Dependencies
PyBankID makes use of the following external packages:

* `httpx <https://www.python-httpx.org/>`_
* `importlib-resources >= 5.12.0 <https://importlib-resources.readthedocs.io/>`_

Using the client
----------------
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
httpx
importlib-resources>=5.12.0
5 changes: 3 additions & 2 deletions tests/test_asyncclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
async def test_authentication_and_collect(cert_and_key, ip_address):
"""Authenticate call and then collect with the returned orderRef UUID."""
c = BankIDAsyncClient(certificates=cert_and_key, test_server=True)
assert "appapi2.test.bankid.com.pem" in c.verify_cert
out = await c.authenticate(ip_address)
assert "appapi2.test.bankid.com.pem" in str(c.verify_cert)
out = await c.authenticate(ip_address_async)

assert isinstance(out, dict)
# UUID.__init__ performs the UUID compliance assertion.
uuid.UUID(out.get("orderRef"), version=4)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_syncclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_authentication_and_collect(cert_and_key, ip_address, random_personal_nu
"""Authenticate call and then collect with the returned orderRef UUID."""

c = BankIDClient(certificates=cert_and_key, test_server=True)
assert "appapi2.test.bankid.com.pem" in c.verify_cert
assert "appapi2.test.bankid.com.pem" in str(c.verify_cert)
out = c.authenticate(ip_address, random_personal_number)
assert isinstance(out, dict)
# UUID.__init__ performs the UUID compliance assertion.
Expand Down Expand Up @@ -139,4 +139,4 @@ def test_cancel_with_invalid_uuid(cert_and_key):
def test_correct_prod_server_urls(cert_and_key, test_server, endpoint):
c = BankIDClient(certificates=cert_and_key, test_server=test_server)
assert c.api_url == "https://{0}/rp/v6.0/".format(endpoint)
assert "{0}.pem".format(endpoint) in c.verify_cert
assert "{0}.pem".format(endpoint) in str(c.verify_cert)
Loading