def test_should_include_previously_selected_paginate_by_page2_kwargs(self): view = manytomanyview.ViewMixin() view.paginate_by = 40 view.page_kwarg = 'page' view.kwargs = {'page': 2} view.request = mock.MagicMock() view.request.GET = {} self.assertFalse(view.should_include_previously_selected())
def test_get_target_renderer(self): view = manytomanyview.ViewMixin() view.request = mock.MagicMock() view.request.GET = { 'manytomany_select_fieldid': 'testid', 'manytomany_select_required': 'True' } target_renderer = view.get_target_renderer() self.assertEqual('testid', target_renderer.target_formfield_id)
def test_get_target_renderer_kwargs(self): view = manytomanyview.ViewMixin() view.request = mock.MagicMock() view.request.GET = { 'manytomany_select_fieldid': 'testid', 'manytomany_select_required': 'True' } target_renderer_kwargs = view.get_target_renderer_kwargs() self.assertEqual('testid', target_renderer_kwargs['target_formfield_id']) self.assertFalse(target_renderer_kwargs['empty_selection_allowed'])
def test_get_selected_objects(self): view = manytomanyview.ViewMixin() view.request = mock.MagicMock() view.request.cradmin_role = 'testrole' view.get_selected_values_list = mock.MagicMock( return_value='testvalue') mockqueryset = mock.MagicMock() view.get_queryset_for_role = mock.MagicMock(return_value=mockqueryset) view.get_selected_objects() mockqueryset.filter.assert_called_once_with(pk__in='testvalue') view.get_queryset_for_role.assert_called_once_with('testrole')
def test_should_include_previously_selected_get_filters_string_nonempty_string( self): view = manytomanyview.ViewMixin() view.get_filters_string = mock.MagicMock(return_value='test') self.assertFalse(view.should_include_previously_selected())
def test_should_include_previously_selected_no_paging_no_get_filters_string( self): view = manytomanyview.ViewMixin() self.assertTrue(view.should_include_previously_selected())
def test_get_target_renderer_class(self): view = manytomanyview.ViewMixin() self.assertEqual(manytomanyview.ViewMixin.target_renderer_class, view.get_target_renderer_class())
def test_get_selected_values_list(self): view = manytomanyview.ViewMixin() view.request = mock.MagicMock() view.request.GET = QueryDict('', mutable=True) view.request.GET.update({'manytomany_select_current_value': '[1,2]'}) self.assertEqual([1, 2], view.get_selected_values_list())