Пример #1
0
    def setUp(self):
        self.checkslug_viewset = CollectionViewSet.as_view(actions={
            'get': 'slug_exists',
        })
        self.add_data_viewset = CollectionViewSet.as_view(actions={
            'post': 'add_data',
        })
        self.remove_data_viewset = CollectionViewSet.as_view(actions={
            'post': 'remove_data',
        })
        self.collection_detail_viewset = CollectionViewSet.as_view(actions={
            'get': 'retrieve',
            'put': 'update',
            'patch': 'partial_update',
            'delete': 'destroy',
        })
        self.collection_list_viewset = CollectionViewSet.as_view(actions={
            'get': 'list',
            'post': 'create',
        })

        self.detail_url = lambda pk: reverse('resolwe-api:collection-detail', kwargs={'pk': pk})

        self.super_user = User.objects.create(username='******', is_superuser=True)
        self.user = User.objects.create(username='******')
Пример #2
0
    def setUp(self):
        super(TestCollectionViewSetCase, self).setUp()

        self.checkslug_viewset = CollectionViewSet.as_view(
            actions={
                'get': 'slug_exists',
            })
        self.add_data_viewset = CollectionViewSet.as_view(actions={
            'post': 'add_data',
        })
        self.remove_data_viewset = CollectionViewSet.as_view(
            actions={
                'post': 'remove_data',
            })
        self.collection_detail_viewset = CollectionViewSet.as_view(
            actions={
                'get': 'retrieve',
                'put': 'update',
                'patch': 'partial_update',
                'delete': 'destroy',
            })
        self.collection_list_viewset = CollectionViewSet.as_view(
            actions={
                'get': 'list',
                'post': 'create',
            })

        self.detail_url = lambda pk: reverse('resolwe-api:collection-detail',
                                             kwargs={'pk': pk})
Пример #3
0
    def setUp(self):
        self.checkslug_viewset = CollectionViewSet.as_view(actions={
            'get': 'slug_exists',
        })
        self.add_data_viewset = CollectionViewSet.as_view(actions={
            'post': 'add_data',
        })
        self.remove_data_viewset = CollectionViewSet.as_view(actions={
            'post': 'remove_data',
        })

        self.detail_url = lambda pk: reverse('resolwe-api:collection-detail', kwargs={'pk': pk})

        self.super_user = User.objects.create(username='******', is_superuser=True)
        self.user = User.objects.create(username='******')
Пример #4
0
    def setUp(self):
        super().setUp()

        self.collection_viewset = CollectionViewSet.as_view(actions={
            'get': 'list',
        })

        self.collection = Collection.objects.create(
            name='Test collection 1',
            contributor=self.contributor,
        )
Пример #5
0
    def setUp(self):
        super().setUp()

        self.checkslug_viewset = CollectionViewSet.as_view(actions={
            'get': 'slug_exists',
        })
        self.add_data_viewset = CollectionViewSet.as_view(actions={
            'post': 'add_data',
        })
        self.remove_data_viewset = CollectionViewSet.as_view(actions={
            'post': 'remove_data',
        })
        self.duplicate_viewset = CollectionViewSet.as_view(actions={
            'post': 'duplicate',
        })
        self.collection_detail_viewset = CollectionViewSet.as_view(actions={
            'get': 'retrieve',
            'put': 'update',
            'patch': 'partial_update',
            'delete': 'destroy',
        })
        self.collection_list_viewset = CollectionViewSet.as_view(actions={
            'get': 'list',
            'post': 'create',
        })

        self.detail_url = lambda pk: reverse('resolwe-api:collection-detail', kwargs={'pk': pk})
Пример #6
0
    def setUp(self):
        super().setUp()

        self.checkslug_viewset = CollectionViewSet.as_view(
            actions={
                "get": "slug_exists",
            })
        self.add_data_viewset = CollectionViewSet.as_view(actions={
            "post": "add_data",
        })
        self.remove_data_viewset = CollectionViewSet.as_view(
            actions={
                "post": "remove_data",
            })
        self.duplicate_viewset = CollectionViewSet.as_view(actions={
            "post": "duplicate",
        })
        self.collection_detail_viewset = CollectionViewSet.as_view(
            actions={
                "get": "retrieve",
                "put": "update",
                "patch": "partial_update",
                "delete": "destroy",
            })
        self.collection_list_viewset = CollectionViewSet.as_view(
            actions={
                "get": "list",
                "post": "create",
            })

        self.detail_url = lambda pk: reverse("resolwe-api:collection-detail",
                                             kwargs={"pk": pk})
Пример #7
0
    def test_user_permissions(self):
        """Test user permissions.

        Method get_object_perms should only be tested through view, as it
        expects pre-fetched permissions for the given user.
        """

        self.group1.user_set.add(self.user1)
        self.collection.set_permission(Permission.EDIT, self.user1)
        self.collection.set_permission(Permission.VIEW, self.user2)
        self.collection.set_permission(Permission.EDIT, self.group1)
        self.collection.set_permission(Permission.VIEW, self.group2)

        expected_perms = [
            {
                "permissions": ["edit", "view"],
                "type": "user",
                "id": self.user1.pk,
                "name": "test_user1",
                "username": "******",
            },
            {
                "permissions": ["edit", "view"],
                "type": "group",
                "id": self.group1.pk,
                "name": "Test group 1",
            },
        ]

        url = reverse("resolwe-api:collection-permissions",
                      kwargs={"pk": self.collection.pk})
        request = factory.get(url, data={}, format="json")
        force_authenticate(request, self.user1)
        detail_view = CollectionViewSet.as_view({"get": "detail_permissions"})
        response = detail_view(request, pk=self.collection.pk)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        perms = response.data
        self.assertCountEqual(self._sort_perms(expected_perms),
                              self._sort_perms(perms))

        self.group2.user_set.add(self.user1)
        expected_perms.append(
            {
                "permissions": ["view"],
                "type": "group",
                "id": self.group2.pk,
                "name": "Test group 2",
            }, )

        response = detail_view(request, pk=self.collection.pk)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        perms = response.data
        self.assertCountEqual(self._sort_perms(expected_perms),
                              self._sort_perms(perms))

        self.collection.set_permission(Permission.VIEW, self.anonymous)
        expected_perms.append({"permissions": ["view"], "type": "public"}, )

        response = detail_view(request, pk=self.collection.pk)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        perms = response.data
        self.assertCountEqual(self._sort_perms(expected_perms),
                              self._sort_perms(perms))