2019-07-16 21:35:43 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-07-16 21:35:43 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Upload.Filter.MogrifunTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
import Mock
|
|
|
|
|
|
|
|
alias Pleroma.Upload
|
|
|
|
alias Pleroma.Upload.Filter
|
|
|
|
|
|
|
|
test "apply mogrify filter" do
|
|
|
|
File.cp!(
|
|
|
|
"test/fixtures/image.jpg",
|
|
|
|
"test/fixtures/image_tmp.jpg"
|
|
|
|
)
|
|
|
|
|
|
|
|
upload = %Upload{
|
|
|
|
name: "an… image.jpg",
|
2020-10-13 15:37:24 +00:00
|
|
|
content_type: "image/jpeg",
|
2019-07-16 21:35:43 +00:00
|
|
|
path: Path.absname("test/fixtures/image_tmp.jpg"),
|
|
|
|
tempfile: Path.absname("test/fixtures/image_tmp.jpg")
|
|
|
|
}
|
|
|
|
|
|
|
|
task =
|
|
|
|
Task.async(fn ->
|
|
|
|
assert_receive {:apply_filter, {}}, 4_000
|
|
|
|
end)
|
|
|
|
|
|
|
|
with_mocks([
|
|
|
|
{Mogrify, [],
|
|
|
|
[
|
|
|
|
open: fn _f -> %Mogrify.Image{} end,
|
|
|
|
custom: fn _m, _a -> send(task.pid, {:apply_filter, {}}) end,
|
|
|
|
custom: fn _m, _a, _o -> send(task.pid, {:apply_filter, {}}) end,
|
|
|
|
save: fn _f, _o -> :ok end
|
|
|
|
]}
|
|
|
|
]) do
|
2020-09-04 22:40:59 +00:00
|
|
|
assert Filter.Mogrifun.filter(upload) == {:ok, :filtered}
|
2019-07-16 21:35:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Task.await(task)
|
|
|
|
end
|
|
|
|
end
|