logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

local_test.exs (1564B)


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