2026년 7월 21일 화요일

test_curl.py



import pytest
import rust_curl  # 빌드된 러스트 모듈 이름


# 비동기 함수(async def)를 테스트할 때 필수적인 데코레이터
@pytest.mark.asyncio
async def test_curl_get_success():
  # Given: 테스트할 URL 설정 (httpbin은 테스트용 무료 레디메이드 API입니다)
  url = "https://httpbin.org"

  # When: 러스트 비동기 함수 호출
  status, text = await rust_curl.curl_async(url, method="GET")

  # Then: pytest는 복잡한 메서드 없이 오직 'assert' 문 하나로 검증합니다
  assert status == 200
  assert "httpbin.org" in text


@pytest.mark.asyncio
async def test_curl_invalid_url():
  # 잘못된 URL을 넣었을 때 러스트가 에러(RuntimeError)를 잘 뱉는지 검증
  url = "https://this-is-invalid-url-12345.com"

  with pytest.raises(RuntimeError) as exc_info:
    await rust_curl.curl_async(url)

  # 에러 메시지에 우리가 러스트에 적은 문구가 포함되어 있는지 확인
  assert "Request failed" in str(exc_info.value)


database.py

import os from contextlib import contextmanager # contextmanager 임포트 from typing import Generator from dotenv...