Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir 插件分析器不支持的媒体类型错误:在Exunit测试中删除请求_Elixir - Fatal编程技术网

Elixir 插件分析器不支持的媒体类型错误:在Exunit测试中删除请求

Elixir 插件分析器不支持的媒体类型错误:在Exunit测试中删除请求,elixir,Elixir,在我的测试中,我用json为每个路由点击路由器,Plug.parser只接受json。这很好,除了使用delete方法的测试外,该方法总是失败,因为不支持的内容类型为multipart/mixed。我正在发送一个带有delete请求的空正文,在标题中使用我的application/json作为内容类型,但我认为_method参数导致它被拒绝为错误的内容类型-尽管这不会发生在put方法中,该方法也需要将_方法添加到请求正文中 test "inactivate" do {id, token} =

在我的测试中,我用json为每个路由点击路由器,Plug.parser只接受json。这很好,除了使用delete方法的测试外,该方法总是失败,因为不支持的内容类型为multipart/mixed。我正在发送一个带有delete请求的空正文,在标题中使用我的application/json作为内容类型,但我认为_method参数导致它被拒绝为错误的内容类型-尽管这不会发生在put方法中,该方法也需要将_方法添加到请求正文中

test "inactivate" do
  {id, token} = register
  response = Myapp.Router.call(conn(:delete, "/api/manager/tenants/" <> id, 
    [], headers: [{"content-type", "application/json"}, {"token", token}] ) |> Plug.Conn.fetch_params(), @opts)
  assert response.status == 200
end
测试“停用”do
{id,token}=寄存器
response=Myapp.Router.call(conn(:delete,“/api/manager/tenants/”id,
[],标题:[{“内容类型”,“应用程序/json”},{“令牌”,令牌}])|>Plug.Conn.fetch_params(),@opts)
assert response.status==200
结束

当使用httprequester访问相同的删除路由时,它们工作正常,不会被插件解析器停止。Router.call在测试中处理http请求的方式不同吗?

Phoenix现在附带了一个
MyApp.ConnCase
。您应该在运行控制器测试时使用它。它为测试控制器提供了方便。每次调用http方法(如
get conn(),“/”
)时,它都会为您遍历端点和路由器中的插件堆栈

在您的情况下,使用
MyApp.ConnCase
的删除请求如下:

conn = conn()
  |> put_req_header("content-type", "application/json")
  |> put_req_header("token", token)
  |> delete("/api/manager/tenants/" <> id, params)

assert response(conn, 200)
conn=conn()
|>put请求头(“内容类型”、“应用程序/json”)
|>放置请求头(“令牌”,令牌)
|>删除(“/api/manager/tenants/”id,参数)
断言响应(conn,200)

如果有帮助,请告诉我。

凤凰卫视现在附带了一个
MyApp.ConnCase
。您应该在运行控制器测试时使用它。它为测试控制器提供了便利。您不会发送空的正文。空列表表示空参数。您可以尝试将其设置为空字符串
,但这可能会失败,因为它不是有效的JSON。或者发送“{}”或者不发送任何东西(nil)。这很有效。我必须发送nil作为主体。我仍在使用v0.10,并且需要大量代码库才能升级,但这让测试更容易!!