Skip to content

Commit cc7f0fa

Browse files
committed
fix(ci): send Bearer JWT in video integration API test
POST /api/videos/add and GET /api/videos require get_current_user; the test called them without Authorization and returned 401 in GitHub Actions. Made-with: Cursor
1 parent 061df4f commit cc7f0fa

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

backend-python/tests/test_api.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
import uuid
2+
13
import pytest
24
from fastapi.testclient import TestClient
3-
import uuid
45

56
# Import your app from main
7+
from app.api.auth import create_token
68
from app.main import app
79
from app.repository.models import UserModel, VideoModel
810

911
client = TestClient(app)
1012

13+
14+
def _integration_auth_headers() -> dict:
15+
token = create_token("integration_test_user")
16+
return {"Authorization": f"Bearer {token}"}
17+
1118
def test_register_user_actual_db():
1219
unique_username = f"testuser_{uuid.uuid4().hex[:6]}"
1320
response = client.post(
@@ -26,21 +33,23 @@ def test_register_user_actual_db():
2633

2734
def test_add_and_fetch_video_actual_db(db_session):
2835
room_name = "test_integration_room"
29-
30-
# 1. Add a video (This will trigger yt-dlp and actual GCP PubSub if credentials exist)
36+
headers = _integration_auth_headers()
37+
38+
# 1. Add a video (metadata/pubsub may be mocked by conftest)
3139
response = client.post(
3240
"/api/videos/add",
3341
json={
3442
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
35-
"room": room_name
36-
}
43+
"room": room_name,
44+
},
45+
headers=headers,
3746
)
3847
assert response.status_code == 200
3948
added_video = response.json()
4049
assert added_video["video_url"] == "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
41-
50+
4251
# 2. Fetch it back
43-
res_get = client.get(f"/api/videos?room={room_name}")
52+
res_get = client.get(f"/api/videos?room={room_name}", headers=headers)
4453
assert res_get.status_code == 200
4554
videos = res_get.json()
4655
assert len(videos) > 0

0 commit comments

Comments
 (0)