Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add QuerySet methods to actually do the filtering #21

Open
bbirand opened this issue Aug 23, 2013 · 3 comments
Open

Add QuerySet methods to actually do the filtering #21

bbirand opened this issue Aug 23, 2013 · 3 comments

Comments

@bbirand
Copy link

bbirand commented Aug 23, 2013

I realize this will sound far-fetched, but is there a plan to actually implement the QuerySet methods, or maybe delegate them to Django somehow? I'm trying to test a function that returns a filtered set of objects. I modified it to take a QuerySet as a parameter, and I figured I should mock it.

I figured one way to do this is to pass a list of objects that behaves like an actual QuerySet, and then do some asserts on the return values. Of course, for this to work, the .filter() etc.. methods on the mock QuerySet should actually remove the items from the list.

Does this make sense? Would this even be useful, or am I missing a key testing strategy that would invalidate this approach?

@dcramer
Copy link
Owner

dcramer commented Aug 23, 2013

Ideally we would spec it from Django so it doesnt require so much upkeep

In all honesty, I haven't used this library that much. It's pretty prototype-y so "what's best" is kind of still up in the air :)

@boydjj
Copy link
Contributor

boydjj commented Aug 24, 2013

+1 for spec'ing from Django, but I'm not sure we'd want to reimplement Django-like functionality.

@bbirand Ordinarily I'd suggest doing things like asserting that the Mocks were called with the right args instead of looking for the right results, but that actually doesn't work (see below). This may be a regression due to #20. I'll file an issue to get that fixed.

def test_can_treat_as_a_mock(self):
    """
    We should be able to treat the result of any manager calls as Mocks.
    """
    qs = QuerySetMock(None, 1, 2, 3)
    qs.filter(filter_arg='dummy').order_by('-dummy_ordering')

    # These currently fail
    qs.filter.assert_called_with(filter_arg='dummy')
    qs.filter().order_by.assert_called_with('-dummy_ordering')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@dcramer @bbirand @boydjj and others