1
|
|
|
import json |
2
|
|
|
from datetime import datetime, timedelta, timezone |
3
|
|
|
|
4
|
|
|
# ignore warning for these imports, they're included so i can |
5
|
|
|
# keep track of modules which don't have tests written yet |
6
|
|
|
from models.category import Category # noqa: F401 |
7
|
|
|
from models.category_past_races import CategoryPastRaces # noqa: F401 |
8
|
|
|
from models.leaderboards import Leaderboard, Leaderboards # noqa: F401 |
9
|
|
|
from models.race import Entrant, Goal, Race, RaceCategory, Status |
10
|
|
|
from models.user import Stats, User |
11
|
|
|
from models.user_past_races import UserPastRaces # noqa: F401 |
12
|
|
|
from models.user_search import UserSearch # noqa: F401 |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
def test_race1(): |
16
|
|
|
with open('tests/data/race1.txt') as f: |
17
|
|
|
race = Race.from_dict(json.load(f)) |
18
|
|
|
assert race.name == "alttpr/lazy-hookshot-7357" |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
def test_finished_race(): |
22
|
|
|
with open('tests/data/finished_race.txt') as f: |
23
|
|
|
race = Race.from_dict(json.load(f)) |
24
|
|
|
expected_status = Status( |
25
|
|
|
value="finished", |
26
|
|
|
verbose_value="Finished", |
27
|
|
|
help_text="This race has been completed" |
28
|
|
|
) |
29
|
|
|
expected_catogeroy = RaceCategory( |
30
|
|
|
name="A Link to the Past Randomizer", |
31
|
|
|
short_name="ALttPR", |
32
|
|
|
slug="alttpr", |
33
|
|
|
url="/alttpr", |
34
|
|
|
data_url="/alttpr/data", |
35
|
|
|
image="https://racetime.gg/media/alttpr.png" |
36
|
|
|
) |
37
|
|
|
expected_goal = Goal( |
38
|
|
|
name="casual xkeys", |
39
|
|
|
custom=True, |
40
|
|
|
) |
41
|
|
|
expected_entrants = expected_entrants_finished_race1() |
42
|
|
|
expected_race = Race( |
43
|
|
|
version=73, |
44
|
|
|
name="alttpr/dazzling-oldman-0937", |
45
|
|
|
url="/alttpr/dazzling-oldman-0937", |
46
|
|
|
data_url="/alttpr/dazzling-oldman-0937/data", |
47
|
|
|
websocket_url="/ws/race/dazzling-oldman-0937", |
48
|
|
|
websocket_bot_url="/ws/o/bot/dazzling-oldman-0937", |
49
|
|
|
websocket_oauth_url="/ws/o/race/dazzling-oldman-0937", |
50
|
|
|
info=( |
51
|
|
|
"crosskeys - https://alttpr.com/h/QJG8VkrjvB - " |
52
|
|
|
"(Flute/Pendant/Magic Powder/Heart/Cape) - Quickswap Enabled" |
53
|
|
|
), |
54
|
|
|
entrants_count=10, |
55
|
|
|
entrants_count_finished=9, |
56
|
|
|
entrants_count_inactive=1, |
57
|
|
|
status=expected_status, |
58
|
|
|
category=expected_catogeroy, |
59
|
|
|
goal=expected_goal, |
60
|
|
|
entrants=expected_entrants, |
61
|
|
|
opened_at=datetime( |
62
|
|
|
year=2020, month=12, day=14, hour=3, minute=16, second=59, |
63
|
|
|
microsecond=822000, tzinfo=timezone.utc), |
64
|
|
|
time_limit=timedelta(days=1) |
65
|
|
|
) |
66
|
|
|
# assert expected_race == race |
67
|
|
|
assert len(expected_race.entrants) == len(race.entrants) |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
def expected_entrants_finished_race1(): |
71
|
|
|
expected_user1 = User( |
72
|
|
|
id="kzM65aWX7do1y8q0", |
73
|
|
|
full_name="SEJay#5897", |
74
|
|
|
name="SEJay", |
75
|
|
|
discriminator="5897", |
76
|
|
|
url="/user/kzM65aWX7do1y8q0", |
77
|
|
|
avatar=( |
78
|
|
|
"https://racetime.gg/media/lukeacevedo_beer_videogames-01_1x.png" |
79
|
|
|
), |
80
|
|
|
pronouns="he/him", |
81
|
|
|
flair="", |
82
|
|
|
twitch_name="sejay_28", |
83
|
|
|
twitch_display_name="SEJay_28", |
84
|
|
|
twitch_channel="https://www.twitch.tv/sejay_28", |
85
|
|
|
can_moderate=False, |
86
|
|
|
) |
87
|
|
|
expected_status_finished = Status( |
88
|
|
|
value="done", |
89
|
|
|
verbose_value="Finished", |
90
|
|
|
help_text="This race has been completed" |
91
|
|
|
) |
92
|
|
|
expected_entrants = [ |
93
|
|
|
Entrant( |
94
|
|
|
user=expected_user1, |
95
|
|
|
status=expected_status_finished, |
96
|
|
|
finish_time=timedelta(hours=2, minutes=34, seconds=23.909043), |
97
|
|
|
finished_at=datetime(2020, 12, 14, 6, 8, 45, |
98
|
|
|
820000, tzinfo=timezone.utc), |
99
|
|
|
place=1, |
100
|
|
|
place_ordinal="1st", |
101
|
|
|
score=None, |
102
|
|
|
score_change=None, |
103
|
|
|
comment="191", |
104
|
|
|
has_comment=True, |
105
|
|
|
stream_live=False, |
106
|
|
|
stream_override=False, |
107
|
|
|
actions=[] |
108
|
|
|
), |
109
|
|
|
Entrant( |
110
|
|
|
user=expected_user1, |
111
|
|
|
status=expected_status_finished, |
112
|
|
|
finish_time=timedelta(hours=2, minutes=43, seconds=51.353469), |
113
|
|
|
finished_at=datetime(2020, 12, 14, 6, 18, 13, |
114
|
|
|
265000, tzinfo=timezone.utc), |
115
|
|
|
place=2, |
116
|
|
|
place_ordinal="2nd", |
117
|
|
|
score=None, |
118
|
|
|
score_change=None, |
119
|
|
|
comment="190 woof", |
120
|
|
|
has_comment=True, |
121
|
|
|
stream_live=False, |
122
|
|
|
stream_override=False, |
123
|
|
|
actions=[] |
124
|
|
|
), None, None, None, None, None, None, None, None |
125
|
|
|
] |
126
|
|
|
return expected_entrants |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
def test_none_race(): |
130
|
|
|
assert None is None |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
def test_user(): |
134
|
|
|
with open('tests/data/user1.txt') as f: |
135
|
|
|
user = User.from_dict(json.load(f)) |
136
|
|
|
expected_stats = Stats( |
137
|
|
|
joined=21, |
138
|
|
|
first=3, |
139
|
|
|
second=5, |
140
|
|
|
third=0, |
141
|
|
|
forfeits=4, |
142
|
|
|
dqs=0 |
143
|
|
|
) |
144
|
|
|
expected_user = User( |
145
|
|
|
id="b52QE8oN53lywqX4", |
146
|
|
|
full_name="oro#3531", |
147
|
|
|
name="oro", |
148
|
|
|
discriminator="3531", |
149
|
|
|
url="/user/b52QE8oN53lywqX4", |
150
|
|
|
avatar="https://racetime.gg/media/oro_icon_100x100.png", |
151
|
|
|
pronouns="they/them", |
152
|
|
|
flair="", |
153
|
|
|
twitch_name="ssbmoro", |
154
|
|
|
twitch_display_name="SsbmOro", |
155
|
|
|
twitch_channel="https://www.twitch.tv/ssbmoro", |
156
|
|
|
can_moderate=False, |
157
|
|
|
stats=expected_stats |
158
|
|
|
) |
159
|
|
|
assert user == expected_user |
160
|
|
|
|