序列化多部分表单请求以在Play 2.1上进行测试 [英] Serializing Multipart Form requests for testing on Play 2.1

查看:95
本文介绍了序列化多部分表单请求以在Play 2.1上进行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在play2.1上为使用route函数使用多部分表单的后置控制器编写测试.

I'm working on play2.1 writing a test for a post controller that uses multipart forms using the route function.

route(
  FakeRequest(POST,
    postControllerRoute().url,
    FakeHeaders(Seq(HeaderNames.CONTENT_TYPE -> Seq("multipart/form-data"))),
    body = body
  ).withAuthToken.withAdmin(adminId))

我发现,要使此代码正常工作,我需要定义此类型的Writeable Writeable [MultipartFormData [TemporaryFile]],因为我的主体变量的类型为MultipartFormData [TemporaryFile].我不确定如何序列化多部分请求,或者这是否是正确的方法.有什么建议吗?

I've found that for this code to work I need to define a writeable of this type Writeable[MultipartFormData[TemporaryFile]] since my body variable is of type MultipartFormData[TemporaryFile]. I'm not sure how to serialize a multipart request or if this is even the right approach. Any suggestions?

已编辑

答案:跳过路由器并直接使用控制器,就像在文档中一样: http://www.playframework.com/documentation/2.1.0/ScalaFunctionalTest

Answer: Skip the router and use the controller directly like in the docs: http://www.playframework.com/documentation/2.1.0/ScalaFunctionalTest

推荐答案

  • 您有两个选择,对MultiPartFormData进行序列化(据我所知)非常棘手.这篇文章可能会有所帮助: https://groups.google .com/forum/?fromgroups =#!topic/play-framework/MPtQlX-cWMQ
  • 您可以跳过route方法.如果要在控制器中测试Action,则只需绕过路由即可.请参阅文档中的测试控制器.如果不通过路由器,则无需提供Writable.很少需要通过路由器,从本质上讲,您首先可以将其写为字节(使用Writer),然后(使用主体解析器)将其转换回Play可以理解的格式.
    • You have two options, searializing MultiPartFormData which is (as far as I can tell) quite tricky to do. This post might help: https://groups.google.com/forum/?fromgroups=#!topic/play-framework/MPtQlX-cWMQ
    • You can skip going though the route method. If you want to test the Action in your controller, you can simply bypass the route. See Testing your Controllers in the documentation. If you do not go through the router, you don't need to supply a Writable. It is rarely needed to go through the router which essentially let's you first write it as bytes (using Writer) and then (using the body parser) convert it back to something Play understands.
    • 这篇关于序列化多部分表单请求以在Play 2.1上进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