Skip to content

Commit

Permalink
Async client using httpx (#55)
Browse files Browse the repository at this point in the history
* Test against Python 3.12

* Install setuptools after testing

* Swap out pkg_resources for importlib

* Downgrade importlib-resources to 5.12.0

* Always use compat package

* Read required packages in setup.py from requirements.txt

* Drop unused six and update docs

* Async client

* Tidy up async wrapper

* Install requirements-dev.txt on CI

* Add two more packages to requirements-dev.txt from CI

* Update bankid/jsonclient.py

Co-authored-by: David Svenson <davidsvenson@outlook.com>

* Update bankid/jsonclient.py

Co-authored-by: David Svenson <davidsvenson@outlook.com>

* Drop unused TypeVar

* Update bankid/jsonclient.py

Co-authored-by: David Svenson <davidsvenson@outlook.com>

---------

Co-authored-by: David Svenson <davidsvenson@outlook.com>
  • Loading branch information
tiwilliam and Majsvaffla committed Dec 15, 2023
1 parent cab407b commit b742236
Show file tree
Hide file tree
Showing 28 changed files with 647 additions and 457 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.7, 3.8, 3.9, '3.10', '3.11']
python-version: [3.7, 3.8, 3.9, '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3

Expand All @@ -27,14 +27,11 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Upgrade pip. setuptools and wheel
run: python -m pip install --upgrade pip setuptools wheel

- name: Install dependencies
run: pip install -r requirements.txt

- name: Install development dependencies
run: pip install pytest pytest-cov mock flake8
run: pip install -r requirements-dev.txt

- name: Lint with flake8
run: |
Expand All @@ -47,6 +44,9 @@ jobs:
run: |
pytest tests --junitxml=junit/test-results-${{ matrix.os }}-${{ matrix.python-version }}.xml --cov=bankid --cov-report=xml --cov-report=html
- name: Upgrade pip. setuptools and wheel
run: python -m pip install --upgrade pip setuptools wheel

- name: Upload pytest test results
uses: actions/upload-artifact@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var/
*.egg-info/
.installed.cfg
*.egg
.venv
.python-version

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.flake8",
"charliermarsh.ruff"
]
}
33 changes: 33 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"editor.tabSize": 2,
"editor.insertSpaces": true,
"python.analysis.autoImportCompletions": true,
"python.analysis.diagnosticMode": "workspace",
"python.analysis.indexing": true,
"files.insertFinalNewline": true,
"files.exclude": {
".pytest_cache": true,
"**/__pycache__": true,
".venv": true,
"build": true,
"dist": true,
"*.egg-info": true,
},
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
},
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"flake8.importStrategy": "fromEnvironment",
"flake8.args": [
"--max-complexity=10",
"--max-line-length=127",
"--select=E9,F63,F7,F82",
],
}
8 changes: 4 additions & 4 deletions bankid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
:mod:`bankid`
Expand All @@ -19,13 +18,14 @@
"""

from .jsonclient import BankIDJSONClient
from .certutils import create_bankid_test_server_cert_and_key
from . import exceptions
from .__version__ import __version__, version
import bankid.exceptions
from .certutils import create_bankid_test_server_cert_and_key
from .jsonclient import AsyncBankIDJSONClient, BankIDJSONClient

__all__ = [
"BankIDJSONClient",
"AsyncBankIDJSONClient",
"exceptions",
"create_bankid_test_server_cert_and_key",
"__version__",
Expand Down
1 change: 0 additions & 1 deletion bankid/__version__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Version info
Expand Down
20 changes: 12 additions & 8 deletions bankid/certutils.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
:mod:`bankid.certutils` -- Certificate Utilities
================================================
Created 2016-04-10 by hbldh
.. moduleauthor:: hbldh <henrik.blidh@nedomkull.com>
"""

import os
import subprocess
from typing import Tuple

import importlib_resources

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

_TEST_CERT_PASSWORD = "qwerty123"


def create_bankid_test_server_cert_and_key(destination_path):
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 create_bankid_test_server_cert_and_key(destination_path: str) -> Tuple[str]:
"""Split the bundled test certificate into certificate and key parts and save them
as separate files, stored in PEM format.
Expand All @@ -31,9 +37,7 @@ def create_bankid_test_server_cert_and_key(destination_path):
"""
if os.getenv("TEST_CERT_FILE"):
certificate, key = split_certificate(
os.getenv("TEST_CERT_FILE"), destination_path, password=_TEST_CERT_PASSWORD
)
certificate, key = split_certificate(os.getenv("TEST_CERT_FILE"), destination_path, password=_TEST_CERT_PASSWORD)

else:
# Fetch testP12 certificate path
Expand Down
11 changes: 0 additions & 11 deletions bankid/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
:mod:`bankid.exceptions` -- PyBankID Exceptions
===============================================
.. moduleauthor:: hbldh <henrik.blidh@nedomkull.com>
Created on 2014-09-10, 08:29
"""


def get_json_error_class(response):
data = response.json()
Expand Down
Loading

0 comments on commit b742236

Please sign in to comment.