示例#1
0
    def test_anonymous_can_view_public_box_metadata(self):
        box = BoxFactory(visibility=Box.PUBLIC)
        version = BoxVersionFactory(box=box)
        BoxProviderFactory(version=version, provider='virtualbox')
        BoxProviderFactory(version=version, provider='vmware')
        BoxProviderFactory()

        request = self.factory.get('/url/')
        response = self.view_detail(request,
                                    username=box.owner.username,
                                    box_name=box.name)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
示例#2
0
    def test_user_with_permissions_can_view_metadata(self):
        user = UserFactory()
        box = BoxFactory()
        box.share_with(user, BoxMember.PERM_R)
        version = BoxVersionFactory(box=box)
        BoxProviderFactory(version=version, provider='virtualbox')
        BoxProviderFactory(version=version, provider='vmware')
        BoxProviderFactory()

        request = self.factory.get('/url/')
        force_authenticate(request, user=user)
        response = self.view_detail(request,
                                    username=box.owner.username,
                                    box_name=box.name)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
示例#3
0
    def test_box_date_updated(self):
        """Ensures box's and version's `date_updated` changes with new provider"""
        box = BoxFactory()
        version = BoxVersionFactory(box=box)
        provider = BoxProviderFactory(version=version)

        updated_version = BoxVersion.objects.get(pk=version.pk)
        updated_box = Box.objects.get(pk=box.pk)
        self.assertEqual(updated_version.date_updated, provider.date_updated)
        self.assertEqual(updated_box.date_updated, provider.date_updated)
示例#4
0
    def test_user_with_permissions_cannot_delete_provider(self):
        user = UserFactory()
        box = BoxFactory()
        box.share_with(user, BoxMember.PERM_R)
        version = BoxVersionFactory(box=box)
        provider = BoxProviderFactory(version=version)

        request = self.factory.delete('/url/')
        force_authenticate(request, user=user)
        response = self.view_detail(request,
                                    username=box.owner.username,
                                    box_name=box.name,
                                    version=version.version,
                                    provider=provider.provider)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
示例#5
0
    def test_on_download_only_number_of_pulls_changes(self):
        provider = BoxProviderFactory()

        request = self.factory.get('/url/')
        force_authenticate(request, user=provider.owner)
        response = self.view(request,
                             username=provider.owner.username,
                             box_name=provider.box.name,
                             version=provider.version.version,
                             provider=provider.provider)

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        updated_provider = BoxProvider.objects.get(pk=provider.pk)
        self.assertEqual(provider.pulls + 1, updated_provider.pulls)
        self.assertEqual(provider.date_modified,
                         updated_provider.date_modified)
示例#6
0
    def test_user_with_permissions_can_view_uploads(self):
        user = UserFactory()
        box = BoxFactory()
        box.share_with(user, BoxMember.PERM_R)
        version = BoxVersionFactory(box=box)
        provider = BoxProviderFactory(version=version)
        BoxUploadFactory(provider=provider)
        BoxUploadFactory(provider=provider, file_content=b'test2')

        request = self.factory.get('/url/')
        force_authenticate(request, user=user)
        response = self.view_list(
            request,
            username=box.owner.username,
            box_name=box.name,
            version=version.version,
            provider=provider.provider,
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['count'], 2)
示例#7
0
    def test_upload_cannot_be_initiated_for_completed_provider(self):
        user = UserFactory()
        box = BoxFactory(owner=user)
        box_version = BoxVersionFactory(box=box)
        box_provider = BoxProviderFactory(version=box_version)

        data = {
            'file_size': 100,
            'checksum_type': BoxProvider.SHA256,
            'checksum': 'asdf',
        }
        request = self.factory.post('/url/', data=data)
        force_authenticate(request, user=user)

        response = self.view_list(
            request,
            username=box.owner.username,
            box_name=box.name,
            version=box_version.version,
            provider=box_provider.provider,
        )

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)