File size: 861 Bytes
46efd9c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import pytest
from fastapi.testclient import TestClient
from app.main import app
client = TestClient(app)
def test_extract_metadata_success():
# Attempting to extract from a highly stable site like GitHub
url = "https://github.com"
response = client.get(f"/api/tools/extract-metadata?url={url}")
assert response.status_code == 200
data = response.json()
assert "title" in data
assert "description" in data
assert data["url"] == url
# GitHub usually has 'GitHub' in the title
assert "GitHub" in data["title"]
def test_extract_metadata_invalid_url():
url = "https://this-is-definitely-not-a-real-website-12345.com"
response = client.get(f"/api/tools/extract-metadata?url={url}")
# It should return a 400 since it fails to extract
assert response.status_code == 400
assert "detail" in response.json()
|