logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: b4b68b71fc88de7ee3387aab1071f2cea257e54d
parent c1129ff6746b20b164b7bc6dadf851f396ef29ad
Author: lain <lain@soykaf.club>
Date:   Fri, 18 Dec 2020 13:18:17 +0100

Tests: Remove unneeded explicit cachex use.

Only use cachex when we're actually testing it.

Diffstat:

Mtest/mix/tasks/pleroma/relay_test.exs4++--
Mtest/pleroma/captcha_test.exs1-
Mtest/pleroma/user/query_test.exs2+-
Mtest/pleroma/web/activity_pub/relay_test.exs2+-
Mtest/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs1+
Mtest/pleroma/web/activity_pub/visibility_test.exs2+-
Mtest/pleroma/web/admin_api/controllers/media_proxy_cache_controller_test.exs4----
Mtest/pleroma/web/mastodon_api/controllers/account_controller_test.exs2--
Mtest/pleroma/web/mastodon_api/controllers/status_controller_test.exs4----
Mtest/pleroma/web/mastodon_api/views/status_view_test.exs4++--
Mtest/pleroma/web/media_proxy/invalidation/http_test.exs4----
Mtest/pleroma/web/media_proxy/invalidation/script_test.exs4----
Mtest/pleroma/web/media_proxy/invalidation_test.exs4----
Mtest/pleroma/web/media_proxy/media_proxy_controller_test.exs4----
Mtest/pleroma/web/plugs/cache_test.exs7+------
Mtest/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs2+-
Mtest/pleroma/web/twitter_api/twitter_api_test.exs6------
17 files changed, 10 insertions(+), 47 deletions(-)

