Closed KIRA009 closed 9 months ago
I am wondering how do we test this behaviour?
I thought of something like this, where we run the query n number of times, and if the ordering is different from what was seen previously, the test passes.
recognized_order = ' '.join(tuple(album.name for album in beatles.albums.order_by('?')))
for _ in range(100):
new_order = ' '.join(tuple(album.name for album in beatles.albums.order_by('?')))
if new_order != recognized_order:
break
else:
self.fail("Ordering was the same in all 100 queries")
But I am not sure if this is the best way to do this
It's probably fine to just run it once and verify that it contains the expected items - since that's the only thing you can rely on when using it in the real world.
Merged in df4c6be8ed3de4da81921d78ece7ce95f61ca50a - thanks @KIRA009!
Fixes #111
This PR randomizes the queryset by using
random.random()
values as the key during sorting of the results.