d582f15681
- Implemented tests for import polling functionality, ensuring correct behavior for active and terminal import statuses. - Created tests for the login page, validating user interactions and error handling. - Added unit tests for money utility functions, covering parsing, formatting, and summation of monetary values. - Developed tests for query keys, ensuring proper scoping and invalidation roots. chore: setup testing environment and configuration - Added setup file for testing with Vitest and Testing Library. - Configured TypeScript and Vite for the frontend project. - Created Docker and Nginx configurations for local development and production environments. - Established a PostgreSQL initialization script for setting up application roles. docs: add README and environment configuration for infra - Included README for the infra directory, detailing local development setup and service descriptions. - Created an example environment configuration file for local development with placeholders for sensitive information.
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from app.imports.adapters.alfa_xlsx import AlfaCreditXlsxAdapter, AlfaDebitXlsxAdapter
|
|
from app.imports.adapters.base import StatementAdapter, UnsupportedStatementLayout
|
|
from app.imports.adapters.ozon_pdf import OzonCreditPdfAdapter, OzonDebitPdfAdapter
|
|
from app.imports.adapters.rocketbank_pdf import RocketbankDebitPdfAdapter
|
|
|
|
ADAPTERS: tuple[StatementAdapter, ...] = (
|
|
AlfaDebitXlsxAdapter(),
|
|
AlfaCreditXlsxAdapter(),
|
|
OzonDebitPdfAdapter(),
|
|
OzonCreditPdfAdapter(),
|
|
RocketbankDebitPdfAdapter(),
|
|
)
|
|
|
|
XLSX_MAGIC = b"PK\x03\x04"
|
|
PDF_MAGIC = b"%PDF-"
|
|
|
|
|
|
def magic_kind(raw: bytes) -> str | None:
|
|
if raw.startswith(XLSX_MAGIC):
|
|
return "xlsx"
|
|
if raw.startswith(PDF_MAGIC):
|
|
return "pdf"
|
|
return None
|
|
|
|
|
|
def detect_adapter(raw: bytes, magic: str) -> StatementAdapter:
|
|
attempted: list[str] = []
|
|
for adapter in ADAPTERS:
|
|
expected = "xlsx" if adapter.adapter_id.endswith("xlsx") else "pdf"
|
|
if expected != magic:
|
|
continue
|
|
attempted.append(adapter.adapter_id)
|
|
if adapter.detect(raw):
|
|
return adapter
|
|
raise UnsupportedStatementLayout(
|
|
"no registered adapter recognizes this document layout; "
|
|
f"attempted: {', '.join(attempted) or 'none for this file type'}"
|
|
)
|