def test_fighter_info(): events_page = tools.html_session( "https://www.sherdog.com/organizations/Ultimate-Fighting-Championship-UFC-2" ) next_event_url = event_tools.next_event_url(events_page) next_event_page = tools.html_session(next_event_url) fights = event_tools.FightersOnCard(next_event_page).main() for fight in fights: for fighter_url in fight: fighter_page = tools.html_session(fighter_url) fighter_info = event_tools.fighter_info(fighter_page) assert isinstance(fighter_info, dict) name = fighter_info["name"] assert isinstance(name, str) age = fighter_info["age"] assert isinstance(age, str) assert int(age) record = fighter_info["record"] assert isinstance(record, str) record_int_only = record.replace(" ", "").replace("-", "") assert int(record_int_only) city = fighter_info["city"] assert isinstance(city, str) country = fighter_info["country"] assert isinstance(country, str)
def next_ufc_event() -> dict: """ Collect data on the next ufc event. :return next_ufc_fight_card: """ next_ufc_fight_card = [] ufc_page = tools.html_session( "https://www.sherdog.com/organizations/Ultimate-Fighting-Championship-UFC-2" ) next_ufc_url = next_event_url(ufc_page) next_ufc_page = tools.html_session(next_ufc_url) next_ufc_dict = {"event_date": next_event_date(next_ufc_page)} # TODO add promotion to dict fights = FightersOnCard(next_ufc_page).main() for fight in fights: single_fight = [] for fighter_url in fight: fighter_page = tools.html_session(fighter_url) fighter_information = fighter_info(fighter_page) fighter_information["fighter_url"] = fighter_url single_fight.append(fighter_information) next_ufc_fight_card.append(single_fight) next_ufc_dict["fights"] = next_ufc_fight_card return next_ufc_dict
def test_next_event_date(): ufc_page = tools.html_session( "https://www.sherdog.com/organizations/Ultimate-Fighting-Championship-UFC-2" ) next_ufc_url = event_tools.next_event_url(ufc_page) next_ufc_page = tools.html_session(next_ufc_url) event_date = event_tools.next_event_date(next_ufc_page) assert isinstance(event_date, str)
def test_fighters_on_card(): events_page = tools.html_session( "https://www.sherdog.com/organizations/Ultimate-Fighting-Championship-UFC-2" ) next_fight_url = event_tools.next_event_url(events_page) event_page = tools.html_session(next_fight_url) fights = event_tools.FightersOnCard(event_page).main() for fight in fights: for fighters_url in fight: assert requests.get(fighters_url).status_code == 200
def betting_page() -> object: """ HTMLResponse for https://www.bestfightodds.com :return page: HTMLResponse for https://www.bestfightodds.com """ page = tools.html_session('https://www.bestfightodds.com') return page
def test_next_event_url(): event_page = tools.html_session( "https://www.sherdog.com/organizations/Ultimate-Fighting-Championship-UFC-2" ) next_event_url = event_tools.next_event_url(event_page) domain = 'https://www.sherdog.com' assert domain in next_event_url assert requests.get(next_event_url).status_code == 200
def next_ufc_betting_odds() -> list: """ Gather the betting odds for the next ufc event. :return odds: List of the betting odds for the next ufc event. """ promotion = 'ufc' bet_page = betting_page() bet_events = betting_events(bet_page) next_bet_url = next_betting_url(bet_events, promotion) get_event_id = event_id(next_bet_url) event_page = tools.html_session(next_bet_url) odds = betting_odds(event_page, get_event_id) return odds, promotion
def test_betting_odds(): # HTMLResponse for https://www.bestfightodds.com betting_page = betting_tools.betting_page() # Parse HTMLResponse for all betting events and return the html as a list. betting_events = betting_tools.betting_events(betting_page) # The first event in the loop will be the next event. next_betting_url = betting_tools.next_betting_url(betting_events, 'ufc') event_id = betting_tools.event_id(next_betting_url) event_page = tools.html_session(next_betting_url) betting_odds = betting_tools.betting_odds(event_page, event_id) for fighter_odds in betting_odds: assert isinstance(fighter_odds, list) line_count = 0 for fight_info in fighter_odds: if line_count == 0: fighter_name = fight_info assert isinstance(fighter_name, str) line_count += 1 else: assert isinstance(fight_info, dict) line_count = 0 # reset line count for the next fighter_odds
def test_html_session(): session = tools.html_session( "https://www.sherdog.com/events/UFC-Fight-Night-159-Rodriguez-vs-Stephens-76587" ) assert session.status_code == 200
def test_next_betting_url(): betting_page = betting_tools.betting_page() betting_events = betting_tools.betting_events(betting_page) next_betting_url = betting_tools.next_betting_url(betting_events, 'ufc') assert tools.html_session(next_betting_url).status_code == 200 assert 'ufc' in next_betting_url