Merge branch 'develop' into feature/admin-api-user-statuses
[akkoma] / test / upload / filter / mogrify_test.exs
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
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 setup do
14 filter = Config.get([Filter.Mogrify, :args])
15
16 on_exit(fn ->
17 Config.put([Filter.Mogrify, :args], filter)
18 end)
19 end
20
21 test "apply mogrify filter" do
22 Config.put([Filter.Mogrify, :args], [{"tint", "40"}])
23
24 File.cp!(
25 "test/fixtures/image.jpg",
26 "test/fixtures/image_tmp.jpg"
27 )
28
29 upload = %Upload{
30 name: "an… image.jpg",
31 content_type: "image/jpg",
32 path: Path.absname("test/fixtures/image_tmp.jpg"),
33 tempfile: Path.absname("test/fixtures/image_tmp.jpg")
34 }
35
36 task =
37 Task.async(fn ->
38 assert_receive {:apply_filter, {_, "tint", "40"}}, 4_000
39 end)
40
41 with_mock Mogrify,
42 open: fn _f -> %Mogrify.Image{} end,
43 custom: fn _m, _a -> :ok end,
44 custom: fn m, a, o -> send(task.pid, {:apply_filter, {m, a, o}}) end,
45 save: fn _f, _o -> :ok end do
46 assert Filter.Mogrify.filter(upload) == :ok
47 end
48
49 Task.await(task)
50 end
51 end