def test_get_queryset_calls_helper(self, mock_helper): # Given a mock that returns a sentinel mock_helper.return_value = sentinel.activities # and a view user view = UserView() view.user = sentinel.user view.request = Mock(user=sentinel.other) # When getting the queryset activities = view.get_queryset() # Then the sentinel is returned, via the helper assert activities == sentinel.activities mock_helper.assert_called_once_with(sentinel.user, sentinel.other)
def test_get_context_data_populates_correctly(self, super_mock, mock_helper): # Given a mock that returns a sentinel summary mock_helper.return_value = sentinel.summary super_mock.return_value = dict(super=sentinel.super) # and a mock queryset that returns a sentinel view = UserView() view.user = sentinel.user view.get_queryset = Mock(return_value=sentinel.activity_query_set) # When getting the context data context = view.get_context_data() # Then the context contains the sentinel summary, via the mock assert context['summaries'] == sentinel.summary assert context['view_user'] == sentinel.user assert context['super'] == sentinel.super mock_helper.assert_called_once_with(sentinel.activity_query_set)