refactor: extract 'bitfinex' and 'BTC/EUR' magic strings to constants
Add SOURCE_BITFINEX and PAIR_BTC_EUR constants in price_fetcher.py and use them consistently in routes/audit.py, worker.py, and tests.
This commit is contained in:
parent
dd7bec6091
commit
ec835a2935
4 changed files with 19 additions and 15 deletions
|
|
@ -7,7 +7,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
|||
import pytest
|
||||
|
||||
from models import PriceHistory
|
||||
from price_fetcher import fetch_btc_eur_price
|
||||
from price_fetcher import PAIR_BTC_EUR, SOURCE_BITFINEX, fetch_btc_eur_price
|
||||
from worker import process_bitcoin_price_job
|
||||
|
||||
|
||||
|
|
@ -134,8 +134,8 @@ class TestGetPriceHistory:
|
|||
now = datetime.now(UTC)
|
||||
for i in range(5):
|
||||
record = PriceHistory(
|
||||
source="bitfinex",
|
||||
pair="BTC/EUR",
|
||||
source=SOURCE_BITFINEX,
|
||||
pair=PAIR_BTC_EUR,
|
||||
price=90000.0 + i * 100,
|
||||
timestamp=now.replace(second=i),
|
||||
)
|
||||
|
|
@ -159,8 +159,8 @@ class TestGetPriceHistory:
|
|||
now = datetime.now(UTC)
|
||||
for i in range(25):
|
||||
record = PriceHistory(
|
||||
source="bitfinex",
|
||||
pair="BTC/EUR",
|
||||
source=SOURCE_BITFINEX,
|
||||
pair=PAIR_BTC_EUR,
|
||||
price=90000.0 + i,
|
||||
timestamp=now.replace(microsecond=i),
|
||||
)
|
||||
|
|
@ -209,8 +209,8 @@ class TestManualFetch:
|
|||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["source"] == "bitfinex"
|
||||
assert data["pair"] == "BTC/EUR"
|
||||
assert data["source"] == SOURCE_BITFINEX
|
||||
assert data["pair"] == PAIR_BTC_EUR
|
||||
assert data["price"] == 95123.45
|
||||
assert "id" in data
|
||||
assert "timestamp" in data
|
||||
|
|
@ -280,8 +280,8 @@ class TestProcessBitcoinPriceJob:
|
|||
call_args = mock_conn.execute.call_args
|
||||
|
||||
# Check the SQL parameters
|
||||
assert call_args[0][1] == "bitfinex" # source
|
||||
assert call_args[0][2] == "BTC/EUR" # pair
|
||||
assert call_args[0][1] == SOURCE_BITFINEX # source
|
||||
assert call_args[0][2] == PAIR_BTC_EUR # pair
|
||||
assert call_args[0][3] == 95000.0 # price
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue