logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

mediaproxy_warming_policy_test.exs (1343B)


  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. defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.HTTP
  7. alias Pleroma.Tests.ObanHelpers
  8. alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
  9. import Mock
  10. @message %{
  11. "type" => "Create",
  12. "object" => %{
  13. "type" => "Note",
  14. "content" => "content",
  15. "attachment" => [
  16. %{"url" => [%{"href" => "http://example.com/image.jpg"}]}
  17. ]
  18. }
  19. }
  20. setup do: clear_config([:media_proxy, :enabled], true)
  21. test "it prefetches media proxy URIs" do
  22. with_mock HTTP, get: fn _, _, _ -> {:ok, []} end do
  23. MediaProxyWarmingPolicy.filter(@message)
  24. ObanHelpers.perform_all()
  25. # Performing jobs which has been just enqueued
  26. ObanHelpers.perform_all()
  27. assert called(HTTP.get(:_, :_, :_))
  28. end
  29. end
  30. test "it does nothing when no attachments are present" do
  31. object =
  32. @message["object"]
  33. |> Map.delete("attachment")
  34. message =
  35. @message
  36. |> Map.put("object", object)
  37. with_mock HTTP, get: fn _, _, _ -> {:ok, []} end do
  38. MediaProxyWarmingPolicy.filter(message)
  39. refute called(HTTP.get(:_, :_, :_))
  40. end
  41. end
  42. end