InnSight-Backend / api /tests /test_endpoints.py
jackonthemike's picture
Initial commit: InnSight scraper backend with Playwright
d77abf8
"""
Tests for hotel and dashboard endpoints
"""
import pytest
class TestDashboardEndpoints:
"""Test dashboard-related endpoints"""
def test_get_dashboard_stats(self, client, auth_headers):
"""Test getting dashboard statistics"""
response = client.get("/api/dashboard/stats", headers=auth_headers)
assert response.status_code == 200
data = response.json()
assert "total_hotels" in data
assert "total_comparisons" in data
def test_get_dashboard_stats_unauthorized(self, client):
"""Test that dashboard stats require authentication"""
response = client.get("/api/dashboard/stats")
assert response.status_code == 401
def test_get_price_trends(self, client, auth_headers):
"""Test getting price trends"""
response = client.get("/api/dashboard/price-trends", headers=auth_headers)
assert response.status_code == 200
data = response.json()
assert "labels" in data
assert "datasets" in data
def test_get_occupancy_data(self, client, auth_headers):
"""Test getting occupancy data"""
response = client.get("/api/dashboard/occupancy", headers=auth_headers)
assert response.status_code == 200
data = response.json()
assert "couple" in data
class TestHotelEndpoints:
"""Test hotel-related endpoints"""
def test_get_hotels_list(self, client, auth_headers):
"""Test getting list of hotels"""
response = client.get("/api/hotels", headers=auth_headers)
assert response.status_code == 200
data = response.json()
assert isinstance(data, list)
def test_get_hotels_unauthorized(self, client):
"""Test that hotel list requires authentication"""
response = client.get("/api/hotels")
assert response.status_code == 401
def test_create_hotel(self, client, auth_headers):
"""Test creating a new hotel"""
response = client.post("/api/hotels",
headers=auth_headers,
json={
"name": "Test Hotel",
"booking_url": "https://booking.com/test",
"website_url": "https://testhotel.com"
}
)
assert response.status_code == 200
data = response.json()
assert data["name"] == "Test Hotel"
assert "id" in data
def test_create_hotel_minimal(self, client, auth_headers):
"""Test creating a hotel with minimal data"""
response = client.post("/api/hotels",
headers=auth_headers,
json={
"name": "Minimal Hotel"
}
)
assert response.status_code == 200
data = response.json()
assert data["name"] == "Minimal Hotel"
class TestComparisonEndpoints:
"""Test price comparison endpoints"""
def test_compare_prices(self, client, auth_headers):
"""Test price comparison endpoint"""
response = client.post("/api/comparisons/compare",
headers=auth_headers,
json={
"hotel_ids": [1, 2],
"check_in": "2026-02-01",
"check_out": "2026-02-03",
"occupancy": "couple"
}
)
assert response.status_code == 200
data = response.json()
assert "results" in data
assert isinstance(data["results"], list)
def test_compare_prices_unauthorized(self, client):
"""Test that comparison requires authentication"""
response = client.post("/api/comparisons/compare", json={
"hotel_ids": [1, 2],
"check_in": "2026-02-01",
"check_out": "2026-02-03"
})
assert response.status_code == 401
class TestChatEndpoints:
"""Test chatbot endpoints"""
def test_chat_endpoint(self, client, auth_headers):
"""Test chat endpoint returns response"""
response = client.post("/api/chat",
headers=auth_headers,
json={
"message": "שלום, מה השירותים שלכם?"
}
)
assert response.status_code == 200
data = response.json()
assert "response" in data
assert len(data["response"]) > 0
def test_chat_unauthorized(self, client):
"""Test that chat requires authentication"""
response = client.post("/api/chat", json={
"message": "Hello"
})
assert response.status_code == 401