Create a DB session per query test
This commit is contained in:
parent
893d618a31
commit
abd0f45c91
|
@ -0,0 +1,10 @@
|
||||||
|
from fastapi.testclient import TestClient
|
||||||
|
from sqlalchemy import create_engine
|
||||||
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
|
||||||
|
from app import app
|
||||||
|
from constants import TESTING_DB
|
||||||
|
|
||||||
|
engine = create_engine(TESTING_DB, connect_args={"check_same_thread": False})
|
||||||
|
TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||||
|
client = TestClient(app)
|
|
@ -1,73 +1,86 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from database import SessionLocal
|
|
||||||
from database.models import *
|
from database.models import *
|
||||||
|
from tests import TestingSessionLocal
|
||||||
|
from pytest import fixture
|
||||||
|
|
||||||
|
|
||||||
db = SessionLocal()
|
@fixture
|
||||||
|
def get_test_db():
|
||||||
|
try:
|
||||||
|
db = TestingSessionLocal()
|
||||||
|
yield db
|
||||||
|
finally:
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
def test_users():
|
def test_users(get_test_db):
|
||||||
test = db.query(Users).filter(Users.id == 260).first()
|
test = get_test_db.query(Users).filter(Users.id == 260).first()
|
||||||
assert test.email == "testaccountjugador@gmail.com"
|
assert test.email == "testaccountjugador@gmail.com"
|
||||||
|
|
||||||
|
|
||||||
def test_cities():
|
def test_cities(get_test_db):
|
||||||
test = db.query(Cities).filter(Cities.id == 7).first()
|
test = get_test_db.query(Cities).filter(Cities.id == 7).first()
|
||||||
assert test.name == "Lyon"
|
assert test.name == "Lyon"
|
||||||
|
|
||||||
|
|
||||||
def test_games():
|
def test_games(get_test_db):
|
||||||
test = db.query(Games).filter(Games.id == 508).first()
|
test = get_test_db.query(Games).filter(Games.id == 508).first()
|
||||||
assert test.user_id == 1978
|
assert test.user_id == 1978
|
||||||
|
|
||||||
|
|
||||||
def test_payments():
|
def test_payments(get_test_db):
|
||||||
test = db.query(Payments).filter(Payments.id == 375).first()
|
test = get_test_db.query(Payments).filter(Payments.id == 375).first()
|
||||||
assert test.user_id == 88
|
assert test.user_id == 88
|
||||||
|
|
||||||
|
|
||||||
def test_player_availabilities():
|
def test_player_availabilities(get_test_db):
|
||||||
test = db.query(PlayerAvailabilities).filter(PlayerAvailabilities.id == 248).first()
|
test = (
|
||||||
|
get_test_db.query(PlayerAvailabilities)
|
||||||
|
.filter(PlayerAvailabilities.id == 248)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
assert test.game_id == 89
|
assert test.game_id == 89
|
||||||
|
|
||||||
|
|
||||||
def test_player_cancel_games():
|
def test_player_cancel_games(get_test_db):
|
||||||
test = db.query(PlayerCancelGames).filter(PlayerCancelGames.id == 67).first()
|
test = (
|
||||||
|
get_test_db.query(PlayerCancelGames).filter(PlayerCancelGames.id == 67).first()
|
||||||
|
)
|
||||||
assert test.player_id == 44
|
assert test.player_id == 44
|
||||||
|
|
||||||
|
|
||||||
def test_purchase_games():
|
def test_purchase_games(get_test_db):
|
||||||
test = db.query(PurchaseGames).filter(PurchaseGames.id == 235).first()
|
test = get_test_db.query(PurchaseGames).filter(PurchaseGames.id == 235).first()
|
||||||
assert test.game_id == 50
|
assert test.game_id == 50
|
||||||
|
|
||||||
|
|
||||||
def test_sports():
|
def test_sports(get_test_db):
|
||||||
test = db.query(Sports).filter(Sports.id == 4).first()
|
test = get_test_db.query(Sports).filter(Sports.id == 4).first()
|
||||||
assert test.name == "Volleyball"
|
assert test.name == "Volleyball"
|
||||||
|
|
||||||
|
|
||||||
def test_teams():
|
def test_teams(get_test_db):
|
||||||
test = db.query(Teams).filter(Teams.id == 306).first()
|
test = get_test_db.query(Teams).filter(Teams.id == 306).first()
|
||||||
assert test.game_id == 64
|
assert test.game_id == 64
|
||||||
|
|
||||||
|
|
||||||
def test_user_ratings():
|
def test_user_ratings(get_test_db):
|
||||||
test = db.query(UserRatings).filter(UserRatings.id == 287).first()
|
test = get_test_db.query(UserRatings).filter(UserRatings.id == 287).first()
|
||||||
assert test.user_id == 60
|
assert test.user_id == 60
|
||||||
|
|
||||||
|
|
||||||
def test_venue_images():
|
def test_venue_images(get_test_db):
|
||||||
test = db.query(VenueImages).filter(VenueImages.id == 3).first()
|
test = get_test_db.query(VenueImages).filter(VenueImages.id == 3).first()
|
||||||
date = datetime(year=2019, month=6, day=3, hour=5, minute=43, second=22)
|
date = datetime(year=2019, month=6, day=3, hour=5, minute=43, second=22)
|
||||||
assert test.created == date
|
assert test.created == date
|
||||||
|
|
||||||
|
|
||||||
def test_venues():
|
def test_venues(get_test_db):
|
||||||
test = db.query(Venues).filter(Venues.id == 26).first()
|
test = get_test_db.query(Venues).filter(Venues.id == 26).first()
|
||||||
assert test.name == "Le tuto "
|
assert test.name == "Le tuto "
|
||||||
|
|
||||||
|
|
||||||
def test_web_bookings():
|
def test_web_bookings(get_test_db):
|
||||||
test = db.query(WebBookings).filter(WebBookings.id == 7).first()
|
test = get_test_db.query(WebBookings).filter(WebBookings.id == 7).first()
|
||||||
assert test.game == "Soccer"
|
assert test.game == "Soccer"
|
||||||
|
|
Loading…
Reference in New Issue