Files
finance/backend/tests/test_postgres_and_s3.py
T
k1nq d582f15681 feat: add tests for import polling, login page, money utilities, and query keys
- 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.
2026-09-14 09:26:33 +05:00

53 lines
1.7 KiB
Python

import os
import uuid
from datetime import date
import pytest
from sqlalchemy import create_engine
from sqlalchemy.exc import DBAPIError
from sqlalchemy.orm import Session
from app.db.session import set_space_context
from app.imports.blob import get_blob_store
from app.ledger.models import Account
from app.spaces.models import FinancialSpace
@pytest.mark.skipif(not os.getenv("RLS_DATABASE_URL"), reason="requires restricted PostgreSQL role")
def test_postgres_rls_requires_matching_transaction_context() -> None:
engine = create_engine(os.environ["RLS_DATABASE_URL"])
with Session(engine) as db:
space = FinancialSpace(name="RLS integration")
db.add(space)
db.commit()
space_id = space.id
db.add(Account(space_id=space_id, name="Blocked", kind="cash", opened_on=date.today()))
with pytest.raises(DBAPIError):
db.commit()
db.rollback()
set_space_context(db, space_id)
db.add(Account(space_id=space_id, name="Allowed", kind="cash", opened_on=date.today()))
db.commit()
set_space_context(db, uuid.uuid4())
assert db.query(Account).count() == 0
db.rollback()
set_space_context(db, space_id)
persisted_space = db.get(FinancialSpace, space_id)
assert persisted_space is not None
db.delete(persisted_space)
db.commit()
engine.dispose()
@pytest.mark.skipif(not os.getenv("S3_ENDPOINT_URL"), reason="requires S3-compatible storage")
def test_s3_blob_round_trip() -> None:
store = get_blob_store()
key = uuid.uuid4().hex
payload = b"synthetic statement payload"
store.put(key, payload)
assert store.get(key) == payload
store.delete(key)