logo

pleroma

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

mogrify_test.exs (1102B)


  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.MogrifyTest do
  5. use Pleroma.DataCase
  6. import Mock
  7. alias Pleroma.Upload.Filter
  8. test "apply mogrify filter" do
  9. clear_config(Filter.Mogrify, args: [{"tint", "40"}])
  10. File.cp!(
  11. "test/fixtures/image.jpg",
  12. "test/fixtures/image_tmp.jpg"
  13. )
  14. upload = %Pleroma.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, {_, "tint", "40"}}, 4_000
  23. end)
  24. with_mock Mogrify,
  25. open: fn _f -> %Mogrify.Image{} end,
  26. custom: fn _m, _a -> :ok end,
  27. custom: fn m, a, o -> send(task.pid, {:apply_filter, {m, a, o}}) end,
  28. save: fn _f, _o -> :ok end do
  29. assert Filter.Mogrify.filter(upload) == {:ok, :filtered}
  30. end
  31. Task.await(task)
  32. end
  33. end