Move deadline and old_insert_date to setup

Several tests for prune_objetcs need a date older than the deadline for pruning, so I moved that to the setup
This commit is contained in:
ilja 2023-05-21 11:47:38 +02:00
parent 58f75ac062
commit c7fb78cc32

View file

@ -45,21 +45,25 @@ test "it replaces objects with references" do
end end
describe "prune_objects" do describe "prune_objects" do
test "it prunes old objects from the database" do setup do
deadline = Pleroma.Config.get([:instance, :remote_post_retention_days]) + 1 deadline = Pleroma.Config.get([:instance, :remote_post_retention_days]) + 1
date = old_insert_date =
Timex.now() Timex.now()
|> Timex.shift(days: -deadline) |> Timex.shift(days: -deadline)
|> Timex.to_naive_datetime() |> Timex.to_naive_datetime()
|> NaiveDateTime.truncate(:second) |> NaiveDateTime.truncate(:second)
%{old_insert_date: old_insert_date}
end
test "it prunes old objects from the database", %{old_insert_date: old_insert_date} do
insert(:note) insert(:note)
%{id: note_remote_public_id} = %{id: note_remote_public_id} =
:note :note
|> insert() |> insert()
|> Ecto.Changeset.change(%{updated_at: date}) |> Ecto.Changeset.change(%{updated_at: old_insert_date})
|> Repo.update!() |> Repo.update!()
note_remote_non_public = note_remote_non_public =
@ -69,7 +73,7 @@ test "it prunes old objects from the database" do
note_remote_non_public note_remote_non_public
|> Ecto.Changeset.change(%{ |> Ecto.Changeset.change(%{
updated_at: date, updated_at: old_insert_date,
data: note_remote_non_public_data |> update_in(["to"], fn _ -> [] end) data: note_remote_non_public_data |> update_in(["to"], fn _ -> [] end)
}) })
|> Repo.update!() |> Repo.update!()
@ -83,21 +87,14 @@ test "it prunes old objects from the database" do
refute Object.get_by_id(note_remote_non_public_id) refute Object.get_by_id(note_remote_non_public_id)
end end
test "with the --keep-non-public option it still keeps non-public posts even if they are not local" do test "with the --keep-non-public option it still keeps non-public posts even if they are not local",
deadline = Pleroma.Config.get([:instance, :remote_post_retention_days]) + 1 %{old_insert_date: old_insert_date} do
date =
Timex.now()
|> Timex.shift(days: -deadline)
|> Timex.to_naive_datetime()
|> NaiveDateTime.truncate(:second)
insert(:note) insert(:note)
%{id: note_remote_id} = %{id: note_remote_id} =
:note :note
|> insert() |> insert()
|> Ecto.Changeset.change(%{updated_at: date}) |> Ecto.Changeset.change(%{updated_at: old_insert_date})
|> Repo.update!() |> Repo.update!()
note_remote_non_public = note_remote_non_public =
@ -107,7 +104,7 @@ test "with the --keep-non-public option it still keeps non-public posts even if
note_remote_non_public note_remote_non_public
|> Ecto.Changeset.change(%{ |> Ecto.Changeset.change(%{
updated_at: date, updated_at: old_insert_date,
data: note_remote_non_public_data |> update_in(["to"], fn _ -> [] end) data: note_remote_non_public_data |> update_in(["to"], fn _ -> [] end)
}) })
|> Repo.update!() |> Repo.update!()
@ -120,16 +117,10 @@ test "with the --keep-non-public option it still keeps non-public posts even if
refute Object.get_by_id(note_remote_id) refute Object.get_by_id(note_remote_id)
end end
test "with the --keep-threads and --keep-non-public option it keeps old threads with non-public replies even if the interaction is not local" do test "with the --keep-threads and --keep-non-public option it keeps old threads with non-public replies even if the interaction is not local",
%{old_insert_date: old_insert_date} do
# For non-public we only check Create Activities because only these are relevant for threads # For non-public we only check Create Activities because only these are relevant for threads
# Flags are always non-public, Announces from relays can be non-public... # Flags are always non-public, Announces from relays can be non-public...
deadline = Pleroma.Config.get([:instance, :remote_post_retention_days]) + 1
old_insert_date =
Timex.now()
|> Timex.shift(days: -deadline)
|> Timex.to_naive_datetime()
|> NaiveDateTime.truncate(:second)
remote_user1 = insert(:user, local: false) remote_user1 = insert(:user, local: false)
remote_user2 = insert(:user, local: false) remote_user2 = insert(:user, local: false)
@ -212,15 +203,9 @@ test "with the --keep-threads option it still keeps non-old threads even with no
assert length(Repo.all(Object)) == 2 assert length(Repo.all(Object)) == 2
end end
test "with the --keep-threads option it deletes old threads with no local interaction" do test "with the --keep-threads option it deletes old threads with no local interaction", %{
deadline = Pleroma.Config.get([:instance, :remote_post_retention_days]) + 1 old_insert_date: old_insert_date
} do
old_insert_date =
Timex.now()
|> Timex.shift(days: -deadline)
|> Timex.to_naive_datetime()
|> NaiveDateTime.truncate(:second)
remote_user = insert(:user, local: false) remote_user = insert(:user, local: false)
remote_user2 = insert(:user, local: false) remote_user2 = insert(:user, local: false)
@ -261,15 +246,9 @@ test "with the --keep-threads option it deletes old threads with no local intera
assert length(Repo.all(Object)) == 0 assert length(Repo.all(Object)) == 0
end end
test "with the --keep-threads option it keeps old threads with local interaction" do test "with the --keep-threads option it keeps old threads with local interaction", %{
deadline = Pleroma.Config.get([:instance, :remote_post_retention_days]) + 1 old_insert_date: old_insert_date
} do
old_insert_date =
Timex.now()
|> Timex.shift(days: -deadline)
|> Timex.to_naive_datetime()
|> NaiveDateTime.truncate(:second)
remote_user = insert(:user, local: false) remote_user = insert(:user, local: false)
local_user = insert(:user, local: true) local_user = insert(:user, local: true)
@ -326,15 +305,9 @@ test "with the --keep-threads option it keeps old threads with local interaction
assert length(Repo.all(Object)) == 4 assert length(Repo.all(Object)) == 4
end end
test "with the --keep-threads option it keeps old threads with bookmarked posts" do test "with the --keep-threads option it keeps old threads with bookmarked posts", %{
deadline = Pleroma.Config.get([:instance, :remote_post_retention_days]) + 1 old_insert_date: old_insert_date
} do
old_insert_date =
Timex.now()
|> Timex.shift(days: -deadline)
|> Timex.to_naive_datetime()
|> NaiveDateTime.truncate(:second)
remote_user = insert(:user, local: false) remote_user = insert(:user, local: false)
local_user = insert(:user, local: true) local_user = insert(:user, local: true)