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)
16 url: "http://example.com/hello",
17 headers: [{"content-type", "application/json"}]
19 json(%{"my" => "data"})
21 %{method: :head, url: "http://example.com/hello"} ->
22 %Tesla.Env{status: 200, body: ""}
24 %{method: :get, url: "http://example.com/hello"} ->
25 %Tesla.Env{status: 200, body: "hello"}
27 %{method: :post, url: "http://example.com/world"} ->
28 %Tesla.Env{status: 200, body: "world"}
35 test "returns successfully result" do
36 assert HTTP.head("http://example.com/hello") == {:ok, %Tesla.Env{status: 200, body: ""}}
41 test "returns successfully result" do
42 assert HTTP.get("http://example.com/hello") == {
44 %Tesla.Env{status: 200, body: "hello"}
49 describe "get/2 (with headers)" do
50 test "returns successfully result for json content-type" do
51 assert HTTP.get("http://example.com/hello", [{"content-type", "application/json"}]) ==
56 body: "{\"my\":\"data\"}",
57 headers: [{"content-type", "application/json"}]
64 test "returns successfully result" do
65 assert HTTP.post("http://example.com/world", "") == {
67 %Tesla.Env{status: 200, body: "world"}