Add optional API upload alongside SMTP, Nextcloud/WebDAV as a document source with the same dedup/retry flow as IMAP, stricter invoice file checks for images, and admin UI for source and delivery modes.
53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
"""BizDocs API client unit tests."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from forwarder.bizdocs.client import BizdocsClient, BizdocsCredentials
|
|
|
|
|
|
def test_identity_router_parses_mobile_api_url():
|
|
client = BizdocsClient()
|
|
mock_response = MagicMock()
|
|
mock_response.status_code = 200
|
|
mock_response.content = b'{"mobileApiUrl":"https://api.example.com"}'
|
|
mock_response.json.return_value = {"mobileApiUrl": "https://api.example.com"}
|
|
|
|
with patch.object(client, "_client") as mock_client_factory:
|
|
mock_http = MagicMock()
|
|
mock_http.__enter__.return_value = mock_http
|
|
mock_http.get.return_value = mock_response
|
|
mock_client_factory.return_value = mock_http
|
|
|
|
url = client.resolve_mobile_api_url("[email protected]")
|
|
assert url == "https://api.example.com"
|
|
|
|
|
|
def test_login_extracts_access_token():
|
|
client = BizdocsClient()
|
|
route_response = MagicMock(status_code=200, content=b"{}", json=lambda: {"mobileApiUrl": "https://api.example.com"})
|
|
login_response = MagicMock(
|
|
status_code=200,
|
|
content=b"{}",
|
|
json=lambda: {"accessToken": "abc123", "refreshToken": "ref"},
|
|
)
|
|
|
|
with patch.object(client, "_client") as mock_client_factory:
|
|
mock_http = MagicMock()
|
|
mock_http.__enter__.return_value = mock_http
|
|
mock_http.get.return_value = route_response
|
|
mock_http.post.return_value = login_response
|
|
mock_client_factory.return_value = mock_http
|
|
|
|
session = client.login(
|
|
BizdocsCredentials(
|
|
email="[email protected]",
|
|
password="secret",
|
|
company_id="co-1",
|
|
api_base_url="https://api.example.com",
|
|
)
|
|
)
|
|
assert session.access_token == "abc123"
|
|
assert session.mobile_api_url == "https://api.example.com"
|