def test_get_queryset(self): """Establish that our `get_queryset` method filters in the way we expect. """ mvs = ModelViewSet() with mock.patch.object(ModelViewSet.mro()[1], 'get_queryset') as m: qs = mvs.get_queryset() self.assertEqual(qs, m.return_value)
def test_get_queryset_with_kwargs(self): """Establish that our `get_queryset` method filters in the way we expect if we have unknown keyword arguments (which typically come from parent viewsets). """ mvs = ModelViewSet(kwargs={'foo__pk': 42}) with mock.patch.object(ModelViewSet.mro()[1], 'get_queryset') as m: m.return_value = mock.MagicMock() qs = mvs.get_queryset() self.assertEqual(m.return_value.mock_calls, [mock.call.filter(foo__pk=42)])