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.

45 lines
1.1KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2019 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
  34. end
  35. Task.await(task)
  36. end
  37. end