Skip to content
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
31 changes: 30 additions & 1 deletion src/blindpay/resources/upload/upload.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
from typing_extensions import Literal, TypedDict
from typing import Optional

from typing_extensions import Literal, NotRequired, TypedDict

from ..._internal.api_client import InternalApiClient, InternalApiClientSync
from ...types import ApprovalRate, BlindpayApiResponse

UploadBucket = Literal["avatar", "onboarding", "limit_increase"]

UploadAnalyzeDocumentType = Literal[
"proof_of_address",
"identity_document",
"incorporation_document",
"proof_of_ownership",
"source_of_funds",
"selfie",
"bank_statement",
"tax_return",
"proof_of_income",
"financial_statement",
"invoice",
"transaction_document",
"passport",
"pay_stub",
"employment_letter",
"investment",
"crypto_exchange",
"blockchain_wallet",
"contract",
"accounts_receivable",
"merchant_processor",
"shareholder_loan",
]


class UploadInput(TypedDict):
bucket: UploadBucket
Expand All @@ -17,6 +44,8 @@ class UploadResponse(TypedDict):

class UploadAnalyzeInput(TypedDict):
file: str
type: UploadAnalyzeDocumentType
metadata: NotRequired[Optional[str]]


class UploadAnalyzeOutput(TypedDict):
Expand Down
37 changes: 37 additions & 0 deletions tests/resources/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ async def test_create(self):
assert response["data"] == mocked_data
mock_request.assert_called_once_with("POST", "/upload", {"bucket": "avatar", "file": "base64data"})

@pytest.mark.asyncio
async def test_analyze(self):
mocked_data = {"approval_rate": "high", "description": "Looks valid"}

with patch.object(self.blindpay._api, "_request") as mock_request:
mock_request.return_value = {"data": mocked_data, "error": None}

response = await self.blindpay.upload.analyze(
{"file": "base64data", "type": "proof_of_address", "metadata": '{"full_name":"Jane Doe"}'}
)

assert response["error"] is None
assert response["data"] == mocked_data
mock_request.assert_called_once_with(
"POST",
"/upload/analyze",
{"file": "base64data", "type": "proof_of_address", "metadata": '{"full_name":"Jane Doe"}'},
)


class TestUploadSync:
@pytest.fixture(autouse=True)
Expand All @@ -40,3 +59,21 @@ def test_create(self):
assert response["error"] is None
assert response["data"] == mocked_data
mock_request.assert_called_once_with("POST", "/upload", {"bucket": "avatar", "file": "base64data"})

def test_analyze(self):
mocked_data = {"approval_rate": "high", "description": "Looks valid"}

with patch.object(self.blindpay._api, "_request") as mock_request:
mock_request.return_value = {"data": mocked_data, "error": None}

response = self.blindpay.upload.analyze(
{"file": "base64data", "type": "proof_of_address", "metadata": '{"full_name":"Jane Doe"}'}
)

assert response["error"] is None
assert response["data"] == mocked_data
mock_request.assert_called_once_with(
"POST",
"/upload/analyze",
{"file": "base64data", "type": "proof_of_address", "metadata": '{"full_name":"Jane Doe"}'},
)
Loading