Merge remote-tracking branch 'origin/translations' into develop
[akkoma] / test / pleroma / http / ex_aws_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.HTTP.ExAwsTest do
6 use ExUnit.Case
7
8 import Tesla.Mock
9 alias Pleroma.HTTP
10
11 @url "https://s3.amazonaws.com/test_bucket/test_image.jpg"
12
13 setup do
14 mock(fn
15 %{method: :get, url: @url, headers: [{"x-amz-bucket-region", "us-east-1"}]} ->
16 %Tesla.Env{
17 status: 200,
18 body: "image-content",
19 headers: [{"x-amz-bucket-region", "us-east-1"}]
20 }
21
22 %{method: :post, url: @url, body: "image-content-2"} ->
23 %Tesla.Env{status: 200, body: "image-content-2"}
24 end)
25
26 :ok
27 end
28
29 describe "request" do
30 test "get" do
31 assert HTTP.ExAws.request(:get, @url, "", [{"x-amz-bucket-region", "us-east-1"}]) == {
32 :ok,
33 %{
34 body: "image-content",
35 headers: [{"x-amz-bucket-region", "us-east-1"}],
36 status_code: 200
37 }
38 }
39 end
40
41 test "post" do
42 assert HTTP.ExAws.request(:post, @url, "image-content-2", [
43 {"x-amz-bucket-region", "us-east-1"}
44 ]) == {
45 :ok,
46 %{
47 body: "image-content-2",
48 headers: [],
49 status_code: 200
50 }
51 }
52 end
53 end
54 end