Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7794913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:54:56+00:00 2026-06-01T22:54:56+00:00

Assume i have the following function: def select_queryset(value_to_decide_upon): this function returns either any of

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:54:58+00:00Added an answer on June 1, 2026 at 10:54 pm

    I think the most starighforward way is to compare sets (which are unordered).

    self.assertEqual(
        set(select_queryset(n-1)),
        set(User._default_manager.all())
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Why is this function returning “undefined”? Let's assume I have the following
Let's assume we have a decorator: def decor(function): def result(): printf('decorated') return function() return
Assume I have the following example: Example One $('.my_Selector_Selected_More_Than_One_Element').each(function() { $(this).stuff(); $(this).moreStuff(); $(this).otherStuff(); $(this).herStuff();
Assume I have the following input in Pig: some And I would like to
Assume I have the following function: // Precondition: foo is '0' or 'MAGIC_NUMBER_4711' //
Lets assume I have the following Java code: public String foo() { // returns
I have a static library. This library have the following function defined int WriteData(LPTSTR
Assume I have the following string: Hellotoevryone<img height=115 width=150 alt= src=/Content/Edt/image/b4976875-8dfb-444c-8b32-cc b47b2d81e0.jpg />Iamsogladtoseeall. This
Assume I have the following style table, col1 col2 and col3 have same value
Assume I have the following classes class Genre { static hasMany=[author:Author] } class Author{

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.