1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.HTTPTest do
6 use ExUnit.Case, async: true
7 use Pleroma.Tests.Helpers
12 clear_config([:http, :send_user_agent], false)
17 url: "http://example.com/hello",
18 headers: [{"content-type", "application/json"}]
20 json(%{"my" => "data"})
22 %{method: :head, url: "http://example.com/hello"} ->
23 %Tesla.Env{status: 200, body: ""}
25 %{method: :get, url: "http://example.com/hello"} ->
26 %Tesla.Env{status: 200, body: "hello"}
28 %{method: :post, url: "http://example.com/world"} ->
29 %Tesla.Env{status: 200, body: "world"}
36 test "returns successfully result" do
37 assert HTTP.head("http://example.com/hello") == {:ok, %Tesla.Env{status: 200, body: ""}}
42 test "returns successfully result" do
43 assert HTTP.get("http://example.com/hello") == {
45 %Tesla.Env{status: 200, body: "hello"}
50 describe "get/2 (with headers)" do
51 test "returns successfully result for json content-type" do
52 assert HTTP.get("http://example.com/hello", [{"content-type", "application/json"}]) ==
57 body: "{\"my\":\"data\"}",
58 headers: [{"content-type", "application/json"}]
65 test "returns successfully result" do
66 assert HTTP.post("http://example.com/world", "") == {
68 %Tesla.Env{status: 200, body: "world"}