def test_regular_user_hide_private(self, super_mock, mocked_profile): mock_bundle = MagicMock() request_mock = MagicMock() r_attr = {'user': Profile(username='******')} attrs = {'request': request_mock} request_mock.configure_mock(**r_attr) mock_bundle.configure_mock(**attrs) groups = GroupAuthorization().read_list(['not_empty_but_fake'], mock_bundle) self.assertEqual(1, groups.count())
def test_anonymous_user(self, super_mock, mocked_profile): mock_bundle = MagicMock() request_mock = MagicMock() r_attr = {'user': AnonymousUser()} attrs = {'request': request_mock} request_mock.configure_mock(**r_attr) mock_bundle.configure_mock(**attrs) groups = GroupAuthorization().read_list(['not_empty_but_fake'], mock_bundle) self.assertEqual(1, groups.count())
def test_super_admin_user(self, super_mock): mock_bundle = MagicMock() request_mock = MagicMock() r_attr = { 'user': Profile(username='******', is_staff=True, is_superuser=True) } attrs = {'request': request_mock} request_mock.configure_mock(**r_attr) mock_bundle.configure_mock(**attrs) groups = GroupAuthorization().read_list([], mock_bundle) self.assertEqual( Group.objects.exclude(name='anonymous').count(), groups.count())
class Meta: queryset = Group.objects.exclude(groupprofile=None) resource_name = 'groups' allowed_methods = ['get'] filtering = { 'name': ALL, 'title': ALL, 'group_profile': ALL_WITH_RELATIONS, } ordering = ['name', 'last_modified'] authorization = GroupAuthorization()