|
| 1 | +import sys |
| 2 | +import os |
| 3 | + |
| 4 | +sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) |
| 5 | + |
| 6 | +from fastapi.testclient import TestClient |
| 7 | +from unittest.mock import patch |
| 8 | + |
| 9 | +from main import app |
| 10 | +from models import Resort |
| 11 | + |
| 12 | +FAKE_RESORTS = [ |
| 13 | + Resort( |
| 14 | + resort_id='abc-123', |
| 15 | + name='Vail', |
| 16 | + region='West', |
| 17 | + city='Vail', |
| 18 | + state='CO', |
| 19 | + country='USA', |
| 20 | + reservation_status='required', |
| 21 | + indy_page='https://example.com/vail', |
| 22 | + ), |
| 23 | + Resort( |
| 24 | + resort_id='def-456', |
| 25 | + name='Stowe', |
| 26 | + region='Northeast', |
| 27 | + city='Stowe', |
| 28 | + state='VT', |
| 29 | + country='USA', |
| 30 | + reservation_status='none', |
| 31 | + indy_page='https://example.com/stowe', |
| 32 | + ), |
| 33 | +] |
| 34 | + |
| 35 | +client = TestClient(app) |
| 36 | + |
| 37 | + |
| 38 | +def test_get_resort_by_id_returns_resort(): |
| 39 | + with patch('main._resorts', FAKE_RESORTS): |
| 40 | + response = client.get('/resorts/abc-123') |
| 41 | + assert response.status_code == 200 |
| 42 | + data = response.json() |
| 43 | + assert data['resort_id'] == 'abc-123' |
| 44 | + assert data['name'] == 'Vail' |
| 45 | + |
| 46 | + |
| 47 | +def test_get_resort_by_id_returns_full_model(): |
| 48 | + with patch('main._resorts', FAKE_RESORTS): |
| 49 | + response = client.get('/resorts/def-456') |
| 50 | + assert response.status_code == 200 |
| 51 | + data = response.json() |
| 52 | + assert data['resort_id'] == 'def-456' |
| 53 | + assert data['state'] == 'VT' |
| 54 | + |
| 55 | + |
| 56 | +def test_get_resort_by_id_not_found(): |
| 57 | + with patch('main._resorts', FAKE_RESORTS): |
| 58 | + response = client.get('/resorts/nonexistent-uuid') |
| 59 | + assert response.status_code == 404 |
0 commit comments