async def test_entrant_finished_first(random_users): event_loop = get_event_loop() event_loop.set_debug(True) play_media = Mock() media_player = MediaPlayer() media_file_path = "fake/path/test.mp3" media_player.play_media_callback = play_media media_player.add_trigger(media_file_path, 0) media_player.monitoring_type = 0 await asyncio.sleep(0.1) assert len(media_player.triggers) == 1 play_media.assert_not_called() entrant = get_test_entrant(status_value="in_progress", user=next(random_users)) entrants = get_test_entrants(random_users, entrant) race = get_test_race(entrants=entrants) media_player.race_updated(race, entrant.user.full_name) await asyncio.sleep(0.1) play_media.assert_not_called() entrant = race.get_entrant_by_name(entrant.user.full_name) await asyncio.sleep(0.1) entrant.place = 1 entrant.status.value = "finished" entrant.finish_time = datetime.now(timezone.utc) media_player.race_updated(race, entrant.user.full_name) await asyncio.sleep(0.1) play_media.assert_called_once_with(media_file_path, 0)
def test_cutoff_and_entrant_finished_waay_ahead(random_users): entrant = get_test_entrant(next(random_users), status_value="finished", finished_at=time_ago(minutes=20), finish_time=timedelta(hours=1, microseconds=1), place=2) second_place = get_test_entrant(next(random_users), status_value="finished", finished_at=time_ago(minutes=15), finish_time=timedelta(hours=1, minutes=35, microseconds=1), place=1) third_place = get_test_entrant(next(random_users), status_value="finished", finished_at=time_ago(minutes=10), finish_time=timedelta(hours=1, minutes=40, microseconds=1), place=3) entrants = get_test_entrants(random_users, entrant, second_place, third_place) race = get_test_race(entrants=entrants) qualifier = get_test_qualifier() qualifier.update_qualifier_text(race, entrant.user.full_name) # par is 95 minutes, entrant's time is 60 minutes. 2-(60/85) ~= 1.29 # but max score is 1.05 assert qualifier.entrant_score == "1.05" assert qualifier.par_text == "1:25:00.0"
def test_cutoff_finished(random_users): entrant = get_test_entrant(next(random_users), status_value="in_progress") first_place = get_test_entrant( next(random_users), status_value="finished", finished_at=time_ago(minutes=20), finish_time=timedelta(hours=1, minutes=30, microseconds=1), place=1, ) second_place = get_test_entrant( next(random_users), status_value="finished", finished_at=time_ago(minutes=15), finish_time=timedelta(hours=1, minutes=35, microseconds=1), place=2, ) third_place = get_test_entrant(next(random_users), status_value="finished", finished_at=time_ago(minutes=10), finish_time=timedelta(hours=1, minutes=40, microseconds=1), place=3) entrants = get_test_entrants(random_users, first_place, second_place, third_place, entrant) race = get_test_race(entrants=entrants) qualifier = get_test_qualifier() qualifier.update_qualifier_text(race, entrant.user.full_name) assert qualifier.entrant_score == " " assert qualifier.par_text == "1:35:00.0"
def test_cutoff_and_entrant_finished_in_top(random_users): entrant = get_test_entrant(next(random_users), status_value="finished", finished_at=time_ago(minutes=15), finish_time=timedelta(hours=1, minutes=35, microseconds=1), place=2) first_place = get_test_entrant( next(random_users), status_value="finished", finished_at=time_ago(minutes=20), finish_time=timedelta(hours=1, minutes=30, microseconds=1), place=1, ) third_place = get_test_entrant( next(random_users), status_value="finished", finished_at=time_ago(minutes=10), finish_time=timedelta(hours=1, minutes=40, microseconds=1), place=3, ) entrants = get_test_entrants(random_users, first_place, third_place, entrant) race = get_test_race(entrants=entrants) qualifier = get_test_qualifier() qualifier.update_qualifier_text(race, entrant.user.full_name) # par is 95 minutes, entrant's time is 95 minutes. 2-(95/95) = 1.00 assert qualifier.entrant_score == "1.00" assert qualifier.par_text == "1:35:00.0"
def test_timer_user_dqed(random_users): entrant = get_test_entrant(next(random_users), status_value="dq") entrants = get_test_entrants(random_users, entrant) race = get_test_race(entrants=entrants) timer = get_test_timer() color, text = timer.get_timer_text(race, entrant.user.full_name) assert color is None assert text == "--:--:--.-" timer.use_podium_colors = True color, text = timer.get_timer_text(race, entrant.user.full_name) assert color == timer.cancel_dq_color
def test_timer_race_cancelled(random_users): race = get_test_race(status_value="cancelled", entrants=get_test_entrants(random_users), cancelled_at=datetime.now(timezone.utc) + timedelta(minutes=20)) timer = get_test_timer() color, text = timer.get_timer_text(race, "") assert color is None assert text == "--:--:--.-" timer.use_podium_colors = True color, text = timer.get_timer_text(race, "") # currently, the timer is always red for canceled or dq races assert color is timer.cancel_dq_color
def test_timer_midrace_w_user_not_in_race(random_users): started_at = (datetime.now(timezone.utc) - timedelta(hours=1, minutes=42, seconds=42.0)) race = get_test_race(version=17, entrants=get_test_entrants(random_users), started_at=started_at) timer = get_test_timer() color, text = timer.get_timer_text(race, "user_not_in_race#6969") assert color is None assert text == "1:42:42.0" timer.use_podium_colors = True color, text = timer.get_timer_text(race, "user_not_in_race#6969") assert color == timer.racing_color
def test_timer_counting_down(random_users): timer = get_test_timer() race = get_test_race(status_value="pending", version=13, started_at=time_ago(seconds=-5.01), start_delay=timedelta(seconds=15.0), entrants=get_test_entrants(random_users)) color, text = timer.get_timer_text(race, "") assert color is None assert text == "-0:00:05.0" timer.use_podium_colors = True color, text = timer.get_timer_text(race, "") assert color is timer.pre_color
def test_timer_midrace_no_entrant(random_users): timer = get_test_timer() race = get_test_race(status_value="in_progress", version=15, entrants_count=2, started_at=datetime.now(timezone.utc) - timedelta(hours=1, minutes=20), entrants=get_test_entrants(random_users)) color, text = timer.get_timer_text(race, "") assert color is None # hope this always runs in less than 0.1 seconds XD assert text == "1:20:00.0" timer.use_podium_colors = True color, text = timer.get_timer_text(race, "") assert color is timer.racing_color
def test_timer_prerace(random_users): timer = get_test_timer() race = get_test_race(status_value="open", version=12, started_at=None, start_delay=timedelta(seconds=15, microseconds=1), entrants=get_test_entrants(random_users)) color, text = timer.get_timer_text(race, "") assert color is None assert text == "-0:00:15.0" timer.use_podium_colors = True color, text = timer.get_timer_text(race, "") assert color is timer.pre_color assert text == "-0:00:15.0"
def test_timer_midrace_w_entrant(random_users): entrant = get_test_entrant(next(random_users), status_value="finished", finished_at=datetime.now(timezone.utc), finish_time=timedelta(hours=1, minutes=42, seconds=6.9)) entrants = get_test_entrants(random_users, entrant) race = get_test_race(version=16, entrants=entrants) timer = get_test_timer() color, text = timer.get_timer_text(race, entrant.user.full_name) assert color is None assert text == "1:42:06.9" timer.use_podium_colors = True color, text = timer.get_timer_text(race, entrant.user.full_name) assert color == timer.racing_color
def test_user_finished_other(random_users): entrant = get_test_entrant(next(random_users), status_value="finished", finished_at=datetime.now(timezone.utc), place=5, finish_time=timedelta(hours=1, minutes=9, seconds=42, microseconds=1)) entrants = get_test_entrants(random_users, entrant) race = get_test_race(started_at=datetime.now(timezone.utc) - entrant.finish_time, entrants_count=5, entrants=entrants) timer = get_test_timer() color, text = timer.get_timer_text(race, entrant.user.full_name) assert color is None assert text == "1:09:42.0" timer.use_podium_colors = True color, text = timer.get_timer_text(race, entrant.user.full_name) assert color == timer.finished_color