Add try/except to catch error when site is unavailable
This commit is contained in:
1 parent
97635dd3f2
commit
08491297e3
3 files changed
+17
No files matched your search
@@ -1,5 +1,8 @@
|
||||
from datetime import datetime
|
||||
import pytest
|
||||
|
||||
from sqlite3 import IntegrityError
|
||||
from httpx import ConnectError
|
||||
|
||||
from conftest import MegaMillionsDraw
|
||||
from util.drawing import get_mega_millions_object
|
||||
@@ -71,6 +74,7 @@ def test_mega_millions_draw_eq_repr_and_str(db_session) -> None:
|
||||
def test_mega_millions_scrape_and_insert(db_session) -> None:
|
||||
"""test scraping game data and inserting it into the database"""
|
||||
# scrape the current year history for mega millions
|
||||
try:
|
||||
raw_data = scrape_game_history(game='mega-millions')
|
||||
|
||||
print(len(raw_data))
|
||||
@@ -87,3 +91,5 @@ def test_mega_millions_scrape_and_insert(db_session) -> None:
|
||||
# get all the records from the table
|
||||
records = db_session.query(MegaMillionsDraw).all()
|
||||
assert len(records) == len(raw_data)
|
||||
except ConnectError as ce:
|
||||
assert pytest.fail(f"Target scrape site is unavailable: {ce}")
|
||||
@@ -1,5 +1,8 @@
|
||||
from datetime import datetime
|
||||
import pytest
|
||||
|
||||
from sqlite3 import IntegrityError
|
||||
from httpx import ConnectError
|
||||
|
||||
from conftest import PowerballDraw
|
||||
from util.drawing import get_powerball_object
|
||||
@@ -71,6 +74,7 @@ def test_powerball_draw_eq_repr_and_str(db_session) -> None:
|
||||
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
|
||||
try:
|
||||
raw_data = scrape_game_history(game='powerball')
|
||||
|
||||
# loop over the records returned
|
||||
@@ -86,3 +90,5 @@ def test_powerball_scrape_and_insert(db_session) -> None:
|
||||
# get all the records from the table
|
||||
records = db_session.query(PowerballDraw).all()
|
||||
assert len(records) == len(raw_data)
|
||||
except ConnectError as ce:
|
||||
pytest.fail(f"Target scrape site is unavailable: {ce}")
|
||||
@@ -1,6 +1,8 @@
|
||||
"""Tests for the `util` module."""
|
||||
from datetime import datetime
|
||||
|
||||
from httpx import ConnectError
|
||||
|
||||
import pytest
|
||||
import util.convert as uc
|
||||
import util.drawing as ud
|
||||
@@ -51,12 +53,15 @@ def test_get_next_draw_date_specified_from_date() -> None:
|
||||
@pytest.mark.parametrize("game", ['powerball', 'mega-millions'])
|
||||
def test_scrape_game_history(game) -> None:
|
||||
"""Test scraping the powerball result page for 1996, 2020, and current year."""
|
||||
try:
|
||||
scrape_data = sc.scrape_game_history(game, year=1996)
|
||||
assert len(scrape_data) in [17, 104]
|
||||
scrape_data = sc.scrape_game_history(game, year=2020)
|
||||
assert len(scrape_data) in [104, 105]
|
||||
scrape_data = sc.scrape_game_history(game)
|
||||
assert len(scrape_data) in range(0, 105)
|
||||
except ConnectError as ce:
|
||||
pytest.fail(f"Target scrape site is unavailable: {ce}")
|
||||
|
||||
|
||||
def test_calculate_odds() -> None:
|
||||
|
||||
Reference in new issue
Block a user