Пример #1
0
    def test_build_downloadfile_response(self):

        request = self._prepare_request_mock()
        with patch('django.views.static.serve') as serve_mock:
            response = build_downloadfile_response(request, 'manage.py', '/')
            self.assertNotEqual(response, None)
            serve_mock.assert_called_once_with(request, 'manage.py', document_root='/')
Пример #2
0
    def test_build_downloadfile_response_sendfile(self):

        request = self._prepare_request_mock()
        with patch('wirecloud.commons.utils.http.build_sendfile_response') as serve_mock:
            response = build_downloadfile_response(request, 'manage.py', '/')
            self.assertNotEqual(response, None)
            serve_mock.assert_called_once_with('manage.py', '/')
Пример #3
0
def serve_showcase_media(request, vendor, name, version, file_path):

    resource = get_object_or_404(CatalogueResource,
                                 vendor=vendor,
                                 short_name=name,
                                 version=version)
    if resource.resource_type() not in ['widget', 'operator']:
        raise Http404()

    # For now, all widgets and operators are freely accessible/distributable
    #if not resource.is_available_for(request.user):
    #    return build_error_response(request, 403, "Forbidden")

    if resource.resource_type() == 'widget' and request.GET.get(
            'entrypoint', 'false') == 'true':
        return process_widget_code(request, resource)

    base_dir = showcase_utils.wgt_deployer.get_base_dir(vendor, name, version)
    response = build_downloadfile_response(request, file_path, base_dir)
    if response.status_code == 302:
        response['Location'] = reverse('wirecloud.showcase_media',
                                       kwargs={
                                           "vendor": vendor,
                                           "name": name,
                                           "version": version,
                                           "file_path": response['Location']
                                       })

    return response
Пример #4
0
    def test_build_downloadfile_response_sendfile(self):

        request = self._prepare_request_mock()
        with patch('wirecloud.commons.utils.http.build_sendfile_response') as serve_mock:
            response = build_downloadfile_response(request, 'manage.py', '/')
            self.assertNotEqual(response, None)
            serve_mock.assert_called_once_with('manage.py', '/')
Пример #5
0
    def test_build_downloadfile_response(self):

        request = self._prepare_request_mock()
        with patch('django.views.static.serve') as serve_mock:
            response = build_downloadfile_response(request, 'manage.py', '/')
            self.assertNotEqual(response, None)
            serve_mock.assert_called_once_with(request, 'manage.py', document_root='/')
Пример #6
0
def serve_catalogue_media(request, vendor, name, version, file_path):

    base_dir = catalogue_utils.wgt_deployer.get_base_dir(vendor, name, version)

    response = build_downloadfile_response(request, file_path, base_dir)
    if response.status_code == 302:
        response['Location'] = reverse('wirecloud_catalogue.media', kwargs= {"vendor": vendor, "name": name, "version": version, "file_path": response['Location']})

    return response
Пример #7
0
    def read(self, request, vendor, name, version):

        resource = get_object_or_404(CatalogueResource, vendor=vendor, short_name=name, version=version)
        if not request.user.is_superuser and not resource.is_available_for(request.user):
            return build_error_response(request, 403, _('You are not allowed to retrieve info about this resource'))

        file_name = '_'.join((vendor, name, version)) + '.wgt'
        base_dir = catalogue_utils.wgt_deployer.get_base_dir(vendor, name, version)
        response = build_downloadfile_response(request, file_name, base_dir)
        response['Content-Type'] = resource.mimetype
        return response
Пример #8
0
    def read(self, request, vendor, name, version):

        resource = get_object_or_404(CatalogueResource, vendor=vendor, short_name=name, version=version)
        if not request.user.is_superuser and not resource.is_available_for(request.user):
            return build_error_response(request, 403, _('You are not allowed to retrieve info about this resource'))

        file_name = '_'.join((vendor, name, version)) + '.wgt'
        base_dir = catalogue_utils.wgt_deployer.get_base_dir(vendor, name, version)
        response = build_downloadfile_response(request, file_name, base_dir)
        response['Content-Type'] = resource.mimetype
        return response
Пример #9
0
def serve_catalogue_media(request, vendor, name, version, file_path):

    base_dir = catalogue_utils.wgt_deployer.get_base_dir(vendor, name, version)

    response = build_downloadfile_response(request, file_path, base_dir)
    if response.status_code == 302:
        response['Location'] = reverse('wirecloud_catalogue.media',
                                       kwargs={
                                           "vendor": vendor,
                                           "name": name,
                                           "version": version,
                                           "file_path": response['Location']
                                       })

    return response
Пример #10
0
def serve_showcase_media(request, vendor, name, version, file_path):

    resource = get_object_or_404(CatalogueResource, vendor=vendor, short_name=name, version=version)
    if resource.resource_type() not in ['widget', 'operator']:
        raise Http404()

    # For now, all widgets are freely accessible/distributable
    #if not resource.is_available_for(request.user):
    #    return build_error_response(request, 403, "Forbidden")

    base_dir = showcase_utils.wgt_deployer.get_base_dir(vendor, name, version)
    response = build_downloadfile_response(request, file_path, base_dir)
    if response.status_code == 302:
        response['Location'] = reverse('wirecloud.showcase_media', kwargs= {"vendor": vendor, "name": name, "version": version, "file_path": response['Location']})

    return response