formatting the code

This commit is contained in:
Maksim Pechnikov 2018-12-04 17:48:55 +03:00
parent 5c6d47614d
commit dd8aee332c
6 changed files with 57 additions and 16 deletions

View file

@ -1,4 +1,8 @@
defmodule Pleroma.HTTP.Connection do defmodule Pleroma.HTTP.Connection do
@moduledoc """
Connection for http-requests.
"""
@hackney_options [pool: :default] @hackney_options [pool: :default]
@adapter Application.get_env(:tesla, :adapter) @adapter Application.get_env(:tesla, :adapter)

View file

@ -1,8 +1,10 @@
defmodule Pleroma.HTTP do defmodule Pleroma.HTTP do
require HTTPoison
alias Pleroma.HTTP.Connection alias Pleroma.HTTP.Connection
alias Pleroma.HTTP.RequestBuilder, as: Builder alias Pleroma.HTTP.RequestBuilder, as: Builder
@doc """
Builds and perform http request.
"""
def request(method, url, body \\ "", headers \\ [], options \\ []) do def request(method, url, body \\ "", headers \\ [], options \\ []) do
options = options =
process_request_options(options) process_request_options(options)
@ -19,6 +21,7 @@ def request(method, url, body \\ "", headers \\ [], options \\ []) do
end end
defp process_sni_options(options, nil), do: options defp process_sni_options(options, nil), do: options
defp process_sni_options(options, url) do defp process_sni_options(options, url) do
uri = URI.parse(url) uri = URI.parse(url)
host = uri.host |> to_charlist() host = uri.host |> to_charlist()

View file

@ -4,6 +4,7 @@ defmodule Pleroma.FormatterTest do
use Pleroma.DataCase use Pleroma.DataCase
import Pleroma.Factory import Pleroma.Factory
setup_all do setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok :ok

View file

@ -27,13 +27,17 @@ def get("https://osada.macgirvin.com/channel/mike", _, _, _) do
{:ok, {:ok,
%Tesla.Env{ %Tesla.Env{
status: 200, status: 200,
body: File.read!( body:
"test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json" File.read!("test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json")
)
}} }}
end end
def get("https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com", _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do def get(
"https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com",
_,
_,
Accept: "application/xrd+xml,application/jrd+json"
) do
{:ok, {:ok,
%Tesla.Env{ %Tesla.Env{
status: 200, status: 200,
@ -41,8 +45,12 @@ def get("https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@os
}} }}
end end
def get("https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191", def get(
_, _, [Accept: "application/xrd+xml,application/jrd+json"]) do "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191",
_,
_,
Accept: "application/xrd+xml,application/jrd+json"
) do
{:ok, {:ok,
%Tesla.Env{ %Tesla.Env{
status: 200, status: 200,
@ -58,8 +66,12 @@ def get("https://pawoo.net/users/pekorino.atom", _, _, _) do
}} }}
end end
def get("https://pawoo.net/.well-known/webfinger?resource=acct:https://pawoo.net/users/pekorino", def get(
_, _, [Accept: "application/xrd+xml,application/jrd+json"]) do "https://pawoo.net/.well-known/webfinger?resource=acct:https://pawoo.net/users/pekorino",
_,
_,
Accept: "application/xrd+xml,application/jrd+json"
) do
{:ok, {:ok,
%Tesla.Env{ %Tesla.Env{
status: 200, status: 200,
@ -67,7 +79,12 @@ def get("https://pawoo.net/.well-known/webfinger?resource=acct:https://pawoo.net
}} }}
end end
def get("https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/18330.atom", _, _, _) do def get(
"https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/18330.atom",
_,
_,
_
) do
{:ok, {:ok,
%Tesla.Env{ %Tesla.Env{
status: 200, status: 200,
@ -75,8 +92,12 @@ def get("https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/
}} }}
end end
def get("https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=acct:https://social.stopwatchingus-heidelberg.de/user/18330", def get(
_, _, [Accept: "application/xrd+xml,application/jrd+json"]) do "https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=acct:https://social.stopwatchingus-heidelberg.de/user/18330",
_,
_,
Accept: "application/xrd+xml,application/jrd+json"
) do
{:ok, {:ok,
%Tesla.Env{ %Tesla.Env{
status: 200, status: 200,
@ -92,8 +113,12 @@ def get("https://mamot.fr/users/Skruyb.atom", _, _, _) do
}} }}
end end
def get("https://mamot.fr/.well-known/webfinger?resource=acct:https://mamot.fr/users/Skruyb", def get(
_, _, [Accept: "application/xrd+xml,application/jrd+json"]) do "https://mamot.fr/.well-known/webfinger?resource=acct:https://mamot.fr/users/Skruyb",
_,
_,
Accept: "application/xrd+xml,application/jrd+json"
) do
{:ok, {:ok,
%Tesla.Env{ %Tesla.Env{
status: 200, status: 200,
@ -101,7 +126,12 @@ def get("https://mamot.fr/.well-known/webfinger?resource=acct:https://mamot.fr/u
}} }}
end end
def get("https://social.heldscal.la/.well-known/webfinger?resource=nonexistant@social.heldscal.la", _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do def get(
"https://social.heldscal.la/.well-known/webfinger?resource=nonexistant@social.heldscal.la",
_,
_,
Accept: "application/xrd+xml,application/jrd+json"
) do
{:ok, {:ok,
%Tesla.Env{ %Tesla.Env{
status: 200, status: 200,

View file

@ -4,10 +4,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
alias Pleroma.Web.ActivityPub.{UserView, ObjectView} alias Pleroma.Web.ActivityPub.{UserView, ObjectView}
alias Pleroma.{Repo, User} alias Pleroma.{Repo, User}
alias Pleroma.Activity alias Pleroma.Activity
setup_all do setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok :ok
end end
describe "/relay" do describe "/relay" do
test "with the relay active, it returns the relay user", %{conn: conn} do test "with the relay active, it returns the relay user", %{conn: conn} do
res = res =

View file

@ -11,6 +11,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
import Pleroma.Factory import Pleroma.Factory
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
setup_all do setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok :ok