Tests: Remove unneeded explicit cachex use.

Only use cachex when we're actually testing it.
This commit is contained in:
lain 2020-12-18 13:18:17 +01:00
parent c1129ff674
commit b4b68b71fc
17 changed files with 10 additions and 47 deletions

View file

@ -100,7 +100,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
end) end)
Pleroma.Repo.delete(user) Pleroma.Repo.delete(user)
Cachex.clear(:user_cache) User.invalidate_cache(user)
Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance]) Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance])
@ -137,7 +137,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
end) end)
Pleroma.Repo.delete(user) Pleroma.Repo.delete(user)
Cachex.clear(:user_cache) User.invalidate_cache(user)
Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance, "--force"]) Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance, "--force"])

View file

@ -80,7 +80,6 @@ defmodule Pleroma.CaptchaTest do
assert is_binary(answer) assert is_binary(answer)
assert :ok = Captcha.validate(token, "63615261b77f5354fb8c4e4986477555", answer) assert :ok = Captcha.validate(token, "63615261b77f5354fb8c4e4986477555", answer)
Cachex.del(:used_captcha_cache, token)
end end
test "doesn't validate invalid answer" do test "doesn't validate invalid answer" do

View file

@ -3,7 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.User.QueryTest do defmodule Pleroma.User.QueryTest do
use Pleroma.DataCase, async: true use Pleroma.DataCase
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.User alias Pleroma.User

View file

@ -84,7 +84,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
) )
Pleroma.Repo.delete(user) Pleroma.Repo.delete(user)
Cachex.clear(:user_cache) User.invalidate_cache(user)
assert {:ok, %Activity{} = activity} = Relay.unfollow(user_ap_id, %{force: true}) assert {:ok, %Activity{} = activity} = Relay.unfollow(user_ap_id, %{force: true})

View file

@ -51,6 +51,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do
Object.normalize(activity.data["object"]) Object.normalize(activity.data["object"])
|> Repo.delete() |> Repo.delete()
# TODO: mock cachex
Cachex.del(:object_cache, "object:#{object.data["id"]}") Cachex.del(:object_cache, "object:#{object.data["id"]}")
deleting_user = insert(:user) deleting_user = insert(:user)

View file

@ -159,7 +159,7 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
user: user user: user
} do } do
Repo.delete(user) Repo.delete(user)
Cachex.clear(:user_cache) Pleroma.User.invalidate_cache(user)
refute Visibility.is_private?(direct) refute Visibility.is_private?(direct)
end end

View file

@ -12,10 +12,6 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
setup do: clear_config([:media_proxy]) setup do: clear_config([:media_proxy])
setup do
on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
end
setup do setup do
admin = insert(:user, is_admin: true) admin = insert(:user, is_admin: true)
token = insert(:oauth_admin_token, user: admin) token = insert(:oauth_admin_token, user: admin)

View file

@ -1411,8 +1411,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|> json_response_and_validate_schema(:ok) |> json_response_and_validate_schema(:ok)
assert Token |> Repo.get_by(token: access_token) |> Repo.preload(:user) |> Map.get(:user) assert Token |> Repo.get_by(token: access_token) |> Repo.preload(:user) |> Map.get(:user)
Cachex.del(:used_captcha_cache, token)
end end
test "returns 400 if any captcha field is not provided", %{conn: conn} do test "returns 400 if any captcha field is not provided", %{conn: conn} do

View file

@ -67,10 +67,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
"sensitive" => "0" "sensitive" => "0"
}) })
{:ok, ttl} = Cachex.ttl(:idempotency_cache, idempotency_key)
# Six hours
assert ttl > :timer.seconds(6 * 60 * 60 - 1)
assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu", "sensitive" => false} = assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu", "sensitive" => false} =
json_response_and_validate_schema(conn_one, 200) json_response_and_validate_schema(conn_one, 200)

View file

@ -160,7 +160,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
{:ok, activity} = CommonAPI.post(user, %{status: "Hey @shp!", visibility: "direct"}) {:ok, activity} = CommonAPI.post(user, %{status: "Hey @shp!", visibility: "direct"})
Repo.delete(user) Repo.delete(user)
Cachex.clear(:user_cache) User.invalidate_cache(user)
finger_url = finger_url =
"https://localhost/.well-known/webfinger?resource=acct:#{user.nickname}@localhost" "https://localhost/.well-known/webfinger?resource=acct:#{user.nickname}@localhost"
@ -194,7 +194,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|> Ecto.Changeset.change(%{ap_id: "#{user.ap_id}/extension/#{user.nickname}"}) |> Ecto.Changeset.change(%{ap_id: "#{user.ap_id}/extension/#{user.nickname}"})
|> Repo.update() |> Repo.update()
Cachex.clear(:user_cache) User.invalidate_cache(user)
result = StatusView.render("show.json", activity: activity) result = StatusView.render("show.json", activity: activity)

View file

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

View file

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

View file

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

View file

@ -10,10 +10,6 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
alias Pleroma.Web.MediaProxy alias Pleroma.Web.MediaProxy
alias Plug.Conn alias Plug.Conn
setup do
on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
end
describe "Media Proxy" do describe "Media Proxy" do
setup do setup do
clear_config([:media_proxy, :enabled], true) clear_config([:media_proxy, :enabled], true)

View file

@ -3,7 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.CacheTest do defmodule Pleroma.Web.Plugs.CacheTest do
use ExUnit.Case, async: true use Pleroma.DataCase
use Plug.Test use Plug.Test
alias Pleroma.Web.Plugs.Cache alias Pleroma.Web.Plugs.Cache
@ -24,11 +24,6 @@ defmodule Pleroma.Web.Plugs.CacheTest do
@ttl 5 @ttl 5
setup do
Cachex.clear(:web_resp_cache)
:ok
end
test "caches a response" do test "caches a response" do
assert @miss_resp == assert @miss_resp ==
conn(:get, "/") conn(:get, "/")

View file

@ -3,7 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrlTest do defmodule Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrlTest do
use ExUnit.Case, async: true use Pleroma.DataCase
test "s3 signed url is parsed correct for expiration time" do test "s3 signed url is parsed correct for expiration time" do
url = "https://pleroma.social/amz" url = "https://pleroma.social/amz"

View file

@ -423,10 +423,4 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert is_binary(error) assert is_binary(error)
refute User.get_cached_by_nickname("lain") refute User.get_cached_by_nickname("lain")
end end
setup do
Supervisor.terminate_child(Pleroma.Supervisor, Cachex)
Supervisor.restart_child(Pleroma.Supervisor, Cachex)
:ok
end
end end