You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
+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')
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?
The text was updated successfully, but these errors were encountered: