Skip to content

Instantly share code, notes, and snippets.

@guyjacks
Created December 16, 2017 03:01
Show Gist options
  • Save guyjacks/2991d11be0cee253447ef44c5b156bc1 to your computer and use it in GitHub Desktop.
Save guyjacks/2991d11be0cee253447ef44c5b156bc1 to your computer and use it in GitHub Desktop.
def some_func():
organization = Organization.objects.get(id=1)
action_qs = organization.actions.filter(action='fund').by_month()
return action_qs
def test():
organization_mock = mocker.Mock()
patch(..., organization_mock)
# Monkeypatch organization_mock.actions with the new QuerySetMock
members = [1, 2, 3]
organization_mock.actions = QuerySetMock(members)
actual = some_func()
assert actual == organization_mock.actions.filter.by_month.return_value
# test that the chained functions were called with the correct parameters
expected = [
Call('filter', name="one raft"),
Call('by_month')
]
assert organization_mock.objects.filter.by_month.chain_called(expected)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment