如何在play scala框架中测试多部分表单数据的操作

时间:2015-09-14 14:30:14

标签: scala multipartform-data specs2 playframework-2.4

我需要一个动作方法来接收文件上传,我也想测试它。但我的测试是抛出错误

我的行动:

def upload = Action.async(parse.multipartFormData) { request =>
  val multipart = request.body
  val optFile = multipart.files.toList.headOption.map(_.ref.file)

  optFile match {
    case None => Future.successful(Ok("got none"))
    case Some(file) => Future.successful(Ok("got some"))
  }
}

我想测试此方法,但收到错误:

我的测试

"create notes" in {

  val temp = SingletonTemporaryFileCreator.create("test", "png")
  val tempFile = TemporaryFile(temp)
  val filePart = FilePart[TemporaryFile](key = "image", filename = "debug.png", contentType = Some("image/png"), ref = tempFile)
  val form = MultipartFormData(dataParts = Map(), files = Seq(filePart), badParts = Seq(), missingFileParts = Seq())


  val notesController = new NotesController()
  val result = notesController.upload().apply(FakeRequest(POST, "/notes/upload").withMultipartFormDataBody(form))

  status(result) mustEqual OK
}

错误:

[error]  found   : play.api.libs.iteratee.Iteratee[Array[Byte],play.api.mvc.Result]
[error]  required: scala.concurrent.Future[play.api.mvc.Result]
[error]       status(result) mustEqual OK
[error]              ^
[error] one error found
[error] (root/test:compileIncremental) Compilation failed

0 个答案:

没有答案