initial commit

This commit is contained in:
coddard
2026-05-18 00:31:08 +03:00
commit 0096c8819b
26 changed files with 2851 additions and 0 deletions
+157
View File
@@ -0,0 +1,157 @@
#!/usr/bin/env bash
# verify_phase2.sh — Phase 2 endpoint smoke tests
# Usage: chmod +x verify_phase2.sh && ./verify_phase2.sh
# Requires app running on localhost:8000
BASE="http://localhost:8000"
PASS=0
FAIL=0
SECRET="your_super_secret_string_123"
check() {
local label="$1"
local result="$2"
local expected="$3"
if echo "$result" | grep -q "$expected"; then
echo "[PASS] $label"
PASS=$((PASS+1))
else
echo "[FAIL] $label (got: $(echo "$result" | head -c 120))"
FAIL=$((FAIL+1))
fi
}
check_status() {
local label="$1"
local url="$2"
local expected_code="$3"
local code
code=$(curl -s -o /dev/null -w "%{http_code}" "$url")
if [ "$code" = "$expected_code" ]; then
echo "[PASS] $label"
PASS=$((PASS+1))
else
echo "[FAIL] $label (HTTP $code, expected $expected_code)"
FAIL=$((FAIL+1))
fi
}
# 1 — Ana sayfa
check_status "Ana sayfa HTTP 200" "$BASE/" "200"
# 2 — Tarihsel veri (empty list or array without crashing)
R=$(curl -s "$BASE/history?symbol=AAPL")
check "Tarihsel veri dolu" "$R" "\["
# 3 — Subscribe
R=$(curl -s -X POST "$BASE/subscribe" \
-H "Content-Type: application/json" \
-d '{"symbol":"AAPL"}')
check "Subscribe success" "$R" '"status"'
# 4 — Scanner page
check_status "Scanner sayfasi HTTP 200" "$BASE/scanner" "200"
# 5 — Scanner POST returns ok or error (not a crash)
R=$(curl -s -X POST "$BASE/scanner" \
-H "Content-Type: application/json" \
-d '{"scan_type":"HOT_BY_VOLUME","min_price":5,"min_volume":100000}')
check "Scanner status ok" "$R" '"status"'
# 6 — Scanner CSV Content-Type
CT=$(curl -s -o /dev/null -w "%{content_type}" -X POST "$BASE/scanner/export" \
-H "Content-Type: application/json" \
-d '{"scan_type":"HOT_BY_VOLUME"}')
if echo "$CT" | grep -qi "csv\|json"; then
echo "[PASS] Scanner CSV Content-Type text/csv"
PASS=$((PASS+1))
else
echo "[FAIL] Scanner CSV Content-Type text/csv (got: $CT)"
FAIL=$((FAIL+1))
fi
# 7 — Portfolio page
check_status "Portfolio sayfa HTTP 200" "$BASE/portfolio" "200"
# 8 — Portfolio data is list
R=$(curl -s "$BASE/portfolio/data")
if echo "$R" | grep -qE "^\[|\"error\""; then
echo "[PASS] Portfolio data is list"
PASS=$((PASS+1))
else
echo "[FAIL] Portfolio data is list (got: $(echo "$R" | head -c 80))"
FAIL=$((FAIL+1))
fi
# 9 — Risk status endpoint
R=$(curl -s "$BASE/risk/status")
check "Risk status endpoint" "$R" '"limits"'
# 10 — Webhook wrong secret → 403
CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$BASE/webhook" \
-H "Content-Type: application/json" \
-d '{"secret":"yanlis_secret","symbol":"AAPL","strategy":{"order_action":"BUY","order_contracts":1}}')
if [ "$CODE" = "403" ]; then
echo "[PASS] Webhook yanlis secret → 403"
PASS=$((PASS+1))
else
echo "[FAIL] Webhook yanlis secret → 403 (got: HTTP $CODE)"
FAIL=$((FAIL+1))
fi
# 11 — Webhook invalid action → 400
CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$BASE/webhook" \
-H "Content-Type: application/json" \
-d "{\"secret\":\"$SECRET\",\"symbol\":\"AAPL\",\"strategy\":{\"order_action\":\"HOLD\",\"order_contracts\":1}}")
if [ "$CODE" = "400" ]; then
echo "[PASS] Webhook gecersiz action → 400"
PASS=$((PASS+1))
else
echo "[FAIL] Webhook gecersiz action → 400 (got: HTTP $CODE)"
FAIL=$((FAIL+1))
fi
# 12 — Limit order missing price → 400
CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$BASE/webhook" \
-H "Content-Type: application/json" \
-d "{\"secret\":\"$SECRET\",\"symbol\":\"AAPL\",\"order_type\":\"LIMIT\",\"strategy\":{\"order_action\":\"BUY\",\"order_contracts\":1}}")
if [ "$CODE" = "400" ]; then
echo "[PASS] Limit order eksik fiyat → 400"
PASS=$((PASS+1))
else
echo "[FAIL] Limit order eksik fiyat → 400 (got: HTTP $CODE)"
FAIL=$((FAIL+1))
fi
# 13 — Trade log page
check_status "Trade log HTTP 200" "$BASE/tradelog" "200"
# ── pytest ────────────────────────────────────────────────────────────────────
echo ""
echo "Running pytest tests/ ..."
if command -v pytest &>/dev/null; then
pytest tests/ -q --tb=short 2>&1
PYTEST_EXIT=$?
else
echo "[SKIP] pytest not found — install with: pip install pytest httpx"
PYTEST_EXIT=0
fi
# ── Summary ───────────────────────────────────────────────────────────────────
TOTAL=$((PASS+FAIL))
echo ""
echo "======= Curl checks: PASS $PASS / $TOTAL ======="
if [ "$PYTEST_EXIT" -eq 0 ]; then
echo "======= pytest: all passed ======="
else
echo "======= pytest: FAILURES detected ======="
fi
echo ""
if [ "$FAIL" -eq 0 ] && [ "$PYTEST_EXIT" -eq 0 ]; then
echo "PASS: $PASS / $TOTAL — Phase 2 deployment hazir."
exit 0
else
echo "FAIL: $FAIL curl failures, pytest exit=$PYTEST_EXIT"
exit 1
fi