forked from UnBTV/UnB-TV-VideoService
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adicao dos metodos create/post do favorite e teste
- Loading branch information
1 parent
b28857b
commit 4a2011e
Showing
4 changed files
with
74 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
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
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
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,48 @@ | ||
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_favorite(setup_database): | ||
response = client.post("/api/favorite/", json={"user_id": "user123", "video_id": "video123"}) | ||
assert response.status_code == 200 | ||
assert response.json()["user_id"] == "user123" | ||
assert response.json()["video_id"] == "video123" | ||
assert response.json()["statusfavorite"] is True | ||
|