fix tests

This commit is contained in:
Maksim Pechnikov 2020-05-26 06:38:45 +03:00
parent 6e9e21d6fc
commit 65d9692975
5 changed files with 23 additions and 3 deletions

View File

@ -10,10 +10,10 @@ defmodule Pleroma.Web.MediaProxy do
@base64_opts [padding: false]
@spec in_deleted_urls(String.t()) :: boolean()
def in_deleted_urls(url), do: !!Cachex.get!(:deleted_urls_cache, url)
def in_deleted_urls(url), do: elem(Cachex.exists?(:deleted_urls_cache, url), 1)
def remove_from_deleted_urls(urls) when is_list(urls) do
Enum.each(urls, &remove_from_deleted_urls(&1))
Enum.each(urls, &remove_from_deleted_urls/1)
end
def remove_from_deleted_urls(url) when is_binary(url) do
@ -21,7 +21,7 @@ defmodule Pleroma.Web.MediaProxy do
end
def put_in_deleted_urls(urls) when is_list(urls) do
Enum.each(urls, &put_in_deleted_urls(&1))
Enum.each(urls, &put_in_deleted_urls/1)
end
def put_in_deleted_urls(url) when is_binary(url) do

View File

@ -11,6 +11,11 @@ defmodule Pleroma.Web.MediaProxy.InvalidationTest do
setup do: clear_config([:media_proxy])
setup do
on_exit(fn -> Cachex.purge(:deleted_urls_cache) end)
:ok
end
describe "Invalidation.Http" do
test "perform request to clear cache" do
Config.put([:media_proxy, :enabled], false)

View File

@ -5,6 +5,11 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.HttpTest do
import ExUnit.CaptureLog
import Tesla.Mock
setup do
on_exit(fn -> Cachex.purge(:deleted_urls_cache) end)
:ok
end
test "logs hasn't error message when request is valid" do
mock(fn
%{method: :purge, url: "http://example.com/media/example.jpg"} ->

View File

@ -4,6 +4,11 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.ScriptTest do
import ExUnit.CaptureLog
setup do
on_exit(fn -> Cachex.purge(:deleted_urls_cache) end)
:ok
end
test "it logger error when script not found" do
assert capture_log(fn ->
assert Invalidation.Script.purge(

View File

@ -10,6 +10,11 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
setup do: clear_config(:media_proxy)
setup do: clear_config([Pleroma.Web.Endpoint, :secret_key_base])
setup do
on_exit(fn -> Cachex.purge(:deleted_urls_cache) end)
:ok
end
test "it returns 404 when MediaProxy disabled", %{conn: conn} do
Config.put([:media_proxy, :enabled], false)