Fix linting error and linting config
This commit is contained in:
@@ -13,8 +13,14 @@ ignore = [
|
|||||||
"TRY003",
|
"TRY003",
|
||||||
"EM101",
|
"EM101",
|
||||||
"EM102",
|
"EM102",
|
||||||
"PLC0405",
|
"SIM108",
|
||||||
|
"C901",
|
||||||
|
"PLR0912",
|
||||||
|
"PLR0915",
|
||||||
|
"PLR0913",
|
||||||
|
"PLC0415",
|
||||||
]
|
]
|
||||||
|
|
||||||
[lint.extend-per-file-ignores]
|
[lint.extend-per-file-ignores]
|
||||||
"test*.py" = ["S101"]
|
"test*.py" = ["S101", "S105", "S106", "PT011", "PLR2004"]
|
||||||
|
"models*.py" = ["FA102"]
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
from collections.abc import Generator
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.engine import Engine
|
|
||||||
from sqlalchemy.pool import StaticPool
|
from sqlalchemy.pool import StaticPool
|
||||||
from sqlmodel import Session, SQLModel
|
from sqlmodel import Session, SQLModel
|
||||||
|
|
||||||
from trading_journal import crud, models
|
from trading_journal import crud, models
|
||||||
|
|
||||||
# TODO: If needed, add failing flow tests, but now only add happy flow.
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Generator
|
||||||
|
|
||||||
|
from sqlalchemy.engine import Engine
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@@ -41,16 +45,14 @@ def make_user(session: Session, username: str = "testuser") -> int:
|
|||||||
return user.id
|
return user.id
|
||||||
|
|
||||||
|
|
||||||
def make_cycle(
|
def make_cycle(session: Session, user_id: int, friendly_name: str = "Test Cycle") -> int:
|
||||||
session: Session, user_id: int, friendly_name: str = "Test Cycle"
|
|
||||||
) -> int:
|
|
||||||
cycle = models.Cycles(
|
cycle = models.Cycles(
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
friendly_name=friendly_name,
|
friendly_name=friendly_name,
|
||||||
symbol="AAPL",
|
symbol="AAPL",
|
||||||
underlying_currency=models.UnderlyingCurrency.USD,
|
underlying_currency=models.UnderlyingCurrency.USD,
|
||||||
status=models.CycleStatus.OPEN,
|
status=models.CycleStatus.OPEN,
|
||||||
start_date=datetime.now().date(),
|
start_date=datetime.now(timezone.utc).date(),
|
||||||
)
|
)
|
||||||
session.add(cycle)
|
session.add(cycle)
|
||||||
session.commit()
|
session.commit()
|
||||||
@@ -58,9 +60,7 @@ def make_cycle(
|
|||||||
return cycle.id
|
return cycle.id
|
||||||
|
|
||||||
|
|
||||||
def make_trade(
|
def make_trade(session: Session, user_id: int, cycle_id: int, friendly_name: str = "Test Trade") -> int:
|
||||||
session: Session, user_id: int, cycle_id: int, friendly_name: str = "Test Trade"
|
|
||||||
) -> int:
|
|
||||||
trade = models.Trades(
|
trade = models.Trades(
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
friendly_name=friendly_name,
|
friendly_name=friendly_name,
|
||||||
@@ -68,8 +68,8 @@ def make_trade(
|
|||||||
underlying_currency=models.UnderlyingCurrency.USD,
|
underlying_currency=models.UnderlyingCurrency.USD,
|
||||||
trade_type=models.TradeType.LONG_SPOT,
|
trade_type=models.TradeType.LONG_SPOT,
|
||||||
trade_strategy=models.TradeStrategy.SPOT,
|
trade_strategy=models.TradeStrategy.SPOT,
|
||||||
trade_date=datetime.now().date(),
|
trade_date=datetime.now(timezone.utc).date(),
|
||||||
trade_time_utc=datetime.now(),
|
trade_time_utc=datetime.now(timezone.utc),
|
||||||
quantity=10,
|
quantity=10,
|
||||||
price_cents=15000,
|
price_cents=15000,
|
||||||
gross_cash_flow_cents=-150000,
|
gross_cash_flow_cents=-150000,
|
||||||
@@ -113,7 +113,15 @@ def make_login_session(session: Session, created_at: datetime) -> models.Session
|
|||||||
return login_session
|
return login_session
|
||||||
|
|
||||||
|
|
||||||
def test_create_trade_success_with_cycle(session: Session):
|
def _ensure_utc_aware(dt: datetime) -> datetime | None:
|
||||||
|
if dt is None:
|
||||||
|
return None
|
||||||
|
if dt.tzinfo is None:
|
||||||
|
return dt.replace(tzinfo=timezone.utc)
|
||||||
|
return dt.astimezone(timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_trade_success_with_cycle(session: Session) -> None:
|
||||||
user_id = make_user(session)
|
user_id = make_user(session)
|
||||||
cycle_id = make_cycle(session, user_id)
|
cycle_id = make_cycle(session, user_id)
|
||||||
|
|
||||||
@@ -124,7 +132,7 @@ def test_create_trade_success_with_cycle(session: Session):
|
|||||||
"underlying_currency": models.UnderlyingCurrency.USD,
|
"underlying_currency": models.UnderlyingCurrency.USD,
|
||||||
"trade_type": models.TradeType.LONG_SPOT,
|
"trade_type": models.TradeType.LONG_SPOT,
|
||||||
"trade_strategy": models.TradeStrategy.SPOT,
|
"trade_strategy": models.TradeStrategy.SPOT,
|
||||||
"trade_time_utc": datetime.now(),
|
"trade_time_utc": datetime.now(timezone.utc),
|
||||||
"quantity": 10,
|
"quantity": 10,
|
||||||
"price_cents": 15000,
|
"price_cents": 15000,
|
||||||
"gross_cash_flow_cents": -150000,
|
"gross_cash_flow_cents": -150000,
|
||||||
@@ -154,7 +162,7 @@ def test_create_trade_success_with_cycle(session: Session):
|
|||||||
assert actual_trade.cycle_id == trade_data["cycle_id"]
|
assert actual_trade.cycle_id == trade_data["cycle_id"]
|
||||||
|
|
||||||
|
|
||||||
def test_create_trade_with_auto_created_cycle(session: Session):
|
def test_create_trade_with_auto_created_cycle(session: Session) -> None:
|
||||||
user_id = make_user(session)
|
user_id = make_user(session)
|
||||||
|
|
||||||
trade_data = {
|
trade_data = {
|
||||||
@@ -164,7 +172,7 @@ def test_create_trade_with_auto_created_cycle(session: Session):
|
|||||||
"underlying_currency": models.UnderlyingCurrency.USD,
|
"underlying_currency": models.UnderlyingCurrency.USD,
|
||||||
"trade_type": models.TradeType.LONG_SPOT,
|
"trade_type": models.TradeType.LONG_SPOT,
|
||||||
"trade_strategy": models.TradeStrategy.SPOT,
|
"trade_strategy": models.TradeStrategy.SPOT,
|
||||||
"trade_time_utc": datetime.now(),
|
"trade_time_utc": datetime.now(timezone.utc),
|
||||||
"quantity": 5,
|
"quantity": 5,
|
||||||
"price_cents": 15500,
|
"price_cents": 15500,
|
||||||
}
|
}
|
||||||
@@ -196,7 +204,7 @@ def test_create_trade_with_auto_created_cycle(session: Session):
|
|||||||
assert auto_cycle.friendly_name.startswith("Auto-created Cycle by trade")
|
assert auto_cycle.friendly_name.startswith("Auto-created Cycle by trade")
|
||||||
|
|
||||||
|
|
||||||
def test_create_trade_missing_required_fields(session: Session):
|
def test_create_trade_missing_required_fields(session: Session) -> None:
|
||||||
user_id = make_user(session)
|
user_id = make_user(session)
|
||||||
|
|
||||||
base_trade_data = {
|
base_trade_data = {
|
||||||
@@ -206,7 +214,7 @@ def test_create_trade_missing_required_fields(session: Session):
|
|||||||
"underlying_currency": models.UnderlyingCurrency.USD,
|
"underlying_currency": models.UnderlyingCurrency.USD,
|
||||||
"trade_type": models.TradeType.LONG_SPOT,
|
"trade_type": models.TradeType.LONG_SPOT,
|
||||||
"trade_strategy": models.TradeStrategy.SPOT,
|
"trade_strategy": models.TradeStrategy.SPOT,
|
||||||
"trade_time_utc": datetime.now(),
|
"trade_time_utc": datetime.now(timezone.utc),
|
||||||
"quantity": 10,
|
"quantity": 10,
|
||||||
"price_cents": 15000,
|
"price_cents": 15000,
|
||||||
}
|
}
|
||||||
@@ -254,7 +262,7 @@ def test_create_trade_missing_required_fields(session: Session):
|
|||||||
assert "price_cents is required" in str(excinfo.value)
|
assert "price_cents is required" in str(excinfo.value)
|
||||||
|
|
||||||
|
|
||||||
def test_get_trade_by_id(session: Session):
|
def test_get_trade_by_id(session: Session) -> None:
|
||||||
user_id = make_user(session)
|
user_id = make_user(session)
|
||||||
cycle_id = make_cycle(session, user_id)
|
cycle_id = make_cycle(session, user_id)
|
||||||
trade_data = {
|
trade_data = {
|
||||||
@@ -264,8 +272,8 @@ def test_get_trade_by_id(session: Session):
|
|||||||
"underlying_currency": models.UnderlyingCurrency.USD,
|
"underlying_currency": models.UnderlyingCurrency.USD,
|
||||||
"trade_type": models.TradeType.LONG_SPOT,
|
"trade_type": models.TradeType.LONG_SPOT,
|
||||||
"trade_strategy": models.TradeStrategy.SPOT,
|
"trade_strategy": models.TradeStrategy.SPOT,
|
||||||
"trade_date": datetime.now().date(),
|
"trade_date": datetime.now(timezone.utc).date(),
|
||||||
"trade_time_utc": datetime.now(),
|
"trade_time_utc": datetime.now(timezone.utc),
|
||||||
"quantity": 10,
|
"quantity": 10,
|
||||||
"price_cents": 15000,
|
"price_cents": 15000,
|
||||||
"gross_cash_flow_cents": -150000,
|
"gross_cash_flow_cents": -150000,
|
||||||
@@ -291,7 +299,7 @@ def test_get_trade_by_id(session: Session):
|
|||||||
assert trade.trade_date == trade_data["trade_date"]
|
assert trade.trade_date == trade_data["trade_date"]
|
||||||
|
|
||||||
|
|
||||||
def test_get_trade_by_user_id_and_friendly_name(session: Session):
|
def test_get_trade_by_user_id_and_friendly_name(session: Session) -> None:
|
||||||
user_id = make_user(session)
|
user_id = make_user(session)
|
||||||
cycle_id = make_cycle(session, user_id)
|
cycle_id = make_cycle(session, user_id)
|
||||||
friendly_name = "Unique Trade Name"
|
friendly_name = "Unique Trade Name"
|
||||||
@@ -302,8 +310,8 @@ def test_get_trade_by_user_id_and_friendly_name(session: Session):
|
|||||||
"underlying_currency": models.UnderlyingCurrency.USD,
|
"underlying_currency": models.UnderlyingCurrency.USD,
|
||||||
"trade_type": models.TradeType.LONG_SPOT,
|
"trade_type": models.TradeType.LONG_SPOT,
|
||||||
"trade_strategy": models.TradeStrategy.SPOT,
|
"trade_strategy": models.TradeStrategy.SPOT,
|
||||||
"trade_date": datetime.now().date(),
|
"trade_date": datetime.now(timezone.utc).date(),
|
||||||
"trade_time_utc": datetime.now(),
|
"trade_time_utc": datetime.now(timezone.utc),
|
||||||
"quantity": 10,
|
"quantity": 10,
|
||||||
"price_cents": 15000,
|
"price_cents": 15000,
|
||||||
"gross_cash_flow_cents": -150000,
|
"gross_cash_flow_cents": -150000,
|
||||||
@@ -318,7 +326,7 @@ def test_get_trade_by_user_id_and_friendly_name(session: Session):
|
|||||||
assert trade.user_id == user_id
|
assert trade.user_id == user_id
|
||||||
|
|
||||||
|
|
||||||
def test_get_trades_by_user_id(session: Session):
|
def test_get_trades_by_user_id(session: Session) -> None:
|
||||||
user_id = make_user(session)
|
user_id = make_user(session)
|
||||||
cycle_id = make_cycle(session, user_id)
|
cycle_id = make_cycle(session, user_id)
|
||||||
trade_data_1 = {
|
trade_data_1 = {
|
||||||
@@ -328,8 +336,8 @@ def test_get_trades_by_user_id(session: Session):
|
|||||||
"underlying_currency": models.UnderlyingCurrency.USD,
|
"underlying_currency": models.UnderlyingCurrency.USD,
|
||||||
"trade_type": models.TradeType.LONG_SPOT,
|
"trade_type": models.TradeType.LONG_SPOT,
|
||||||
"trade_strategy": models.TradeStrategy.SPOT,
|
"trade_strategy": models.TradeStrategy.SPOT,
|
||||||
"trade_date": datetime.now().date(),
|
"trade_date": datetime.now(timezone.utc).date(),
|
||||||
"trade_time_utc": datetime.now(),
|
"trade_time_utc": datetime.now(timezone.utc),
|
||||||
"quantity": 10,
|
"quantity": 10,
|
||||||
"price_cents": 15000,
|
"price_cents": 15000,
|
||||||
"gross_cash_flow_cents": -150000,
|
"gross_cash_flow_cents": -150000,
|
||||||
@@ -344,8 +352,8 @@ def test_get_trades_by_user_id(session: Session):
|
|||||||
"underlying_currency": models.UnderlyingCurrency.USD,
|
"underlying_currency": models.UnderlyingCurrency.USD,
|
||||||
"trade_type": models.TradeType.SHORT_SPOT,
|
"trade_type": models.TradeType.SHORT_SPOT,
|
||||||
"trade_strategy": models.TradeStrategy.SPOT,
|
"trade_strategy": models.TradeStrategy.SPOT,
|
||||||
"trade_date": datetime.now().date(),
|
"trade_date": datetime.now(timezone.utc).date(),
|
||||||
"trade_time_utc": datetime.now(),
|
"trade_time_utc": datetime.now(timezone.utc),
|
||||||
"quantity": 5,
|
"quantity": 5,
|
||||||
"price_cents": 280000,
|
"price_cents": 280000,
|
||||||
"gross_cash_flow_cents": 1400000,
|
"gross_cash_flow_cents": 1400000,
|
||||||
@@ -362,7 +370,7 @@ def test_get_trades_by_user_id(session: Session):
|
|||||||
assert friendly_names == {"Trade One", "Trade Two"}
|
assert friendly_names == {"Trade One", "Trade Two"}
|
||||||
|
|
||||||
|
|
||||||
def test_update_trade_note(session: Session):
|
def test_update_trade_note(session: Session) -> None:
|
||||||
user_id = make_user(session)
|
user_id = make_user(session)
|
||||||
cycle_id = make_cycle(session, user_id)
|
cycle_id = make_cycle(session, user_id)
|
||||||
trade_id = make_trade(session, user_id, cycle_id)
|
trade_id = make_trade(session, user_id, cycle_id)
|
||||||
@@ -379,7 +387,7 @@ def test_update_trade_note(session: Session):
|
|||||||
assert actual_trade.notes == new_note
|
assert actual_trade.notes == new_note
|
||||||
|
|
||||||
|
|
||||||
def test_invalidate_trade(session: Session):
|
def test_invalidate_trade(session: Session) -> None:
|
||||||
user_id = make_user(session)
|
user_id = make_user(session)
|
||||||
cycle_id = make_cycle(session, user_id)
|
cycle_id = make_cycle(session, user_id)
|
||||||
trade_id = make_trade(session, user_id, cycle_id)
|
trade_id = make_trade(session, user_id, cycle_id)
|
||||||
@@ -395,7 +403,7 @@ def test_invalidate_trade(session: Session):
|
|||||||
assert actual_trade.is_invalidated is True
|
assert actual_trade.is_invalidated is True
|
||||||
|
|
||||||
|
|
||||||
def test_replace_trade(session: Session):
|
def test_replace_trade(session: Session) -> None:
|
||||||
user_id = make_user(session)
|
user_id = make_user(session)
|
||||||
cycle_id = make_cycle(session, user_id)
|
cycle_id = make_cycle(session, user_id)
|
||||||
old_trade_id = make_trade(session, user_id, cycle_id)
|
old_trade_id = make_trade(session, user_id, cycle_id)
|
||||||
@@ -407,7 +415,7 @@ def test_replace_trade(session: Session):
|
|||||||
"underlying_currency": models.UnderlyingCurrency.USD,
|
"underlying_currency": models.UnderlyingCurrency.USD,
|
||||||
"trade_type": models.TradeType.LONG_SPOT,
|
"trade_type": models.TradeType.LONG_SPOT,
|
||||||
"trade_strategy": models.TradeStrategy.SPOT,
|
"trade_strategy": models.TradeStrategy.SPOT,
|
||||||
"trade_time_utc": datetime.now(),
|
"trade_time_utc": datetime.now(timezone.utc),
|
||||||
"quantity": 20,
|
"quantity": 20,
|
||||||
"price_cents": 25000,
|
"price_cents": 25000,
|
||||||
}
|
}
|
||||||
@@ -438,7 +446,7 @@ def test_replace_trade(session: Session):
|
|||||||
assert actual_new_trade.replaced_by_trade_id == old_trade_id
|
assert actual_new_trade.replaced_by_trade_id == old_trade_id
|
||||||
|
|
||||||
|
|
||||||
def test_create_cycle(session: Session):
|
def test_create_cycle(session: Session) -> None:
|
||||||
user_id = make_user(session)
|
user_id = make_user(session)
|
||||||
cycle_data = {
|
cycle_data = {
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
@@ -446,7 +454,7 @@ def test_create_cycle(session: Session):
|
|||||||
"symbol": "GOOGL",
|
"symbol": "GOOGL",
|
||||||
"underlying_currency": models.UnderlyingCurrency.USD,
|
"underlying_currency": models.UnderlyingCurrency.USD,
|
||||||
"status": models.CycleStatus.OPEN,
|
"status": models.CycleStatus.OPEN,
|
||||||
"start_date": datetime.now().date(),
|
"start_date": datetime.now(timezone.utc).date(),
|
||||||
}
|
}
|
||||||
cycle = crud.create_cycle(session, cycle_data)
|
cycle = crud.create_cycle(session, cycle_data)
|
||||||
assert cycle.id is not None
|
assert cycle.id is not None
|
||||||
@@ -467,7 +475,7 @@ def test_create_cycle(session: Session):
|
|||||||
assert actual_cycle.start_date == cycle_data["start_date"]
|
assert actual_cycle.start_date == cycle_data["start_date"]
|
||||||
|
|
||||||
|
|
||||||
def test_update_cycle(session: Session):
|
def test_update_cycle(session: Session) -> None:
|
||||||
user_id = make_user(session)
|
user_id = make_user(session)
|
||||||
cycle_id = make_cycle(session, user_id, friendly_name="Initial Cycle Name")
|
cycle_id = make_cycle(session, user_id, friendly_name="Initial Cycle Name")
|
||||||
|
|
||||||
@@ -488,7 +496,7 @@ def test_update_cycle(session: Session):
|
|||||||
assert actual_cycle.status == update_data["status"]
|
assert actual_cycle.status == update_data["status"]
|
||||||
|
|
||||||
|
|
||||||
def test_update_cycle_immutable_fields(session: Session):
|
def test_update_cycle_immutable_fields(session: Session) -> None:
|
||||||
user_id = make_user(session)
|
user_id = make_user(session)
|
||||||
cycle_id = make_cycle(session, user_id, friendly_name="Initial Cycle Name")
|
cycle_id = make_cycle(session, user_id, friendly_name="Initial Cycle Name")
|
||||||
|
|
||||||
@@ -496,8 +504,8 @@ def test_update_cycle_immutable_fields(session: Session):
|
|||||||
update_data = {
|
update_data = {
|
||||||
"id": cycle_id + 1, # Trying to change the ID
|
"id": cycle_id + 1, # Trying to change the ID
|
||||||
"user_id": user_id + 1, # Trying to change the user_id
|
"user_id": user_id + 1, # Trying to change the user_id
|
||||||
"start_date": datetime(2020, 1, 1).date(), # Trying to change start_date
|
"start_date": datetime(2020, 1, 1, tzinfo=timezone.utc).date(), # Trying to change start_date
|
||||||
"created_at": datetime(2020, 1, 1), # Trying to change created_at
|
"created_at": datetime(2020, 1, 1, tzinfo=timezone.utc), # Trying to change created_at
|
||||||
"friendly_name": "Valid Update", # Valid field to update
|
"friendly_name": "Valid Update", # Valid field to update
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -511,7 +519,7 @@ def test_update_cycle_immutable_fields(session: Session):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_create_user(session: Session):
|
def test_create_user(session: Session) -> None:
|
||||||
user_data = {
|
user_data = {
|
||||||
"username": "newuser",
|
"username": "newuser",
|
||||||
"password_hash": "newhashedpassword",
|
"password_hash": "newhashedpassword",
|
||||||
@@ -528,7 +536,7 @@ def test_create_user(session: Session):
|
|||||||
assert actual_user.password_hash == user_data["password_hash"]
|
assert actual_user.password_hash == user_data["password_hash"]
|
||||||
|
|
||||||
|
|
||||||
def test_update_user(session: Session):
|
def test_update_user(session: Session) -> None:
|
||||||
user_id = make_user(session, username="updatableuser")
|
user_id = make_user(session, username="updatableuser")
|
||||||
|
|
||||||
update_data = {
|
update_data = {
|
||||||
@@ -545,14 +553,14 @@ def test_update_user(session: Session):
|
|||||||
assert actual_user.password_hash == update_data["password_hash"]
|
assert actual_user.password_hash == update_data["password_hash"]
|
||||||
|
|
||||||
|
|
||||||
def test_update_user_immutable_fields(session: Session):
|
def test_update_user_immutable_fields(session: Session) -> None:
|
||||||
user_id = make_user(session, username="immutableuser")
|
user_id = make_user(session, username="immutableuser")
|
||||||
|
|
||||||
# Attempt to update immutable fields
|
# Attempt to update immutable fields
|
||||||
update_data = {
|
update_data = {
|
||||||
"id": user_id + 1, # Trying to change the ID
|
"id": user_id + 1, # Trying to change the ID
|
||||||
"username": "newusername", # Trying to change the username
|
"username": "newusername", # Trying to change the username
|
||||||
"created_at": datetime(2020, 1, 1), # Trying to change created_at
|
"created_at": datetime(2020, 1, 1, tzinfo=timezone.utc), # Trying to change created_at
|
||||||
"password_hash": "validupdate", # Valid field to update
|
"password_hash": "validupdate", # Valid field to update
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -566,7 +574,7 @@ def test_update_user_immutable_fields(session: Session):
|
|||||||
|
|
||||||
|
|
||||||
# login sessions
|
# login sessions
|
||||||
def test_create_login_session(session: Session):
|
def test_create_login_session(session: Session) -> None:
|
||||||
user_id = make_user(session, username="testuser")
|
user_id = make_user(session, username="testuser")
|
||||||
session_token_hash = "sessiontokenhashed"
|
session_token_hash = "sessiontokenhashed"
|
||||||
login_session = crud.create_login_session(session, user_id, session_token_hash)
|
login_session = crud.create_login_session(session, user_id, session_token_hash)
|
||||||
@@ -575,7 +583,7 @@ def test_create_login_session(session: Session):
|
|||||||
assert login_session.session_token_hash == session_token_hash
|
assert login_session.session_token_hash == session_token_hash
|
||||||
|
|
||||||
|
|
||||||
def test_create_login_session_with_invalid_user(session: Session):
|
def test_create_login_session_with_invalid_user(session: Session) -> None:
|
||||||
invalid_user_id = 9999 # Assuming this user ID does not exist
|
invalid_user_id = 9999 # Assuming this user ID does not exist
|
||||||
session_token_hash = "sessiontokenhashed"
|
session_token_hash = "sessiontokenhashed"
|
||||||
with pytest.raises(ValueError) as excinfo:
|
with pytest.raises(ValueError) as excinfo:
|
||||||
@@ -583,40 +591,34 @@ def test_create_login_session_with_invalid_user(session: Session):
|
|||||||
assert "user_id does not exist" in str(excinfo.value)
|
assert "user_id does not exist" in str(excinfo.value)
|
||||||
|
|
||||||
|
|
||||||
def test_get_login_session_by_token_and_user_id(session: Session):
|
def test_get_login_session_by_token_and_user_id(session: Session) -> None:
|
||||||
now = datetime.now()
|
now = datetime.now(timezone.utc)
|
||||||
created_session = make_login_session(session, now)
|
created_session = make_login_session(session, now)
|
||||||
fetched_session = crud.get_login_session_by_token_hash_and_user_id(
|
fetched_session = crud.get_login_session_by_token_hash_and_user_id(session, created_session.session_token_hash, created_session.user_id)
|
||||||
session, created_session.session_token_hash, created_session.user_id
|
|
||||||
)
|
|
||||||
assert fetched_session is not None
|
assert fetched_session is not None
|
||||||
assert fetched_session.id == created_session.id
|
assert fetched_session.id == created_session.id
|
||||||
assert fetched_session.user_id == created_session.user_id
|
assert fetched_session.user_id == created_session.user_id
|
||||||
assert fetched_session.session_token_hash == created_session.session_token_hash
|
assert fetched_session.session_token_hash == created_session.session_token_hash
|
||||||
|
|
||||||
|
|
||||||
def test_update_login_session(session: Session):
|
def test_update_login_session(session: Session) -> None:
|
||||||
now = datetime.now()
|
now = datetime.now(timezone.utc)
|
||||||
created_session = make_login_session(session, now)
|
created_session = make_login_session(session, now)
|
||||||
|
|
||||||
update_data = {
|
update_data = {
|
||||||
"last_seen_at": now + timedelta(hours=1),
|
"last_seen_at": now + timedelta(hours=1),
|
||||||
"last_used_ip": "192.168.1.1",
|
"last_used_ip": "192.168.1.1",
|
||||||
}
|
}
|
||||||
updated_session = crud.update_login_session(
|
updated_session = crud.update_login_session(session, created_session.session_token_hash, update_data)
|
||||||
session, created_session.session_token_hash, update_data
|
|
||||||
)
|
|
||||||
assert updated_session is not None
|
assert updated_session is not None
|
||||||
assert updated_session.last_seen_at == update_data["last_seen_at"]
|
assert _ensure_utc_aware(updated_session.last_seen_at) == update_data["last_seen_at"]
|
||||||
assert updated_session.last_used_ip == update_data["last_used_ip"]
|
assert updated_session.last_used_ip == update_data["last_used_ip"]
|
||||||
|
|
||||||
|
|
||||||
def test_delete_login_session(session: Session):
|
def test_delete_login_session(session: Session) -> None:
|
||||||
now = datetime.now()
|
now = datetime.now(timezone.utc)
|
||||||
created_session = make_login_session(session, now)
|
created_session = make_login_session(session, now)
|
||||||
|
|
||||||
crud.delete_login_session(session, created_session.session_token_hash)
|
crud.delete_login_session(session, created_session.session_token_hash)
|
||||||
deleted_session = crud.get_login_session_by_token_hash_and_user_id(
|
deleted_session = crud.get_login_session_by_token_hash_and_user_id(session, created_session.session_token_hash, created_session.user_id)
|
||||||
session, created_session.session_token_hash, created_session.user_id
|
|
||||||
)
|
|
||||||
assert deleted_session is None
|
assert deleted_session is None
|
||||||
|
|||||||
@@ -46,9 +46,8 @@ def database_ctx(db: Database) -> Generator[Database, None, None]:
|
|||||||
|
|
||||||
def test_select_one_executes() -> None:
|
def test_select_one_executes() -> None:
|
||||||
db = create_database(None) # in-memory by default
|
db = create_database(None) # in-memory by default
|
||||||
with database_ctx(db):
|
with database_ctx(db), session_ctx(db) as session:
|
||||||
with session_ctx(db) as session:
|
val = session.exec(text("SELECT 1")).scalar_one()
|
||||||
val = session.exec(text("SELECT 1")).scalar_one()
|
|
||||||
assert int(val) == 1
|
assert int(val) == 1
|
||||||
|
|
||||||
|
|
||||||
@@ -56,9 +55,7 @@ def test_in_memory_persists_across_sessions_when_using_staticpool() -> None:
|
|||||||
db = create_database(None) # in-memory with StaticPool
|
db = create_database(None) # in-memory with StaticPool
|
||||||
with database_ctx(db):
|
with database_ctx(db):
|
||||||
with session_ctx(db) as s1:
|
with session_ctx(db) as s1:
|
||||||
s1.exec(
|
s1.exec(text("CREATE TABLE IF NOT EXISTS t (id INTEGER PRIMARY KEY, val TEXT);"))
|
||||||
text("CREATE TABLE IF NOT EXISTS t (id INTEGER PRIMARY KEY, val TEXT);")
|
|
||||||
)
|
|
||||||
s1.exec(text("INSERT INTO t (val) VALUES (:v)").bindparams(v="hello"))
|
s1.exec(text("INSERT INTO t (val) VALUES (:v)").bindparams(v="hello"))
|
||||||
with session_ctx(db) as s2:
|
with session_ctx(db) as s2:
|
||||||
got = s2.exec(text("SELECT val FROM t")).scalar_one()
|
got = s2.exec(text("SELECT val FROM t")).scalar_one()
|
||||||
@@ -67,10 +64,9 @@ def test_in_memory_persists_across_sessions_when_using_staticpool() -> None:
|
|||||||
|
|
||||||
def test_sqlite_pragmas_applied() -> None:
|
def test_sqlite_pragmas_applied() -> None:
|
||||||
db = create_database(None)
|
db = create_database(None)
|
||||||
with database_ctx(db):
|
with database_ctx(db), session_ctx(db) as session:
|
||||||
# PRAGMA returns integer 1 when foreign_keys ON
|
# PRAGMA returns integer 1 when foreign_keys ON
|
||||||
with session_ctx(db) as session:
|
fk = session.exec(text("PRAGMA foreign_keys")).scalar_one()
|
||||||
fk = session.exec(text("PRAGMA foreign_keys")).scalar_one()
|
|
||||||
assert int(fk) == 1
|
assert int(fk) == 1
|
||||||
|
|
||||||
|
|
||||||
@@ -82,16 +78,8 @@ def test_rollback_on_exception() -> None:
|
|||||||
# Create table then insert and raise inside the same session to force rollback
|
# Create table then insert and raise inside the same session to force rollback
|
||||||
with pytest.raises(RuntimeError): # noqa: PT012, SIM117
|
with pytest.raises(RuntimeError): # noqa: PT012, SIM117
|
||||||
with session_ctx(db) as s:
|
with session_ctx(db) as s:
|
||||||
s.exec(
|
s.exec(text("CREATE TABLE IF NOT EXISTS t_rb (id INTEGER PRIMARY KEY, val TEXT);"))
|
||||||
text(
|
s.exec(text("INSERT INTO t_rb (val) VALUES (:v)").bindparams(v="will_rollback"))
|
||||||
"CREATE TABLE IF NOT EXISTS t_rb (id INTEGER PRIMARY KEY, val TEXT);"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
s.exec(
|
|
||||||
text("INSERT INTO t_rb (val) VALUES (:v)").bindparams(
|
|
||||||
v="will_rollback"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
# simulate handler error -> should trigger rollback in get_session
|
# simulate handler error -> should trigger rollback in get_session
|
||||||
raise RuntimeError("simulated failure")
|
raise RuntimeError("simulated failure")
|
||||||
|
|
||||||
|
|||||||
@@ -89,12 +89,10 @@ def test_run_migrations_0_to_1(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||||||
with engine.connect() as conn:
|
with engine.connect() as conn:
|
||||||
# check tables exist
|
# check tables exist
|
||||||
rows = conn.execute(
|
rows = conn.execute(
|
||||||
text("SELECT name FROM sqlite_master WHERE type='table'")
|
text("SELECT name FROM sqlite_master WHERE type='table'"),
|
||||||
).fetchall()
|
).fetchall()
|
||||||
found_tables = {r[0] for r in rows}
|
found_tables = {r[0] for r in rows}
|
||||||
assert set(expected_schema.keys()).issubset(found_tables), (
|
assert set(expected_schema.keys()).issubset(found_tables), f"missing tables: {set(expected_schema.keys()) - found_tables}"
|
||||||
f"missing tables: {set(expected_schema.keys()) - found_tables}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# check user_version
|
# check user_version
|
||||||
uv = conn.execute(text("PRAGMA user_version")).fetchone()
|
uv = conn.execute(text("PRAGMA user_version")).fetchone()
|
||||||
@@ -103,14 +101,9 @@ def test_run_migrations_0_to_1(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||||||
|
|
||||||
# validate each table columns
|
# validate each table columns
|
||||||
for tbl_name, cols in expected_schema.items():
|
for tbl_name, cols in expected_schema.items():
|
||||||
info_rows = conn.execute(
|
info_rows = conn.execute(text(f"PRAGMA table_info({tbl_name})")).fetchall()
|
||||||
text(f"PRAGMA table_info({tbl_name})")
|
|
||||||
).fetchall()
|
|
||||||
# map: name -> (type, notnull, pk)
|
# map: name -> (type, notnull, pk)
|
||||||
actual = {
|
actual = {r[1]: ((r[2] or "").upper(), int(r[3]), int(r[5])) for r in info_rows}
|
||||||
r[1]: ((r[2] or "").upper(), int(r[3]), int(r[5]))
|
|
||||||
for r in info_rows
|
|
||||||
}
|
|
||||||
for colname, (exp_type, exp_notnull, exp_pk) in cols.items():
|
for colname, (exp_type, exp_notnull, exp_pk) in cols.items():
|
||||||
assert colname in actual, f"{tbl_name}: missing column {colname}"
|
assert colname in actual, f"{tbl_name}: missing column {colname}"
|
||||||
act_type, act_notnull, act_pk = actual[colname]
|
act_type, act_notnull, act_pk = actual[colname]
|
||||||
@@ -122,20 +115,12 @@ def test_run_migrations_0_to_1(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||||||
assert exp_type in act_base or act_base in exp_type, (
|
assert exp_type in act_base or act_base in exp_type, (
|
||||||
f"type mismatch {tbl_name}.{colname}: expected {exp_type}, got {act_base}"
|
f"type mismatch {tbl_name}.{colname}: expected {exp_type}, got {act_base}"
|
||||||
)
|
)
|
||||||
assert act_notnull == exp_notnull, (
|
assert act_notnull == exp_notnull, f"notnull mismatch {tbl_name}.{colname}: expected {exp_notnull}, got {act_notnull}"
|
||||||
f"notnull mismatch {tbl_name}.{colname}: expected {exp_notnull}, got {act_notnull}"
|
assert act_pk == exp_pk, f"pk mismatch {tbl_name}.{colname}: expected {exp_pk}, got {act_pk}"
|
||||||
)
|
|
||||||
assert act_pk == exp_pk, (
|
|
||||||
f"pk mismatch {tbl_name}.{colname}: expected {exp_pk}, got {act_pk}"
|
|
||||||
)
|
|
||||||
for tbl_name, fks in expected_fks.items():
|
for tbl_name, fks in expected_fks.items():
|
||||||
fk_rows = conn.execute(
|
fk_rows = conn.execute(text(f"PRAGMA foreign_key_list('{tbl_name}')")).fetchall()
|
||||||
text(f"PRAGMA foreign_key_list('{tbl_name}')")
|
|
||||||
).fetchall()
|
|
||||||
# fk_rows columns: (id, seq, table, from, to, on_update, on_delete, match)
|
# fk_rows columns: (id, seq, table, from, to, on_update, on_delete, match)
|
||||||
actual_fk_list = [
|
actual_fk_list = [{"table": r[2], "from": r[3], "to": r[4]} for r in fk_rows]
|
||||||
{"table": r[2], "from": r[3], "to": r[4]} for r in fk_rows
|
|
||||||
]
|
|
||||||
for efk in fks:
|
for efk in fks:
|
||||||
assert efk in actual_fk_list, f"missing FK on {tbl_name}: {efk}"
|
assert efk in actual_fk_list, f"missing FK on {tbl_name}: {efk}"
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ def test_default_settings(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||||||
|
|
||||||
s = load_settings()
|
s = load_settings()
|
||||||
assert s.host == "0.0.0.0" # noqa: S104
|
assert s.host == "0.0.0.0" # noqa: S104
|
||||||
assert s.port == 8000 # noqa: PLR2004
|
assert s.port == 8000
|
||||||
assert s.workers == 1
|
assert s.workers == 1
|
||||||
assert s.log_level == "info"
|
assert s.log_level == "info"
|
||||||
|
|
||||||
@@ -26,8 +26,8 @@ def test_env_overrides(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||||||
|
|
||||||
s = load_settings()
|
s = load_settings()
|
||||||
assert s.host == "127.0.0.1"
|
assert s.host == "127.0.0.1"
|
||||||
assert s.port == 9000 # noqa: PLR2004
|
assert s.port == 9000
|
||||||
assert s.workers == 3 # noqa: PLR2004
|
assert s.workers == 3
|
||||||
assert s.log_level == "debug"
|
assert s.log_level == "debug"
|
||||||
|
|
||||||
|
|
||||||
@@ -40,6 +40,6 @@ def test_yaml_config_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> No
|
|||||||
|
|
||||||
s = load_settings()
|
s = load_settings()
|
||||||
assert s.host == "10.0.0.5"
|
assert s.host == "10.0.0.5"
|
||||||
assert s.port == 8088 # noqa: PLR2004
|
assert s.port == 8088
|
||||||
assert s.workers == 5 # noqa: PLR2004
|
assert s.workers == 5
|
||||||
assert s.log_level == "debug"
|
assert s.log_level == "debug"
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
from typing import Mapping
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
from sqlmodel import Session, select
|
from sqlmodel import Session, select
|
||||||
|
|
||||||
from trading_journal import models
|
from trading_journal import models
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Mapping
|
||||||
|
|
||||||
def _check_enum(enum_cls, value, field_name: str):
|
|
||||||
|
def _check_enum(enum_cls: any, value: any, field_name: str) -> any:
|
||||||
if value is None:
|
if value is None:
|
||||||
raise ValueError(f"{field_name} is required")
|
raise ValueError(f"{field_name} is required")
|
||||||
# already an enum member
|
# already an enum member
|
||||||
@@ -34,19 +39,13 @@ def create_trade(session: Session, trade_data: Mapping) -> models.Trades:
|
|||||||
raise ValueError("symbol is required")
|
raise ValueError("symbol is required")
|
||||||
if "underlying_currency" not in payload:
|
if "underlying_currency" not in payload:
|
||||||
raise ValueError("underlying_currency is required")
|
raise ValueError("underlying_currency is required")
|
||||||
payload["underlying_currency"] = _check_enum(
|
payload["underlying_currency"] = _check_enum(models.UnderlyingCurrency, payload["underlying_currency"], "underlying_currency")
|
||||||
models.UnderlyingCurrency, payload["underlying_currency"], "underlying_currency"
|
|
||||||
)
|
|
||||||
if "trade_type" not in payload:
|
if "trade_type" not in payload:
|
||||||
raise ValueError("trade_type is required")
|
raise ValueError("trade_type is required")
|
||||||
payload["trade_type"] = _check_enum(
|
payload["trade_type"] = _check_enum(models.TradeType, payload["trade_type"], "trade_type")
|
||||||
models.TradeType, payload["trade_type"], "trade_type"
|
|
||||||
)
|
|
||||||
if "trade_strategy" not in payload:
|
if "trade_strategy" not in payload:
|
||||||
raise ValueError("trade_strategy is required")
|
raise ValueError("trade_strategy is required")
|
||||||
payload["trade_strategy"] = _check_enum(
|
payload["trade_strategy"] = _check_enum(models.TradeStrategy, payload["trade_strategy"], "trade_strategy")
|
||||||
models.TradeStrategy, payload["trade_strategy"], "trade_strategy"
|
|
||||||
)
|
|
||||||
# trade_time_utc is the creation moment: always set to now (caller shouldn't provide)
|
# trade_time_utc is the creation moment: always set to now (caller shouldn't provide)
|
||||||
now = datetime.now(timezone.utc)
|
now = datetime.now(timezone.utc)
|
||||||
payload.pop("trade_time_utc", None)
|
payload.pop("trade_time_utc", None)
|
||||||
@@ -67,9 +66,7 @@ def create_trade(session: Session, trade_data: Mapping) -> models.Trades:
|
|||||||
if "gross_cash_flow_cents" not in payload:
|
if "gross_cash_flow_cents" not in payload:
|
||||||
payload["gross_cash_flow_cents"] = -quantity * price_cents
|
payload["gross_cash_flow_cents"] = -quantity * price_cents
|
||||||
if "net_cash_flow_cents" not in payload:
|
if "net_cash_flow_cents" not in payload:
|
||||||
payload["net_cash_flow_cents"] = (
|
payload["net_cash_flow_cents"] = payload["gross_cash_flow_cents"] - commission_cents
|
||||||
payload["gross_cash_flow_cents"] - commission_cents
|
|
||||||
)
|
|
||||||
|
|
||||||
# If no cycle_id provided, create Cycle instance but don't call create_cycle()
|
# If no cycle_id provided, create Cycle instance but don't call create_cycle()
|
||||||
created_cycle = None
|
created_cycle = None
|
||||||
@@ -78,8 +75,7 @@ def create_trade(session: Session, trade_data: Mapping) -> models.Trades:
|
|||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
"symbol": payload["symbol"],
|
"symbol": payload["symbol"],
|
||||||
"underlying_currency": payload["underlying_currency"],
|
"underlying_currency": payload["underlying_currency"],
|
||||||
"friendly_name": "Auto-created Cycle by trade "
|
"friendly_name": "Auto-created Cycle by trade " + payload.get("friendly_name", ""),
|
||||||
+ payload.get("friendly_name", ""),
|
|
||||||
"status": models.CycleStatus.OPEN,
|
"status": models.CycleStatus.OPEN,
|
||||||
"start_date": payload["trade_date"],
|
"start_date": payload["trade_date"],
|
||||||
}
|
}
|
||||||
@@ -92,9 +88,8 @@ def create_trade(session: Session, trade_data: Mapping) -> models.Trades:
|
|||||||
cycle = session.get(models.Cycles, cycle_id)
|
cycle = session.get(models.Cycles, cycle_id)
|
||||||
if cycle is None:
|
if cycle is None:
|
||||||
raise ValueError("cycle_id does not exist")
|
raise ValueError("cycle_id does not exist")
|
||||||
else:
|
if cycle.user_id != user_id:
|
||||||
if cycle.user_id != user_id:
|
raise ValueError("cycle.user_id does not match trade.user_id")
|
||||||
raise ValueError("cycle.user_id does not match trade.user_id")
|
|
||||||
|
|
||||||
# Build trade instance; if we created a Cycle instance, link via relationship so a single flush will persist both and populate ids
|
# Build trade instance; if we created a Cycle instance, link via relationship so a single flush will persist both and populate ids
|
||||||
t_payload = dict(payload)
|
t_payload = dict(payload)
|
||||||
@@ -119,9 +114,7 @@ def get_trade_by_id(session: Session, trade_id: int) -> models.Trades | None:
|
|||||||
return session.get(models.Trades, trade_id)
|
return session.get(models.Trades, trade_id)
|
||||||
|
|
||||||
|
|
||||||
def get_trade_by_user_id_and_friendly_name(
|
def get_trade_by_user_id_and_friendly_name(session: Session, user_id: int, friendly_name: str) -> models.Trades | None:
|
||||||
session: Session, user_id: int, friendly_name: str
|
|
||||||
) -> models.Trades | None:
|
|
||||||
statement = select(models.Trades).where(
|
statement = select(models.Trades).where(
|
||||||
models.Trades.user_id == user_id,
|
models.Trades.user_id == user_id,
|
||||||
models.Trades.friendly_name == friendly_name,
|
models.Trades.friendly_name == friendly_name,
|
||||||
@@ -169,17 +162,14 @@ def invalidate_trade(session: Session, trade_id: int) -> models.Trades:
|
|||||||
return trade
|
return trade
|
||||||
|
|
||||||
|
|
||||||
def replace_trade(
|
def replace_trade(session: Session, old_trade_id: int, new_trade_data: Mapping) -> models.Trades:
|
||||||
session: Session, old_trade_id: int, new_trade_data: Mapping
|
|
||||||
) -> models.Trades:
|
|
||||||
invalidate_trade(session, old_trade_id)
|
invalidate_trade(session, old_trade_id)
|
||||||
if hasattr(new_trade_data, "dict"):
|
if hasattr(new_trade_data, "dict"):
|
||||||
data = new_trade_data.dict(exclude_unset=True)
|
data = new_trade_data.dict(exclude_unset=True)
|
||||||
else:
|
else:
|
||||||
data = dict(new_trade_data)
|
data = dict(new_trade_data)
|
||||||
data["replaced_by_trade_id"] = old_trade_id
|
data["replaced_by_trade_id"] = old_trade_id
|
||||||
new_trade = create_trade(session, data)
|
return create_trade(session, data)
|
||||||
return new_trade
|
|
||||||
|
|
||||||
|
|
||||||
# Cycles
|
# Cycles
|
||||||
@@ -196,9 +186,7 @@ def create_cycle(session: Session, cycle_data: Mapping) -> models.Cycles:
|
|||||||
raise ValueError("symbol is required")
|
raise ValueError("symbol is required")
|
||||||
if "underlying_currency" not in payload:
|
if "underlying_currency" not in payload:
|
||||||
raise ValueError("underlying_currency is required")
|
raise ValueError("underlying_currency is required")
|
||||||
payload["underlying_currency"] = _check_enum(
|
payload["underlying_currency"] = _check_enum(models.UnderlyingCurrency, payload["underlying_currency"], "underlying_currency")
|
||||||
models.UnderlyingCurrency, payload["underlying_currency"], "underlying_currency"
|
|
||||||
)
|
|
||||||
if "status" not in payload:
|
if "status" not in payload:
|
||||||
raise ValueError("status is required")
|
raise ValueError("status is required")
|
||||||
payload["status"] = _check_enum(models.CycleStatus, payload["status"], "status")
|
payload["status"] = _check_enum(models.CycleStatus, payload["status"], "status")
|
||||||
@@ -219,9 +207,7 @@ def create_cycle(session: Session, cycle_data: Mapping) -> models.Cycles:
|
|||||||
IMMUTABLE_CYCLE_FIELDS = {"id", "user_id", "start_date", "created_at"}
|
IMMUTABLE_CYCLE_FIELDS = {"id", "user_id", "start_date", "created_at"}
|
||||||
|
|
||||||
|
|
||||||
def update_cycle(
|
def update_cycle(session: Session, cycle_id: int, update_data: Mapping) -> models.Cycles:
|
||||||
session: Session, cycle_id: int, update_data: Mapping
|
|
||||||
) -> models.Cycles:
|
|
||||||
cycle: models.Cycles | None = session.get(models.Cycles, cycle_id)
|
cycle: models.Cycles | None = session.get(models.Cycles, cycle_id)
|
||||||
if cycle is None:
|
if cycle is None:
|
||||||
raise ValueError("cycle_id does not exist")
|
raise ValueError("cycle_id does not exist")
|
||||||
@@ -237,9 +223,9 @@ def update_cycle(
|
|||||||
if k not in allowed:
|
if k not in allowed:
|
||||||
continue
|
continue
|
||||||
if k == "underlying_currency":
|
if k == "underlying_currency":
|
||||||
v = _check_enum(models.UnderlyingCurrency, v, "underlying_currency")
|
v = _check_enum(models.UnderlyingCurrency, v, "underlying_currency") # noqa: PLW2901
|
||||||
if k == "status":
|
if k == "status":
|
||||||
v = _check_enum(models.CycleStatus, v, "status")
|
v = _check_enum(models.CycleStatus, v, "status") # noqa: PLW2901
|
||||||
setattr(cycle, k, v)
|
setattr(cycle, k, v)
|
||||||
session.add(cycle)
|
session.add(cycle)
|
||||||
try:
|
try:
|
||||||
@@ -337,9 +323,7 @@ def create_login_session(
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
def get_login_session_by_token_hash_and_user_id(
|
def get_login_session_by_token_hash_and_user_id(session: Session, session_token_hash: str, user_id: int) -> models.Sessions | None:
|
||||||
session: Session, session_token_hash: str, user_id: int
|
|
||||||
) -> models.Sessions | None:
|
|
||||||
statement = select(models.Sessions).where(
|
statement = select(models.Sessions).where(
|
||||||
models.Sessions.session_token_hash == session_token_hash,
|
models.Sessions.session_token_hash == session_token_hash,
|
||||||
models.Sessions.user_id == user_id,
|
models.Sessions.user_id == user_id,
|
||||||
@@ -352,14 +336,12 @@ def get_login_session_by_token_hash_and_user_id(
|
|||||||
IMMUTABLE_SESSION_FIELDS = {"id", "user_id", "session_token_hash", "created_at"}
|
IMMUTABLE_SESSION_FIELDS = {"id", "user_id", "session_token_hash", "created_at"}
|
||||||
|
|
||||||
|
|
||||||
def update_login_session(
|
def update_login_session(session: Session, session_token_hashed: str, update_session: Mapping) -> models.Sessions | None:
|
||||||
session: Session, session_token_hashed: str, update_session: Mapping
|
|
||||||
) -> models.Sessions | None:
|
|
||||||
login_session: models.Sessions | None = session.exec(
|
login_session: models.Sessions | None = session.exec(
|
||||||
select(models.Sessions).where(
|
select(models.Sessions).where(
|
||||||
models.Sessions.session_token_hash == session_token_hashed,
|
models.Sessions.session_token_hash == session_token_hashed,
|
||||||
models.Sessions.expires_at > datetime.now(timezone.utc),
|
models.Sessions.expires_at > datetime.now(timezone.utc),
|
||||||
)
|
),
|
||||||
).first()
|
).first()
|
||||||
if login_session is None:
|
if login_session is None:
|
||||||
return None
|
return None
|
||||||
@@ -385,7 +367,7 @@ def delete_login_session(session: Session, session_token_hash: str) -> None:
|
|||||||
login_session: models.Sessions | None = session.exec(
|
login_session: models.Sessions | None = session.exec(
|
||||||
select(models.Sessions).where(
|
select(models.Sessions).where(
|
||||||
models.Sessions.session_token_hash == session_token_hash,
|
models.Sessions.session_token_hash == session_token_hash,
|
||||||
)
|
),
|
||||||
).first()
|
).first()
|
||||||
if login_session is None:
|
if login_session is None:
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -24,17 +24,13 @@ class Database:
|
|||||||
) -> None:
|
) -> None:
|
||||||
self._database_url = database_url or "sqlite:///:memory:"
|
self._database_url = database_url or "sqlite:///:memory:"
|
||||||
|
|
||||||
default_connect = (
|
default_connect = {"check_same_thread": False, "timeout": 30} if self._database_url.startswith("sqlite") else {}
|
||||||
{"check_same_thread": False, "timeout": 30}
|
|
||||||
if self._database_url.startswith("sqlite")
|
|
||||||
else {}
|
|
||||||
)
|
|
||||||
merged_connect = {**default_connect, **(connect_args or {})}
|
merged_connect = {**default_connect, **(connect_args or {})}
|
||||||
|
|
||||||
if self._database_url == "sqlite:///:memory:":
|
if self._database_url == "sqlite:///:memory:":
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Using in-memory SQLite database; all data will be lost when the application stops."
|
"Using in-memory SQLite database; all data will be lost when the application stops.",
|
||||||
)
|
)
|
||||||
self._engine = create_engine(
|
self._engine = create_engine(
|
||||||
self._database_url,
|
self._database_url,
|
||||||
@@ -43,15 +39,11 @@ class Database:
|
|||||||
poolclass=StaticPool,
|
poolclass=StaticPool,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self._engine = create_engine(
|
self._engine = create_engine(self._database_url, echo=echo, connect_args=merged_connect)
|
||||||
self._database_url, echo=echo, connect_args=merged_connect
|
|
||||||
)
|
|
||||||
|
|
||||||
if self._database_url.startswith("sqlite"):
|
if self._database_url.startswith("sqlite"):
|
||||||
|
|
||||||
def _enable_sqlite_pragmas(
|
def _enable_sqlite_pragmas(dbapi_conn: DBAPIConnection, _connection_record: object) -> None:
|
||||||
dbapi_conn: DBAPIConnection, _connection_record: object
|
|
||||||
) -> None:
|
|
||||||
try:
|
try:
|
||||||
cur = dbapi_conn.cursor()
|
cur = dbapi_conn.cursor()
|
||||||
cur.execute("PRAGMA journal_mode=WAL;")
|
cur.execute("PRAGMA journal_mode=WAL;")
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ def run_migrations(engine: Engine, target_version: int | None = None) -> int:
|
|||||||
fn = MIGRATIONS.get(cur_version)
|
fn = MIGRATIONS.get(cur_version)
|
||||||
if fn is None:
|
if fn is None:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"No migration from {cur_version} -> {cur_version + 1}"
|
f"No migration from {cur_version} -> {cur_version + 1}",
|
||||||
)
|
)
|
||||||
# call migration with Engine (fn should use transactions)
|
# call migration with Engine (fn should use transactions)
|
||||||
fn(engine)
|
fn(engine)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from datetime import date, datetime # noqa: TC003
|
from datetime import date, datetime
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from sqlmodel import (
|
from sqlmodel import (
|
||||||
@@ -65,28 +65,18 @@ class FundingSource(str, Enum):
|
|||||||
|
|
||||||
class Trades(SQLModel, table=True):
|
class Trades(SQLModel, table=True):
|
||||||
__tablename__ = "trades"
|
__tablename__ = "trades"
|
||||||
__table_args__ = (
|
__table_args__ = (UniqueConstraint("user_id", "friendly_name", name="uq_trades_user_friendly_name"),)
|
||||||
UniqueConstraint(
|
|
||||||
"user_id", "friendly_name", name="uq_trades_user_friendly_name"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
id: int | None = Field(default=None, primary_key=True)
|
id: int | None = Field(default=None, primary_key=True)
|
||||||
user_id: int = Field(foreign_key="users.id", nullable=False, index=True)
|
user_id: int = Field(foreign_key="users.id", nullable=False, index=True)
|
||||||
# allow null while user may omit friendly_name; uniqueness enforced per-user by constraint
|
# allow null while user may omit friendly_name; uniqueness enforced per-user by constraint
|
||||||
friendly_name: str | None = Field(
|
friendly_name: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
||||||
default=None, sa_column=Column(Text, nullable=True)
|
|
||||||
)
|
|
||||||
symbol: str = Field(sa_column=Column(Text, nullable=False))
|
symbol: str = Field(sa_column=Column(Text, nullable=False))
|
||||||
underlying_currency: UnderlyingCurrency = Field(
|
underlying_currency: UnderlyingCurrency = Field(sa_column=Column(Text, nullable=False))
|
||||||
sa_column=Column(Text, nullable=False)
|
|
||||||
)
|
|
||||||
trade_type: TradeType = Field(sa_column=Column(Text, nullable=False))
|
trade_type: TradeType = Field(sa_column=Column(Text, nullable=False))
|
||||||
trade_strategy: TradeStrategy = Field(sa_column=Column(Text, nullable=False))
|
trade_strategy: TradeStrategy = Field(sa_column=Column(Text, nullable=False))
|
||||||
trade_date: date = Field(sa_column=Column(Date, nullable=False))
|
trade_date: date = Field(sa_column=Column(Date, nullable=False))
|
||||||
trade_time_utc: datetime = Field(
|
trade_time_utc: datetime = Field(sa_column=Column(DateTime(timezone=True), nullable=False))
|
||||||
sa_column=Column(DateTime(timezone=True), nullable=False)
|
|
||||||
)
|
|
||||||
expiry_date: date | None = Field(default=None, nullable=True)
|
expiry_date: date | None = Field(default=None, nullable=True)
|
||||||
strike_price_cents: int | None = Field(default=None, nullable=True)
|
strike_price_cents: int | None = Field(default=None, nullable=True)
|
||||||
quantity: int = Field(sa_column=Column(Integer, nullable=False))
|
quantity: int = Field(sa_column=Column(Integer, nullable=False))
|
||||||
@@ -95,36 +85,22 @@ class Trades(SQLModel, table=True):
|
|||||||
commission_cents: int = Field(sa_column=Column(Integer, nullable=False))
|
commission_cents: int = Field(sa_column=Column(Integer, nullable=False))
|
||||||
net_cash_flow_cents: int = Field(sa_column=Column(Integer, nullable=False))
|
net_cash_flow_cents: int = Field(sa_column=Column(Integer, nullable=False))
|
||||||
is_invalidated: bool = Field(default=False, nullable=False)
|
is_invalidated: bool = Field(default=False, nullable=False)
|
||||||
invalidated_at: datetime | None = Field(
|
invalidated_at: datetime | None = Field(default=None, sa_column=Column(DateTime(timezone=True), nullable=True))
|
||||||
default=None, sa_column=Column(DateTime(timezone=True), nullable=True)
|
replaced_by_trade_id: int | None = Field(default=None, foreign_key="trades.id", nullable=True)
|
||||||
)
|
|
||||||
replaced_by_trade_id: int | None = Field(
|
|
||||||
default=None, foreign_key="trades.id", nullable=True
|
|
||||||
)
|
|
||||||
notes: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
notes: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
||||||
cycle_id: int | None = Field(
|
cycle_id: int | None = Field(default=None, foreign_key="cycles.id", nullable=True, index=True)
|
||||||
default=None, foreign_key="cycles.id", nullable=True, index=True
|
|
||||||
)
|
|
||||||
cycle: "Cycles" = Relationship(back_populates="trades")
|
cycle: "Cycles" = Relationship(back_populates="trades")
|
||||||
|
|
||||||
|
|
||||||
class Cycles(SQLModel, table=True):
|
class Cycles(SQLModel, table=True):
|
||||||
__tablename__ = "cycles"
|
__tablename__ = "cycles"
|
||||||
__table_args__ = (
|
__table_args__ = (UniqueConstraint("user_id", "friendly_name", name="uq_cycles_user_friendly_name"),)
|
||||||
UniqueConstraint(
|
|
||||||
"user_id", "friendly_name", name="uq_cycles_user_friendly_name"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
id: int | None = Field(default=None, primary_key=True)
|
id: int | None = Field(default=None, primary_key=True)
|
||||||
user_id: int = Field(foreign_key="users.id", nullable=False, index=True)
|
user_id: int = Field(foreign_key="users.id", nullable=False, index=True)
|
||||||
friendly_name: str | None = Field(
|
friendly_name: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
||||||
default=None, sa_column=Column(Text, nullable=True)
|
|
||||||
)
|
|
||||||
symbol: str = Field(sa_column=Column(Text, nullable=False))
|
symbol: str = Field(sa_column=Column(Text, nullable=False))
|
||||||
underlying_currency: UnderlyingCurrency = Field(
|
underlying_currency: UnderlyingCurrency = Field(sa_column=Column(Text, nullable=False))
|
||||||
sa_column=Column(Text, nullable=False)
|
|
||||||
)
|
|
||||||
status: CycleStatus = Field(sa_column=Column(Text, nullable=False))
|
status: CycleStatus = Field(sa_column=Column(Text, nullable=False))
|
||||||
funding_source: FundingSource = Field(sa_column=Column(Text, nullable=True))
|
funding_source: FundingSource = Field(sa_column=Column(Text, nullable=True))
|
||||||
capital_exposure_cents: int | None = Field(default=None, nullable=True)
|
capital_exposure_cents: int | None = Field(default=None, nullable=True)
|
||||||
@@ -149,17 +125,9 @@ class Sessions(SQLModel, table=True):
|
|||||||
id: int | None = Field(default=None, primary_key=True)
|
id: int | None = Field(default=None, primary_key=True)
|
||||||
user_id: int = Field(foreign_key="users.id", nullable=False, index=True)
|
user_id: int = Field(foreign_key="users.id", nullable=False, index=True)
|
||||||
session_token_hash: str = Field(sa_column=Column(Text, nullable=False, unique=True))
|
session_token_hash: str = Field(sa_column=Column(Text, nullable=False, unique=True))
|
||||||
created_at: datetime = Field(
|
created_at: datetime = Field(sa_column=Column(DateTime(timezone=True), nullable=False))
|
||||||
sa_column=Column(DateTime(timezone=True), nullable=False)
|
expires_at: datetime = Field(sa_column=Column(DateTime(timezone=True), nullable=False, index=True))
|
||||||
)
|
last_seen_at: datetime | None = Field(sa_column=Column(DateTime(timezone=True), nullable=True))
|
||||||
expires_at: datetime = Field(
|
last_used_ip: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
||||||
sa_column=Column(DateTime(timezone=True), nullable=False, index=True)
|
|
||||||
)
|
|
||||||
last_seen_at: datetime | None = Field(
|
|
||||||
sa_column=Column(DateTime(timezone=True), nullable=True)
|
|
||||||
)
|
|
||||||
last_used_ip: str | None = Field(
|
|
||||||
default=None, sa_column=Column(Text, nullable=True)
|
|
||||||
)
|
|
||||||
user_agent: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
user_agent: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
||||||
device_name: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
device_name: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from datetime import date, datetime # noqa: TC003
|
from datetime import date, datetime
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from sqlmodel import (
|
from sqlmodel import (
|
||||||
@@ -65,28 +65,18 @@ class FundingSource(str, Enum):
|
|||||||
|
|
||||||
class Trades(SQLModel, table=True):
|
class Trades(SQLModel, table=True):
|
||||||
__tablename__ = "trades"
|
__tablename__ = "trades"
|
||||||
__table_args__ = (
|
__table_args__ = (UniqueConstraint("user_id", "friendly_name", name="uq_trades_user_friendly_name"),)
|
||||||
UniqueConstraint(
|
|
||||||
"user_id", "friendly_name", name="uq_trades_user_friendly_name"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
id: int | None = Field(default=None, primary_key=True)
|
id: int | None = Field(default=None, primary_key=True)
|
||||||
user_id: int = Field(foreign_key="users.id", nullable=False, index=True)
|
user_id: int = Field(foreign_key="users.id", nullable=False, index=True)
|
||||||
# allow null while user may omit friendly_name; uniqueness enforced per-user by constraint
|
# allow null while user may omit friendly_name; uniqueness enforced per-user by constraint
|
||||||
friendly_name: str | None = Field(
|
friendly_name: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
||||||
default=None, sa_column=Column(Text, nullable=True)
|
|
||||||
)
|
|
||||||
symbol: str = Field(sa_column=Column(Text, nullable=False))
|
symbol: str = Field(sa_column=Column(Text, nullable=False))
|
||||||
underlying_currency: UnderlyingCurrency = Field(
|
underlying_currency: UnderlyingCurrency = Field(sa_column=Column(Text, nullable=False))
|
||||||
sa_column=Column(Text, nullable=False)
|
|
||||||
)
|
|
||||||
trade_type: TradeType = Field(sa_column=Column(Text, nullable=False))
|
trade_type: TradeType = Field(sa_column=Column(Text, nullable=False))
|
||||||
trade_strategy: TradeStrategy = Field(sa_column=Column(Text, nullable=False))
|
trade_strategy: TradeStrategy = Field(sa_column=Column(Text, nullable=False))
|
||||||
trade_date: date = Field(sa_column=Column(Date, nullable=False))
|
trade_date: date = Field(sa_column=Column(Date, nullable=False))
|
||||||
trade_time_utc: datetime = Field(
|
trade_time_utc: datetime = Field(sa_column=Column(DateTime(timezone=True), nullable=False))
|
||||||
sa_column=Column(DateTime(timezone=True), nullable=False)
|
|
||||||
)
|
|
||||||
expiry_date: date | None = Field(default=None, nullable=True)
|
expiry_date: date | None = Field(default=None, nullable=True)
|
||||||
strike_price_cents: int | None = Field(default=None, nullable=True)
|
strike_price_cents: int | None = Field(default=None, nullable=True)
|
||||||
quantity: int = Field(sa_column=Column(Integer, nullable=False))
|
quantity: int = Field(sa_column=Column(Integer, nullable=False))
|
||||||
@@ -95,36 +85,22 @@ class Trades(SQLModel, table=True):
|
|||||||
commission_cents: int = Field(sa_column=Column(Integer, nullable=False))
|
commission_cents: int = Field(sa_column=Column(Integer, nullable=False))
|
||||||
net_cash_flow_cents: int = Field(sa_column=Column(Integer, nullable=False))
|
net_cash_flow_cents: int = Field(sa_column=Column(Integer, nullable=False))
|
||||||
is_invalidated: bool = Field(default=False, nullable=False)
|
is_invalidated: bool = Field(default=False, nullable=False)
|
||||||
invalidated_at: datetime | None = Field(
|
invalidated_at: datetime | None = Field(default=None, sa_column=Column(DateTime(timezone=True), nullable=True))
|
||||||
default=None, sa_column=Column(DateTime(timezone=True), nullable=True)
|
replaced_by_trade_id: int | None = Field(default=None, foreign_key="trades.id", nullable=True)
|
||||||
)
|
|
||||||
replaced_by_trade_id: int | None = Field(
|
|
||||||
default=None, foreign_key="trades.id", nullable=True
|
|
||||||
)
|
|
||||||
notes: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
notes: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
||||||
cycle_id: int | None = Field(
|
cycle_id: int | None = Field(default=None, foreign_key="cycles.id", nullable=True, index=True)
|
||||||
default=None, foreign_key="cycles.id", nullable=True, index=True
|
|
||||||
)
|
|
||||||
cycle: "Cycles" = Relationship(back_populates="trades")
|
cycle: "Cycles" = Relationship(back_populates="trades")
|
||||||
|
|
||||||
|
|
||||||
class Cycles(SQLModel, table=True):
|
class Cycles(SQLModel, table=True):
|
||||||
__tablename__ = "cycles"
|
__tablename__ = "cycles"
|
||||||
__table_args__ = (
|
__table_args__ = (UniqueConstraint("user_id", "friendly_name", name="uq_cycles_user_friendly_name"),)
|
||||||
UniqueConstraint(
|
|
||||||
"user_id", "friendly_name", name="uq_cycles_user_friendly_name"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
id: int | None = Field(default=None, primary_key=True)
|
id: int | None = Field(default=None, primary_key=True)
|
||||||
user_id: int = Field(foreign_key="users.id", nullable=False, index=True)
|
user_id: int = Field(foreign_key="users.id", nullable=False, index=True)
|
||||||
friendly_name: str | None = Field(
|
friendly_name: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
||||||
default=None, sa_column=Column(Text, nullable=True)
|
|
||||||
)
|
|
||||||
symbol: str = Field(sa_column=Column(Text, nullable=False))
|
symbol: str = Field(sa_column=Column(Text, nullable=False))
|
||||||
underlying_currency: UnderlyingCurrency = Field(
|
underlying_currency: UnderlyingCurrency = Field(sa_column=Column(Text, nullable=False))
|
||||||
sa_column=Column(Text, nullable=False)
|
|
||||||
)
|
|
||||||
status: CycleStatus = Field(sa_column=Column(Text, nullable=False))
|
status: CycleStatus = Field(sa_column=Column(Text, nullable=False))
|
||||||
funding_source: FundingSource = Field(sa_column=Column(Text, nullable=True))
|
funding_source: FundingSource = Field(sa_column=Column(Text, nullable=True))
|
||||||
capital_exposure_cents: int | None = Field(default=None, nullable=True)
|
capital_exposure_cents: int | None = Field(default=None, nullable=True)
|
||||||
@@ -149,17 +125,9 @@ class Sessions(SQLModel, table=True):
|
|||||||
id: int | None = Field(default=None, primary_key=True)
|
id: int | None = Field(default=None, primary_key=True)
|
||||||
user_id: int = Field(foreign_key="users.id", nullable=False, index=True)
|
user_id: int = Field(foreign_key="users.id", nullable=False, index=True)
|
||||||
session_token_hash: str = Field(sa_column=Column(Text, nullable=False, unique=True))
|
session_token_hash: str = Field(sa_column=Column(Text, nullable=False, unique=True))
|
||||||
created_at: datetime = Field(
|
created_at: datetime = Field(sa_column=Column(DateTime(timezone=True), nullable=False))
|
||||||
sa_column=Column(DateTime(timezone=True), nullable=False)
|
expires_at: datetime = Field(sa_column=Column(DateTime(timezone=True), nullable=False, index=True))
|
||||||
)
|
last_seen_at: datetime | None = Field(sa_column=Column(DateTime(timezone=True), nullable=True))
|
||||||
expires_at: datetime = Field(
|
last_used_ip: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
||||||
sa_column=Column(DateTime(timezone=True), nullable=False, index=True)
|
|
||||||
)
|
|
||||||
last_seen_at: datetime | None = Field(
|
|
||||||
sa_column=Column(DateTime(timezone=True), nullable=True)
|
|
||||||
)
|
|
||||||
last_used_ip: str | None = Field(
|
|
||||||
default=None, sa_column=Column(Text, nullable=True)
|
|
||||||
)
|
|
||||||
user_agent: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
user_agent: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
||||||
device_name: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
device_name: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
||||||
|
|||||||
Reference in New Issue
Block a user