logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

mogrifun_test.exs (1126B)


  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.Upload.Filter.MogrifunTest do
  5. use Pleroma.DataCase
  6. import Mock
  7. alias Pleroma.Upload
  8. alias Pleroma.Upload.Filter
  9. test "apply mogrify filter" do
  10. File.cp!(
  11. "test/fixtures/image.jpg",
  12. "test/fixtures/image_tmp.jpg"
  13. )
  14. upload = %Upload{
  15. name: "an… image.jpg",
  16. content_type: "image/jpg",
  17. path: Path.absname("test/fixtures/image_tmp.jpg"),
  18. tempfile: Path.absname("test/fixtures/image_tmp.jpg")
  19. }
  20. task =
  21. Task.async(fn ->
  22. assert_receive {:apply_filter, {}}, 4_000
  23. end)
  24. with_mocks([
  25. {Mogrify, [],
  26. [
  27. open: fn _f -> %Mogrify.Image{} end,
  28. custom: fn _m, _a -> send(task.pid, {:apply_filter, {}}) end,
  29. custom: fn _m, _a, _o -> send(task.pid, {:apply_filter, {}}) end,
  30. save: fn _f, _o -> :ok end
  31. ]}
  32. ]) do
  33. assert Filter.Mogrifun.filter(upload) == {:ok, :filtered}
  34. end
  35. Task.await(task)
  36. end
  37. end