小编Osc*_*son的帖子

使用Supertest测试Express multer文件数组上传

我有一个post端点,它使用multer并获取一个文件数组:

router.post('/api/projects/:id/sessions', upload.array('files', 4), function(req, res, next) {
    ...
}
Run Code Online (Sandbox Code Playgroud)

在测试中,我需要发送一个包含4个文件的数组,我无法弄清楚如何使用supertest执行此操作.这是我使用我在别处看到的方法的非工作测试:

  it('Add a session', function(done) {
        api.post('/api/projects/' + projectId + '/sessions')
            .set('X-Auth', tokenA)
            .attach('files[0]', './test/files/d.zip')
            .attach('files[1]', './test/files/m.csv')
            .attach('files[2]', './test/files/o.15o.txt')
            .attach('files[3]', './test/files/e.n')
            .end(function(err, res) {
                expect(res.status).to.equal(201)
                done(err)
            })
    })
Run Code Online (Sandbox Code Playgroud)

这会返回一个相当长的错误:

Error: Unexpected field
at makeError (/Users/Oscar/Google Drive/CompSci/COMPSCI-YEAR4/FinalProject/gpsapp/node_modules/multer/lib/make-error.js:12:13)
at wrappedFileFilter (/Users/Oscar/Google Drive/CompSci/COMPSCI-YEAR4/FinalProject/gpsapp/node_modules/multer/index.js:39:19)
at Busboy.<anonymous> (/Users/Oscar/Google Drive/CompSci/COMPSCI-YEAR4/FinalProject/gpsapp/node_modules/multer/lib/make-middleware.js:112:7)
at emitMany (events.js:108:13)
at Busboy.emit (events.js:182:7)
at Busboy.emit (/Users/Oscar/Google Drive/CompSci/COMPSCI-YEAR4/FinalProject/gpsapp/node_modules/multer/node_modules/busboy/lib/main.js:31:35)
at PartStream.<anonymous> (/Users/Oscar/Google Drive/CompSci/COMPSCI-YEAR4/FinalProject/gpsapp/node_modules/multer/node_modules/busboy/lib/types/multipart.js:208:13)
at emitOne (events.js:77:13)
at PartStream.emit (events.js:169:7)
at HeaderParser.<anonymous> (/Users/Oscar/Google Drive/CompSci/COMPSCI-YEAR4/FinalProject/gpsapp/node_modules/multer/node_modules/busboy/node_modules/dicer/lib/Dicer.js:51:16)
at emitOne …
Run Code Online (Sandbox Code Playgroud)

testing express supertest multer

5
推荐指数
1
解决办法
2395
查看次数

将参数传递给 django admin 中的内联表单

我有一个从 ModelAdmin 继承的管理类:

class TemplateAdmin (admin.ModelAdmin):
    inlines = (TemplateAttributeInline, CompanyAttributeInline)
    list_display = ("name", "created", "updated","departments")
    list_filter = ['companies__company']
    list_editable = ("departments",)
    search_fields = ("name", "companies__company",)
    exclude = ("companies",)
    save_as = True
Run Code Online (Sandbox Code Playgroud)

我想传递一个参数,TemplateAttributeInline然后将参数传递给TemplateAttributeForm. 做这个的最好方式是什么?

模板属性内联:

class TemplateAttributeInline (admin.TabularInline):
    model = TemplateAttribute
    extra = 0
    sortable_field_name = "display"
    form = TemplateAttributeForm
Run Code Online (Sandbox Code Playgroud)

模板属性表单

class TemplateAttributeForm(forms.ModelForm):
    class Meta:
        model = Template
    def __init__(self,*args, **kwargs):
        super(TemplateAttributeForm, self).__init__(*args, **kwargs) 
        self.fields['attribute'].queryset = Attribute.objects.filter(#WANT TO FILTER BY THE ID OF THE COMPANY THAT OWNS …
Run Code Online (Sandbox Code Playgroud)

django django-forms django-admin

3
推荐指数
1
解决办法
2827
查看次数

更改 Snowflake 阶段时出现“文件格式不存在或未授权”错误

我正在创建雪花文件格式,如下所示:

create or replace file format "db_name"."schema_name".my_csv_unload_format
  type = 'CSV'
  field_delimiter = ',';
Run Code Online (Sandbox Code Playgroud)

然后我尝试将其添加到现有阶段:

alter stage "db_name"."schema_name".my_unloads set
    file_format = (format_name = 'my_csv_unload_format');
Run Code Online (Sandbox Code Playgroud)

但是,在运行此查询时,我收到错误:

SQL compilation error: File format 'MY_CSV_UNLOAD_FORMAT' does not exist or not authorized.
Run Code Online (Sandbox Code Playgroud)

我看不出我在这里做错了什么。我是否需要在某处向文件格式添加一些权限?

snowflake-cloud-data-platform

3
推荐指数
1
解决办法
1万
查看次数