110 lines
3.6 KiB
Python
110 lines
3.6 KiB
Python
import requests
|
|
import json
|
|
from datetime import datetime, timezone
|
|
import uuid
|
|
import random
|
|
import string
|
|
import time
|
|
|
|
# Supabase 설정
|
|
SUPABASE_URL = "http://146.56.101.199:8000"
|
|
SUPABASE_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlzcyI6InN1cGFiYXNlLWRlbW8iLCJpYXQiOjE2NDE3NjkyMDAsImV4cCI6MTc5OTUzNTYwMH0.dc_X5iR_VP_qT0zsiyj_I_OZ2T9FtRU2BBNWN8Bu4GE"
|
|
|
|
# 헤더 설정
|
|
headers = {
|
|
"apikey": SUPABASE_KEY,
|
|
"Content-Type": "application/json",
|
|
"Prefer": "return=representation"
|
|
}
|
|
|
|
print("1. 테스트 사용자 ID 조회 중...")
|
|
|
|
# 테스트용 사용자 이메일 (실제 DB에 있어야 함)
|
|
test_email = "test@example.com"
|
|
|
|
# 사용자 정보 조회
|
|
user_response = requests.get(
|
|
f"{SUPABASE_URL}/rest/v1/users?email=eq.{test_email}",
|
|
headers=headers
|
|
)
|
|
|
|
if user_response.status_code != 200 or not user_response.json():
|
|
print(f"사용자 정보 조회 실패. HTTP 상태 코드: {user_response.status_code}")
|
|
|
|
# 대안으로 admin 계정 사용
|
|
admin_response = requests.get(
|
|
f"{SUPABASE_URL}/rest/v1/users?username=eq.admin",
|
|
headers=headers
|
|
)
|
|
|
|
if admin_response.status_code != 200 or not admin_response.json():
|
|
print("관리자 계정 정보도 조회할 수 없습니다. 첫 번째 사용자 정보 조회 시도...")
|
|
|
|
# 마지막 시도: 첫 번째 사용자 정보 가져오기
|
|
any_user_response = requests.get(
|
|
f"{SUPABASE_URL}/rest/v1/users?limit=1",
|
|
headers=headers
|
|
)
|
|
|
|
if any_user_response.status_code != 200 or not any_user_response.json():
|
|
print("사용자 정보를 조회할 수 없습니다. 종료합니다.")
|
|
exit(1)
|
|
|
|
user_info = any_user_response.json()[0]
|
|
else:
|
|
user_info = admin_response.json()[0]
|
|
else:
|
|
user_info = user_response.json()[0]
|
|
|
|
user_id = user_info.get("id")
|
|
user_email = user_info.get("email", "")
|
|
user_nickname = user_info.get("nickname", "")
|
|
|
|
print(f"사용자 정보 조회 성공. ID: {user_id}, 이메일: {user_email}")
|
|
|
|
# 2. 세션 생성 테스트
|
|
print("\n2. 세션 생성 테스트 중...")
|
|
|
|
# 세션 데이터 생성
|
|
session_data = {
|
|
"user_id": user_id, # 실제 존재하는 사용자 ID
|
|
"device_info": "테스트 디바이스",
|
|
"ip_address": "127.0.0.1",
|
|
"login_time": datetime.now(timezone.utc).isoformat(),
|
|
"last_active_time": datetime.now(timezone.utc).isoformat(),
|
|
"is_active": True,
|
|
"session_token": f"{user_id}_{int(time.time())}",
|
|
"user_email": user_email,
|
|
"user_nickname": user_nickname
|
|
}
|
|
|
|
# 세션 생성 요청
|
|
create_response = requests.post(
|
|
f"{SUPABASE_URL}/rest/v1/user_sessions",
|
|
headers=headers,
|
|
json=session_data
|
|
)
|
|
|
|
print(f"상태 코드: {create_response.status_code}")
|
|
if create_response.status_code == 201:
|
|
session = create_response.json()[0]
|
|
session_id = session.get("id")
|
|
print(f"생성된 세션 ID: {session_id}")
|
|
|
|
# 3. 세션 삭제 테스트
|
|
print("\n3. 세션 삭제 테스트 중...")
|
|
delete_response = requests.delete(
|
|
f"{SUPABASE_URL}/rest/v1/user_sessions?id=eq.{session_id}",
|
|
headers=headers
|
|
)
|
|
|
|
print(f"삭제 상태 코드: {delete_response.status_code}")
|
|
print(f"세션 삭제 {'성공' if delete_response.status_code in (200, 204) else '실패'}")
|
|
else:
|
|
print(f"세션 생성 실패: {create_response.text}")
|
|
# 오류 응답 상세 정보 출력
|
|
try:
|
|
error_details = create_response.json()
|
|
print(f"오류 상세 정보: {json.dumps(error_details, indent=2, ensure_ascii=False)}")
|
|
except:
|
|
print(f"응답: {create_response.text}") |