Play Framework Testing using MultipartFormData in a FakeRequest

前端 未结 3 505
不知归路
不知归路 2021-02-05 18:30

I am currently in the process of writing some Specs2 tests for may Play Framework 2.2.x application which accepts MultipartFormData submissions as part of it\'s function.

<
3条回答
  •  一整个雨季
    2021-02-05 18:44

    In Play 2.5.x, it is easy to test file upload

      val file = new java.io.File("the.file")
      val part = FilePart[File](key = "thekey", filename = "the.file", contentType = None, ref = file)
      val request =  FakeRequest().withBody(
        MultipartFormData[File](dataParts = Map.empty, files = Seq(part), badParts = Nil)
      )
      val response = controller.create().apply(request)
      status(response) must beEqualTo(201)
    

提交回复
热议问题