Use Logger.info for {:reject, reason}
[akkoma] / test / uploaders / local_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Uploaders.LocalTest do
6 use Pleroma.DataCase
7 alias Pleroma.Uploaders.Local
8
9 describe "get_file/1" do
10 test "it returns path to local folder for files" do
11 assert Local.get_file("") == {:ok, {:static_dir, "test/uploads"}}
12 end
13 end
14
15 describe "put_file/1" do
16 test "put file to local folder" do
17 file_path = "local_upload/files/image.jpg"
18
19 file = %Pleroma.Upload{
20 name: "image.jpg",
21 content_type: "image/jpg",
22 path: file_path,
23 tempfile: Path.absname("test/fixtures/image_tmp.jpg")
24 }
25
26 assert Local.put_file(file) == :ok
27
28 assert Path.join([Local.upload_path(), file_path])
29 |> File.exists?()
30 end
31 end
32
33 describe "delete_file/1" do
34 test "deletes local file" do
35 file_path = "local_upload/files/image.jpg"
36
37 file = %Pleroma.Upload{
38 name: "image.jpg",
39 content_type: "image/jpg",
40 path: file_path,
41 tempfile: Path.absname("test/fixtures/image_tmp.jpg")
42 }
43
44 :ok = Local.put_file(file)
45 local_path = Path.join([Local.upload_path(), file_path])
46 assert File.exists?(local_path)
47
48 Local.delete_file(file_path)
49
50 refute File.exists?(local_path)
51 end
52 end
53 end