2019-07-16 21:35:43 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-03 22:44:49 +00:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-07-16 21:35:43 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Upload.Filter.MogrifyTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
import Mock
|
|
|
|
|
|
|
|
alias Pleroma.Upload.Filter
|
|
|
|
|
|
|
|
test "apply mogrify filter" do
|
2020-05-31 07:46:02 +00:00
|
|
|
clear_config(Filter.Mogrify, args: [{"tint", "40"}])
|
2019-07-16 21:35:43 +00:00
|
|
|
|
|
|
|
File.cp!(
|
|
|
|
"test/fixtures/image.jpg",
|
|
|
|
"test/fixtures/image_tmp.jpg"
|
|
|
|
)
|
|
|
|
|
2020-05-31 07:46:02 +00:00
|
|
|
upload = %Pleroma.Upload{
|
2019-07-16 21:35:43 +00:00
|
|
|
name: "an… image.jpg",
|
|
|
|
content_type: "image/jpg",
|
|
|
|
path: Path.absname("test/fixtures/image_tmp.jpg"),
|
|
|
|
tempfile: Path.absname("test/fixtures/image_tmp.jpg")
|
|
|
|
}
|
|
|
|
|
|
|
|
task =
|
|
|
|
Task.async(fn ->
|
|
|
|
assert_receive {:apply_filter, {_, "tint", "40"}}, 4_000
|
|
|
|
end)
|
|
|
|
|
|
|
|
with_mock Mogrify,
|
|
|
|
open: fn _f -> %Mogrify.Image{} end,
|
|
|
|
custom: fn _m, _a -> :ok end,
|
|
|
|
custom: fn m, a, o -> send(task.pid, {:apply_filter, {m, a, o}}) end,
|
|
|
|
save: fn _f, _o -> :ok end do
|
|
|
|
assert Filter.Mogrify.filter(upload) == :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
Task.await(task)
|
|
|
|
end
|
|
|
|
end
|