Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4KB

  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. defmodule Pleroma.Uploaders.LocalTest do
  5. use Pleroma.DataCase
  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_path = "local_upload/files/image.jpg"
  15. file = %Pleroma.Upload{
  16. name: "image.jpg",
  17. content_type: "image/jpg",
  18. path: file_path,
  19. tempfile: Path.absname("test/fixtures/image_tmp.jpg")
  20. }
  21. assert Local.put_file(file) == :ok
  22. assert Path.join([Local.upload_path(), file_path])
  23. |> File.exists?()
  24. end
  25. end
  26. describe "delete_file/1" do
  27. test "deletes local file" do
  28. file_path = "local_upload/files/image.jpg"
  29. file = %Pleroma.Upload{
  30. name: "image.jpg",
  31. content_type: "image/jpg",
  32. path: file_path,
  33. tempfile: Path.absname("test/fixtures/image_tmp.jpg")
  34. }
  35. :ok = Local.put_file(file)
  36. local_path = Path.join([Local.upload_path(), file_path])
  37. assert File.exists?(local_path)
  38. Local.delete_file(file_path)
  39. refute File.exists?(local_path)
  40. end
  41. end
  42. end