diff --git a/test/mix/tasks/pleroma/relay_test.exs b/test/mix/tasks/pleroma/relay_test.exs @@ -100,7 +100,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do end) Pleroma.Repo.delete(user) - Cachex.clear(:user_cache) + User.invalidate_cache(user) Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance]) @@ -137,7 +137,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do end) Pleroma.Repo.delete(user) - Cachex.clear(:user_cache) + User.invalidate_cache(user) Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance, "--force"]) diff --git a/test/pleroma/captcha_test.exs b/test/pleroma/captcha_test.exs @@ -80,7 +80,6 @@ defmodule Pleroma.CaptchaTest do assert is_binary(answer) assert :ok = Captcha.validate(token, "63615261b77f5354fb8c4e4986477555", answer) - Cachex.del(:used_captcha_cache, token) end test "doesn't validate invalid answer" do diff --git a/test/pleroma/user/query_test.exs b/test/pleroma/user/query_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.User.QueryTest do - use Pleroma.DataCase, async: true + use Pleroma.DataCase alias Pleroma.Repo alias Pleroma.User diff --git a/test/pleroma/web/activity_pub/relay_test.exs b/test/pleroma/web/activity_pub/relay_test.exs @@ -84,7 +84,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do ) Pleroma.Repo.delete(user) - Cachex.clear(:user_cache) + User.invalidate_cache(user) assert {:ok, %Activity{} = activity} = Relay.unfollow(user_ap_id, %{force: true}) diff --git a/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs @@ -51,6 +51,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do Object.normalize(activity.data["object"]) |> Repo.delete() + # TODO: mock cachex Cachex.del(:object_cache, "object:#{object.data["id"]}") deleting_user = insert(:user) diff --git a/test/pleroma/web/activity_pub/visibility_test.exs b/test/pleroma/web/activity_pub/visibility_test.exs @@ -159,7 +159,7 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do user: user } do Repo.delete(user) - Cachex.clear(:user_cache) + Pleroma.User.invalidate_cache(user) refute Visibility.is_private?(direct) end diff --git a/test/pleroma/web/admin_api/controllers/media_proxy_cache_controller_test.exs b/test/pleroma/web/admin_api/controllers/media_proxy_cache_controller_test.exs @@ -13,10 +13,6 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do setup do: clear_config([:media_proxy]) setup do - on_exit(fn -> Cachex.clear(:banned_urls_cache) end) - end - - setup do admin = insert(:user, is_admin: true) token = insert(:oauth_admin_token, user: admin) diff --git a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs @@ -1411,8 +1411,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do |> json_response_and_validate_schema(:ok) assert Token |> Repo.get_by(token: access_token) |> Repo.preload(:user) |> Map.get(:user) - - Cachex.del(:used_captcha_cache, token) end test "returns 400 if any captcha field is not provided", %{conn: conn} do diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs @@ -67,10 +67,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do "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} = json_response_and_validate_schema(conn_one, 200) diff --git a/test/pleroma/web/mastodon_api/views/status_view_test.exs b/test/pleroma/web/mastodon_api/views/status_view_test.exs @@ -160,7 +160,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do {:ok, activity} = CommonAPI.post(user, %{status: "Hey @shp!", visibility: "direct"}) Repo.delete(user) - Cachex.clear(:user_cache) + User.invalidate_cache(user) finger_url = "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}"}) |> Repo.update() - Cachex.clear(:user_cache) + User.invalidate_cache(user) result = StatusView.render("show.json", activity: activity) diff --git a/test/pleroma/web/media_proxy/invalidation/http_test.exs b/test/pleroma/web/media_proxy/invalidation/http_test.exs @@ -9,10 +9,6 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.HttpTest do import ExUnit.CaptureLog 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 mock(fn %{method: :purge, url: "http://example.com/media/example.jpg"} -> diff --git a/test/pleroma/web/media_proxy/invalidation/script_test.exs b/test/pleroma/web/media_proxy/invalidation/script_test.exs @@ -8,10 +8,6 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.ScriptTest do import ExUnit.CaptureLog - setup do - on_exit(fn -> Cachex.clear(:banned_urls_cache) end) - end - test "it logger error when script not found" do assert capture_log(fn -> assert Invalidation.Script.purge( diff --git a/test/pleroma/web/media_proxy/invalidation_test.exs b/test/pleroma/web/media_proxy/invalidation_test.exs @@ -15,10 +15,6 @@ defmodule Pleroma.Web.MediaProxy.InvalidationTest do setup do: clear_config([:media_proxy]) - setup do - on_exit(fn -> Cachex.clear(:banned_urls_cache) end) - end - describe "Invalidation.Http" do test "perform request to clear cache" do Config.put([:media_proxy, :enabled], false) diff --git a/test/pleroma/web/media_proxy/media_proxy_controller_test.exs b/test/pleroma/web/media_proxy/media_proxy_controller_test.exs @@ -10,10 +10,6 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do alias Pleroma.Web.MediaProxy alias Plug.Conn - setup do - on_exit(fn -> Cachex.clear(:banned_urls_cache) end) - end - describe "Media Proxy" do setup do clear_config([:media_proxy, :enabled], true) diff --git a/test/pleroma/web/plugs/cache_test.exs b/test/pleroma/web/plugs/cache_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Plugs.CacheTest do - use ExUnit.Case, async: true + use Pleroma.DataCase use Plug.Test alias Pleroma.Web.Plugs.Cache @@ -24,11 +24,6 @@ defmodule Pleroma.Web.Plugs.CacheTest do @ttl 5 - setup do - Cachex.clear(:web_resp_cache) - :ok - end - test "caches a response" do assert @miss_resp == conn(:get, "/") diff --git a/test/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs b/test/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only 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 url = "https://pleroma.social/amz" diff --git a/test/pleroma/web/twitter_api/twitter_api_test.exs b/test/pleroma/web/twitter_api/twitter_api_test.exs @@ -423,10 +423,4 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do assert is_binary(error) refute User.get_cached_by_nickname("lain") end - - setup do - Supervisor.terminate_child(Pleroma.Supervisor, Cachex) - Supervisor.restart_child(Pleroma.Supervisor, Cachex) - :ok - end end