Assume i have the following function:
def select_queryset(value_to_decide_upon):
""" this function returns either any of some querysets or nothing """
if value_to_decide_upon == 1:
return User._default_manager.all()
elif value_to_decide_upon == 2:
return User._default_manager.filter(pk__in=[some_more_values])
elif value_to_decide_upon == n-1:
return User._default_manager.all().order_by('?')
elif value_to_decide_upon == n:
return None
Now here is the question: this function has a randomly ordered queryset as a return value:
queryset = User._default_manager.all().order_by('?')
Now the only important thing about that function is: it has to return the correct queryset. Is there a way to access the queryset in such way that i can, ie. do something like this:
class TestQuerysetSelection(TestCase):
def test_return_value(self):
# this, of course, will always fail:
self.assertEqual(select_queryset(n-1),
User._default_manager.all().order_by('?') )
# and this is not working as well
self.assertEqual( templatetag.queryset.order_by, '?' )
So how can i test if the function returns the correct queryset, without brute force comparing to all other querysets?
I think the most starighforward way is to compare sets (which are unordered).