Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / test / upload / filter / mogrify_test.exs
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
5 defmodule Pleroma.Upload.Filter.MogrifyTest do
6 use Pleroma.DataCase
7 import Mock
8
9 alias Pleroma.Config
10 alias Pleroma.Upload
11 alias Pleroma.Upload.Filter
12
13 clear_config([Filter.Mogrify, :args])
14
15 test "apply mogrify filter" do
16 Config.put([Filter.Mogrify, :args], [{"tint", "40"}])
17
18 File.cp!(
19 "test/fixtures/image.jpg",
20 "test/fixtures/image_tmp.jpg"
21 )
22
23 upload = %Upload{
24 name: "an… image.jpg",
25 content_type: "image/jpg",
26 path: Path.absname("test/fixtures/image_tmp.jpg"),
27 tempfile: Path.absname("test/fixtures/image_tmp.jpg")
28 }
29
30 task =
31 Task.async(fn ->
32 assert_receive {:apply_filter, {_, "tint", "40"}}, 4_000
33 end)
34
35 with_mock Mogrify,
36 open: fn _f -> %Mogrify.Image{} end,
37 custom: fn _m, _a -> :ok end,
38 custom: fn m, a, o -> send(task.pid, {:apply_filter, {m, a, o}}) end,
39 save: fn _f, _o -> :ok end do
40 assert Filter.Mogrify.filter(upload) == :ok
41 end
42
43 Task.await(task)
44 end
45 end