Skip to content

Commit 25db8f5

Browse files
Explicitly Specify Infraction Time In Tests
The infraction tests checked that the route returned infractions in the correct order, which is based on insertion time. This can be fragile however, since the insertion time can be very close (or identical) during the tests. That became especially more likely with PR #741 (commit 149e67b) which improved database access speed. This is fixed by explicitly specifying the insertion time, and spacing them out properly. Signed-off-by: Hassan Abouelela <[email protected]>
1 parent 640a2e2 commit 25db8f5

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pydis_site/apps/api/tests/test_infractions.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,39 +56,44 @@ def setUpTestData(cls):
5656
type='ban',
5757
reason='He terk my jerb!',
5858
hidden=True,
59+
inserted_at=dt(2020, 10, 10, 0, 0, 0, tzinfo=timezone.utc),
5960
expires_at=dt(5018, 11, 20, 15, 52, tzinfo=timezone.utc),
60-
active=True
61+
active=True,
6162
)
6263
cls.ban_inactive = Infraction.objects.create(
6364
user_id=cls.user.id,
6465
actor_id=cls.user.id,
6566
type='ban',
6667
reason='James is an ass, and we won\'t be working with him again.',
67-
active=False
68+
active=False,
69+
inserted_at=dt(2020, 10, 10, 0, 1, 0, tzinfo=timezone.utc),
6870
)
6971
cls.mute_permanent = Infraction.objects.create(
7072
user_id=cls.user.id,
7173
actor_id=cls.user.id,
7274
type='mute',
7375
reason='He has a filthy mouth and I am his soap.',
7476
active=True,
75-
expires_at=None
77+
inserted_at=dt(2020, 10, 10, 0, 2, 0, tzinfo=timezone.utc),
78+
expires_at=None,
7679
)
7780
cls.superstar_expires_soon = Infraction.objects.create(
7881
user_id=cls.user.id,
7982
actor_id=cls.user.id,
8083
type='superstar',
8184
reason='This one doesn\'t matter anymore.',
8285
active=True,
83-
expires_at=dt.now(timezone.utc) + datetime.timedelta(hours=5)
86+
inserted_at=dt(2020, 10, 10, 0, 3, 0, tzinfo=timezone.utc),
87+
expires_at=dt.now(timezone.utc) + datetime.timedelta(hours=5),
8488
)
8589
cls.voiceban_expires_later = Infraction.objects.create(
8690
user_id=cls.user.id,
8791
actor_id=cls.user.id,
8892
type='voice_ban',
8993
reason='Jet engine mic',
9094
active=True,
91-
expires_at=dt.now(timezone.utc) + datetime.timedelta(days=5)
95+
inserted_at=dt(2020, 10, 10, 0, 4, 0, tzinfo=timezone.utc),
96+
expires_at=dt.now(timezone.utc) + datetime.timedelta(days=5),
9297
)
9398

9499
def test_list_all(self):

0 commit comments

Comments
 (0)