Skip to content

Commit

Permalink
Skip authenticated tests if no passkey
Browse files Browse the repository at this point in the history
  • Loading branch information
eidorb committed Feb 16, 2025
1 parent 8ac3a91 commit 8946b53
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
# Run tests.
curl -LsSf https://astral.sh/uv/install.sh | sh
uv python pin ${{ matrix.python-version }}
uv run pytest -v -k 'not test_ubank_client'
uv run -m pytest -v
publish:
needs: test
# Only publish if releasing.
Expand Down
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,7 @@ Installed 17 packages in 22ms
Run all tests:

```shell
uv run pytest -v
```

`test_ubank_client` requires a valid `passkey.cbor` file for testing ubank
authentication.
Skip this test using the following expression:

```shell
uv run pytest -v -k 'not test_ubank_client'
uv run -m pytest -v
```


Expand Down
30 changes: 12 additions & 18 deletions test_ubank.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from base64 import urlsafe_b64encode
from datetime import date

import pytest
from cryptography.hazmat.primitives import serialization

from ubank import (
Api,
Client,
Passkey,
TransactionsSearchBody,
__version__,
Expand Down Expand Up @@ -184,30 +184,24 @@ def test_passkey_serialization(tmp_path):
assert deserialized_passkey.sign_count == passkey.sign_count


def test_ubank_client():
"""Tests Client using passkey loaded from file."""
def test_authenticated():
"""Client and API tests are authenticated using passkey loaded from file."""
# Load passkey from file.
with open("passkey.cbor", "rb") as f:
passkey = Passkey.load(f)
try:
with open("passkey.cbor", "rb") as f:
passkey = Passkey.load(f)
except FileNotFoundError as e:
pytest.skip("No passkey file")

# Authenticate to ubank with passkey.
with Client(passkey=passkey) as client:
with Api(passkey) as api:
assert (
client.get("accounts").json()["linkedBanks"][0]["accounts"][0]["balance"][
"currency"
]
api.client.get("accounts").json()["linkedBanks"][0]["accounts"][0][
"balance"
]["currency"]
== "AUD"
)


def test_api():
"""Tests API client methods and model validation."""
# Load passkey from file.
with open("passkey.cbor", "rb") as f:
passkey = Passkey.load(f)

# Authenticate to ubank with passkey.
with Api(passkey=passkey) as api:
customer = api.get_customer_details()
assert customer.addresses[0].addressFormat == "AUS"
accounts = api.get_accounts()
Expand Down

0 comments on commit 8946b53

Please sign in to comment.