forked from UnBTV/UnB-TV-VideoService
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="0" failures="0" skipped="0" tests="10" time="2.535" timestamp="2024-08-05T02:33:42.345505" hostname="eb7d7d6cc578"><testcase classname="test_favorite" name="test_add_to_favorite" time="0.044" /><testcase classname="test_favorite" name="test_check_favorite" time="0.007" /><testcase classname="test_favorite" name="test_remove_from_favorites" time="0.012" /><testcase classname="test_schedule.TestSchedule" name="test_schedule_get_schedule_day" time="0.842" /><testcase classname="test_schedule.TestSchedule" name="test_schedule_get_schedule_specific_day_invalid" time="0.003" /><testcase classname="test_schedule.TestSchedule" name="test_schedule_get_schedule_specific_day" time="0.562" /><testcase classname="test_schedule.TestSchedule" name="test_schedule_get_schedule_day_exception_handling" time="0.005" /><testcase classname="test_watch_later" name="test_add_to_watch_later" time="0.011" /><testcase classname="test_watch_later" name="test_check_watch_later_status" time="0.006" /><testcase classname="test_watch_later" name="test_remove_from_watch_later" time="0.012" /></testsuite></testsuites> | ||
<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="0" failures="0" skipped="0" tests="12" time="4.369" timestamp="2024-08-09T21:13:03.726607" hostname="aaa8cc6c91a3"><testcase classname="test_favorite" name="test_add_to_favorite" time="0.163" /><testcase classname="test_favorite" name="test_check_favorite" time="0.013" /><testcase classname="test_favorite" name="test_remove_from_favorites" time="0.031" /><testcase classname="test_record" name="test_add_to_record" time="0.025" /><testcase classname="test_record" name="test_check_record" time="0.016" /><testcase classname="test_schedule.TestSchedule" name="test_schedule_get_schedule_day" time="0.688" /><testcase classname="test_schedule.TestSchedule" name="test_schedule_get_schedule_specific_day_invalid" time="0.004" /><testcase classname="test_schedule.TestSchedule" name="test_schedule_get_schedule_specific_day" time="0.606" /><testcase classname="test_schedule.TestSchedule" name="test_schedule_get_schedule_day_exception_handling" time="0.059" /><testcase classname="test_watch_later" name="test_add_to_watch_later" time="0.024" /><testcase classname="test_watch_later" name="test_check_watch_later_status" time="0.013" /><testcase classname="test_watch_later" name="test_remove_from_watch_later" time="0.022" /></testsuite></testsuites> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import pytest, sys, os | ||
|
||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src'))) | ||
|
||
from fastapi.testclient import TestClient | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import sessionmaker | ||
from src.database import Base, get_db | ||
from src.main import app | ||
|
||
# Crie um banco de dados de teste em memória | ||
SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db" | ||
engine = create_engine(SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}) | ||
TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | ||
|
||
# Dependência para usar o banco de dados de teste | ||
def override_get_db(): | ||
try: | ||
db = TestingSessionLocal() | ||
yield db | ||
finally: | ||
db.close() | ||
|
||
app.dependency_overrides[get_db] = override_get_db | ||
|
||
client = TestClient(app) | ||
|
||
@pytest.fixture(scope="module") | ||
def setup_database(): | ||
Base.metadata.create_all(bind=engine) | ||
yield | ||
Base.metadata.drop_all(bind=engine) | ||
|
||
def test_add_to_record(setup_database): | ||
response = client.post("/api/record/", json={"user_id": "user123", "videos": {"video_id": "timestamp"}}) | ||
assert response.status_code == 200 | ||
assert response.json()["user_id"] == "user123" | ||
assert response.json()["videos"] == {"video_id": "timestamp"} | ||
|
||
def test_check_record(setup_database): | ||
response = client.get("/api/record/get_record/", params={"user_id": "user123"}) | ||
assert response.status_code == 200 | ||
assert "videos" in response.json() | ||
assert response.json()["videos"] == {"video_id": "timestamp"} |