Created
December 16, 2017 03:01
-
-
Save guyjacks/2991d11be0cee253447ef44c5b156bc1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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