Пример #1
0
    def test_file_content_overrides_file(self):
        class buffer:
            def read(self):
                return 'from-file'

        f = types.File(content='from-content', file=buffer())
        assert f.content == 'from-content'
Пример #2
0
    def test_file_property_content(self):
        class buffer:
            def read(self):
                return 'from-file'

        f = types.File(content=six.b('from-content'))
        assert f.file.read() == six.b('from-content')
Пример #3
0
    def test_file_get_content_by_reading(self):
        class buffer:
            def read(self):
                return 'abcdef'

        f = types.File(file=buffer())
        assert f.content == 'abcdef'
Пример #4
0
    def test_file_property_file(self):
        class buffer:
            def read(self):
                return 'from-file'

        buf = buffer()
        f = types.File(file=buf)
        assert f.file is buf
Пример #5
0
    def test_file_setting_content_discards_file(self):
        class buffer:
            def read(self):
                return 'from-file'

        f = types.File(file=buffer())
        f.content = 'from-content'
        assert f.content == 'from-content'
Пример #6
0
    def test_file_field_storage(self):
        class buffer:
            def read(self):
                return 'from-file'

        class fieldstorage:
            filename = 'static.json'
            file = buffer()
            type = 'application/json'

        f = types.File(fieldstorage=fieldstorage)
        assert f.content == 'from-file'
Пример #7
0
 def get(self):
     """Download one output file"""
     user = User.fetch(pecan.request.context['username'], sub_objects=False)
     if user is None:
         return None
     project_name = pecan.request.context['project_name']
     project = Project.fetch(user.username, project_name, sub_objects=False)
     if project is None:
         return None
     build_id = pecan.request.context['build_id']
     if build_id in ["latest"]:
         build_id = project.get_latest_build_id()
     build = Build.fetch(project, build_id, sub_objects=False)
     if build is None:
         return
     # Get options
     distro = pecan.request.GET.get('distro', None)
     filename = pecan.request.GET.get('filename', None)
     if distro not in supported_distros:
         distro = None
     # Get output folder
     output_folder = build.get_output_folder_path(distro)
     # Test if output folder exists
     if not os.path.isdir(output_folder):
         return None
     # Set headers
     headers = pecan.response.headers
     # Get one file
     if filename is not None and distro is not None:
         file_path = os.path.join(output_folder, filename)
         if not os.path.isfile(file_path):
             return None
         # TODO clean the following lines
         mime = MimeTypes()
         contenttype, _ = mime.guess_type(file_path)
         headers.add("Content-Disposition", str("attachment;filename=%s" % filename))
         fhandler = open(file_path, 'r')
         wsme_file = wtypes.File(filename=filename,
                                 file=fhandler,
                                 contenttype=contenttype)
         return wsme_file.content
     return None