Remove old buggy db tests

This commit is contained in:
chris committed 2026-03-02 17:07:46 -05:00
1 parent ae4aa1203e
commit 4e6cb86806
1 file changed
-86
-86
View File
@@ -1,86 +0,0 @@
from datetime import datetime
from pytest import fixture
from sqlalchemy.exc import IntegrityError
import sqlalchemy.orm
import data.database as db
@fixture(scope='session')
def db_session() -> db.dal.Session:
db.dal.connect()
yield db.dal.Session()
if hasattr(db.dal, 'engine') and db.dal.engine:
db.dal.engine.dispose()
db.dal.engine.pool.recreate()
@fixture(scope='function')
def session(db_session) -> db.dal.Session:
"""Provides a transactional scope around each test."""
connection = db_session.connection()
transaction = connection.begin()
# bind the session to this specific connection
db_session.bind = connection
yield db_session
# roll all changed that occurred back
transaction.rollback()
connection.close()
def test_base() -> None:
"""Test to ensure db.Base() is a sqlalchemy DeclarativeBase object."""
assert isinstance(db.Base(), sqlalchemy.orm.DeclarativeBase)
def test_powerball_draw_by_date_blank(session) -> None:
"""
Test that a null record is returned when no date is provided and that no dateless
records can exist in the table.
"""
with session:
blank_results = session.query(db.PowerballDraw).filter_by(draw_date='').all()
assert blank_results == []
def test_powerball_draw_by_date(session) -> None:
"""Test to be sure we can find the first draw in the table by date."""
with session:
date = datetime(2010, 2, 3).date()
draw = db.PowerballDraw(draw_date=date, main_ball1=17, main_ball2=22, main_ball3=36, main_ball4=37,
main_ball5=52, powerball=24, power_play=2)
record = session.query(db.PowerballDraw).filter_by(draw_date=date).first()
assert record == draw
def test_powerball_draw_integrity(session) -> None:
"""Test that a proper error is received when a duplicate value insertion is attempted."""
with session:
date = datetime.strptime('02/03/2010','%m/%d/%Y').date()
draw = db.PowerballDraw(draw_date=date, main_ball1=17, main_ball2=22, main_ball3=36, main_ball4=37,
main_ball5=52, powerball=24, power_play=2)
try:
session.add(draw)
session.commit()
except IntegrityError:
assert True
finally:
session.rollback()
session.close()
def test_powerball_repr_and_str(session) -> None:
"""Test the __repr__ and __str__ methods of PowerballDraw objects."""
with session:
date = datetime(2010, 2, 3).date()
record = session.query(db.PowerballDraw).filter_by(draw_date=date).first()
assert str(record) == '2010-02-03, [17, 22, 36, 37, 52], 24, 2x'
assert repr(record) == 'PowerballDraw(self.draw_date=datetime.date(2010, 2, 3), self.main_ball1=17, ' \
'self.main_ball2=22, self.main_ball3=36, self.main_ball4=37, self.main_ball5=52, ' \
'self.powerball=24, self.power_play=2)'