Add powerball scrape and insert test

This commit is contained in:
chris committed 2026-03-02 19:14:51 -05:00
1 parent 9992abb8a2
commit f41e88ac69
1 file changed
+20
+20
View File
@@ -2,6 +2,8 @@ from datetime import datetime
from sqlite3 import IntegrityError
from conftest import PowerballDraw
from util.drawing import get_powerball_object
from util.scrape import scrape_game_history
def test_create_powerball_draw(db_session) -> None:
@@ -66,3 +68,21 @@ def test_powerball_draw_eq_repr_and_str(db_session) -> None:
assert repr(record) == repr(new_record)
def test_powerball_scrape_and_insert(db_session) -> None:
"""test scraping game data and inserting it into the database"""
# scrape the current year history for powerball
raw_data = scrape_game_history(game='powerball')
# loop over the records returned
for key, value in raw_data.items():
# convert each record to a PowerballDraw object
record = get_powerball_object(draw_date=key, draw_result=value)
# add the record to the database
db_session.add(record)
# commit the changes
db_session.commit()
# get all the records from the table
records = db_session.query(PowerballDraw).all()
assert len(records) == len(raw_data)