aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/pleroma/object_test.exs43
-rw-r--r--test/pleroma/web/activity_pub/activity_pub_test.exs38
-rw-r--r--test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs4
-rw-r--r--test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs14
-rw-r--r--test/pleroma/web/common_api_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/controllers/account_controller_test.exs4
-rw-r--r--test/pleroma/web/mastodon_api/controllers/media_controller_test.exs51
-rw-r--r--test/pleroma/web/mastodon_api/controllers/status_controller_test.exs4
-rw-r--r--test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs8
-rw-r--r--test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs2
-rw-r--r--test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs2
-rw-r--r--test/pleroma/web/push/impl_test.exs2
12 files changed, 92 insertions, 82 deletions
diff --git a/test/pleroma/object_test.exs b/test/pleroma/object_test.exs
index 4a8d80fcc..7119530d8 100644
--- a/test/pleroma/object_test.exs
+++ b/test/pleroma/object_test.exs
@@ -5,10 +5,13 @@
defmodule Pleroma.ObjectTest do
use Pleroma.DataCase
use Oban.Testing, repo: Pleroma.Repo
+
import ExUnit.CaptureLog
import Pleroma.Factory
import Tesla.Mock
+
alias Pleroma.Activity
+ alias Pleroma.Media
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.Tests.ObanHelpers
@@ -89,11 +92,11 @@ defmodule Pleroma.ObjectTest do
user = insert(:user)
- {:ok, %Object{} = attachment} =
- Pleroma.Web.ActivityPub.ActivityPub.upload(file, actor: user.ap_id)
+ {:ok, %Media{} = media} = Pleroma.Web.ActivityPub.ActivityPub.upload(file, user: user)
%{data: %{"attachment" => [%{"url" => [%{"href" => href}]}]}} =
- note = insert(:note, %{user: user, data: %{"attachment" => [attachment.data]}})
+ note =
+ insert(:note, %{user: user, data: %{"attachment" => [Media.to_object_form(media)]}})
uploads_dir = Pleroma.Config.get!([Pleroma.Uploaders.Local, :uploads])
@@ -106,7 +109,7 @@ defmodule Pleroma.ObjectTest do
ObanHelpers.perform(all_enqueued(worker: Pleroma.Workers.AttachmentsCleanupWorker))
assert Object.get_by_id(note.id).data["deleted"]
- refute Object.get_by_id(attachment.id) == nil
+ refute Media.get_by_id(media.id) == nil
assert {:ok, ["an_image.jpg"]} == File.ls("#{uploads_dir}/#{path}")
end
@@ -123,11 +126,11 @@ defmodule Pleroma.ObjectTest do
user = insert(:user)
- {:ok, %Object{} = attachment} =
- Pleroma.Web.ActivityPub.ActivityPub.upload(file, actor: user.ap_id)
+ {:ok, %Media{} = media} = Pleroma.Web.ActivityPub.ActivityPub.upload(file, user: user)
%{data: %{"attachment" => [%{"url" => [%{"href" => href}]}]}} =
- note = insert(:note, %{user: user, data: %{"attachment" => [attachment.data]}})
+ note =
+ insert(:note, %{user: user, data: %{"attachment" => [Media.to_object_form(media)]}})
uploads_dir = Pleroma.Config.get!([Pleroma.Uploaders.Local, :uploads])
@@ -140,7 +143,7 @@ defmodule Pleroma.ObjectTest do
ObanHelpers.perform(all_enqueued(worker: Pleroma.Workers.AttachmentsCleanupWorker))
assert Object.get_by_id(note.id).data["deleted"]
- assert Object.get_by_id(attachment.id) == nil
+ assert Media.get_by_id(media.id) == nil
assert {:ok, []} == File.ls("#{uploads_dir}/#{path}")
end
@@ -162,11 +165,11 @@ defmodule Pleroma.ObjectTest do
user = insert(:user)
- {:ok, %Object{} = attachment} =
- Pleroma.Web.ActivityPub.ActivityPub.upload(file, actor: user.ap_id)
+ {:ok, %Media{} = media} = Pleroma.Web.ActivityPub.ActivityPub.upload(file, user: user)
%{data: %{"attachment" => [%{"url" => [%{"href" => href}]}]}} =
- note = insert(:note, %{user: user, data: %{"attachment" => [attachment.data]}})
+ note =
+ insert(:note, %{user: user, data: %{"attachment" => [Media.to_object_form(media)]}})
filename = Path.basename(href)
@@ -178,7 +181,7 @@ defmodule Pleroma.ObjectTest do
ObanHelpers.perform(all_enqueued(worker: Pleroma.Workers.AttachmentsCleanupWorker))
assert Object.get_by_id(note.id).data["deleted"]
- assert Object.get_by_id(attachment.id) == nil
+ assert Media.get_by_id(media.id) == nil
assert {:ok, files} = File.ls(uploads_dir)
refute filename in files
end
@@ -195,13 +198,13 @@ defmodule Pleroma.ObjectTest do
user = insert(:user)
- {:ok, %Object{} = attachment} =
- Pleroma.Web.ActivityPub.ActivityPub.upload(file, actor: user.ap_id)
+ {:ok, %Media{} = media} = Pleroma.Web.ActivityPub.ActivityPub.upload(file, user: user)
{:ok, %Object{}} = Object.create(%{url: "https://google.com", actor: user.ap_id})
%{data: %{"attachment" => [%{"url" => [%{"href" => href}]}]}} =
- note = insert(:note, %{user: user, data: %{"attachment" => [attachment.data]}})
+ note =
+ insert(:note, %{user: user, data: %{"attachment" => [Media.to_object_form(media)]}})
uploads_dir = Pleroma.Config.get!([Pleroma.Uploaders.Local, :uploads])
@@ -214,7 +217,7 @@ defmodule Pleroma.ObjectTest do
ObanHelpers.perform(all_enqueued(worker: Pleroma.Workers.AttachmentsCleanupWorker))
assert Object.get_by_id(note.id).data["deleted"]
- assert Object.get_by_id(attachment.id) == nil
+ assert Media.get_by_id(media.id) == nil
assert {:ok, []} == File.ls("#{uploads_dir}/#{path}")
end
@@ -232,11 +235,11 @@ defmodule Pleroma.ObjectTest do
user = insert(:user)
- {:ok, %Object{} = attachment} =
- Pleroma.Web.ActivityPub.ActivityPub.upload(file, actor: user.ap_id)
+ {:ok, %Media{} = media} = Pleroma.Web.ActivityPub.ActivityPub.upload(file, user: user)
%{data: %{"attachment" => [%{"url" => [%{"href" => href}]}]}} =
- note = insert(:note, %{user: user, data: %{"attachment" => [attachment.data]}})
+ note =
+ insert(:note, %{user: user, data: %{"attachment" => [Media.to_object_form(media)]}})
uploads_dir = Pleroma.Config.get!([Pleroma.Uploaders.Local, :uploads])
@@ -249,7 +252,7 @@ defmodule Pleroma.ObjectTest do
ObanHelpers.perform(all_enqueued(worker: Pleroma.Workers.AttachmentsCleanupWorker))
assert Object.get_by_id(note.id).data["deleted"]
- assert Object.get_by_id(attachment.id) == nil
+ assert Media.get_by_id(media.id) == nil
assert {:ok, []} == File.ls("#{uploads_dir}/#{path}")
end
diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs
index 24576b31a..713a012b4 100644
--- a/test/pleroma/web/activity_pub/activity_pub_test.exs
+++ b/test/pleroma/web/activity_pub/activity_pub_test.exs
@@ -9,6 +9,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
alias Pleroma.Activity
alias Pleroma.Builders.ActivityBuilder
alias Pleroma.Config
+ alias Pleroma.Media
alias Pleroma.Notification
alias Pleroma.Object
alias Pleroma.User
@@ -1068,42 +1069,47 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
filename: "an_image.jpg"
}
- %{test_file: test_file}
+ user = insert(:user)
+
+ %{test_file: test_file, user: user}
end
- test "sets a description if given", %{test_file: file} do
- {:ok, %Object{} = object} = ActivityPub.upload(file, description: "a cool file")
- assert object.data["name"] == "a cool file"
+ test "sets a description if given", %{test_file: file, user: user} do
+ {:ok, %Media{} = media} = ActivityPub.upload(file, description: "a cool file", user: user)
+ assert media.name == "a cool file"
end
- test "it sets the default description depending on the configuration", %{test_file: file} do
+ test "it sets the default description depending on the configuration", %{
+ test_file: file,
+ user: user
+ } do
clear_config([Pleroma.Upload, :default_description])
Pleroma.Config.put([Pleroma.Upload, :default_description], nil)
- {:ok, %Object{} = object} = ActivityPub.upload(file)
- assert object.data["name"] == ""
+ {:ok, %Media{} = media} = ActivityPub.upload(file, user: user)
+ assert media.name == nil
Pleroma.Config.put([Pleroma.Upload, :default_description], :filename)
- {:ok, %Object{} = object} = ActivityPub.upload(file)
- assert object.data["name"] == "an_image.jpg"
+ {:ok, %Media{} = media} = ActivityPub.upload(file, user: user)
+ assert media.name == "an_image.jpg"
Pleroma.Config.put([Pleroma.Upload, :default_description], "unnamed attachment")
- {:ok, %Object{} = object} = ActivityPub.upload(file)
- assert object.data["name"] == "unnamed attachment"
+ {:ok, %Media{} = media} = ActivityPub.upload(file, user: user)
+ assert media.name == "unnamed attachment"
end
- test "copies the file to the configured folder", %{test_file: file} do
+ test "copies the file to the configured folder", %{test_file: file, user: user} do
clear_config([Pleroma.Upload, :default_description], :filename)
- {:ok, %Object{} = object} = ActivityPub.upload(file)
- assert object.data["name"] == "an_image.jpg"
+ {:ok, %Media{} = media} = ActivityPub.upload(file, user: user)
+ assert media.name == "an_image.jpg"
end
- test "works with base64 encoded images" do
+ test "works with base64 encoded images", %{user: user} do
file = %{
img: data_uri()
}
- {:ok, %Object{}} = ActivityPub.upload(file)
+ {:ok, %Media{}} = ActivityPub.upload(file, user: user)
end
end
diff --git a/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs
index b775515e0..940ab8ab3 100644
--- a/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs
@@ -63,10 +63,10 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
filename: "an_image.jpg"
}
- {:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
+ {:ok, attachment} = ActivityPub.upload(file, user: user)
{:ok, attachment} =
- attachment.data
+ attachment
|> AttachmentValidator.cast_and_validate()
|> Ecto.Changeset.apply_action(:insert)
diff --git a/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs
index 782f6c652..4b12eabc6 100644
--- a/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs
@@ -4,6 +4,8 @@
defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
use Pleroma.DataCase
+
+ alias Pleroma.Media
alias Pleroma.Object
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Builder
@@ -82,11 +84,11 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
filename: "an_image.jpg"
}
- {:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
+ {:ok, media} = ActivityPub.upload(file, user: user)
valid_chat_message =
valid_chat_message
- |> Map.put("attachment", attachment.data)
+ |> Map.put("attachment", Media.to_object_form(media))
assert {:ok, object, _meta} = ObjectValidator.validate(valid_chat_message, [])
@@ -103,11 +105,11 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
filename: "an_image.jpg"
}
- {:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
+ {:ok, media} = ActivityPub.upload(file, user: user)
valid_chat_message =
valid_chat_message
- |> Map.put("attachment", [attachment.data])
+ |> Map.put("attachment", [Media.to_object_form(media)])
assert {:ok, object, _meta} = ObjectValidator.validate(valid_chat_message, [])
@@ -124,11 +126,11 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
filename: "an_image.jpg"
}
- {:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
+ {:ok, media} = ActivityPub.upload(file, user: user)
valid_chat_message =
valid_chat_message
- |> Map.put("attachment", attachment.data)
+ |> Map.put("attachment", Media.to_object_form(media))
|> Map.delete("content")
assert {:ok, object, _meta} = ObjectValidator.validate(valid_chat_message, [])
diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs
index 2ece92806..b705dc7ad 100644
--- a/test/pleroma/web/common_api_test.exs
+++ b/test/pleroma/web/common_api_test.exs
@@ -119,7 +119,7 @@ defmodule Pleroma.Web.CommonAPITest do
filename: "an_image.jpg"
}
- {:ok, upload} = ActivityPub.upload(file, actor: author.ap_id)
+ {:ok, upload} = ActivityPub.upload(file, user: author)
with_mocks([
{
diff --git a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
index 7b3cc7344..8227146c9 100644
--- a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
@@ -385,11 +385,11 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
filename: "an_image.jpg"
}
- {:ok, %{id: media_id}} = ActivityPub.upload(file, actor: user.ap_id)
+ {:ok, %{id: media_id}} = ActivityPub.upload(file, user: user)
{:ok, %{id: image_post_id}} = CommonAPI.post(user, %{status: "cofe", media_ids: [media_id]})
- {:ok, %{id: media_id}} = ActivityPub.upload(file, actor: other_user.ap_id)
+ {:ok, %{id: media_id}} = ActivityPub.upload(file, user: other_user)
{:ok, %{id: other_image_post_id}} =
CommonAPI.post(other_user, %{status: "cofe2", media_ids: [media_id]})
diff --git a/test/pleroma/web/mastodon_api/controllers/media_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/media_controller_test.exs
index 6c8f984d5..c7470d3df 100644
--- a/test/pleroma/web/mastodon_api/controllers/media_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/media_controller_test.exs
@@ -5,8 +5,7 @@
defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
use Pleroma.Web.ConnCase
- alias Pleroma.Object
- alias Pleroma.User
+ alias Pleroma.Media
alias Pleroma.Web.ActivityPub.ActivityPub
describe "Upload media" do
@@ -38,8 +37,8 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
assert media["description"] == desc
assert media["id"]
- object = Object.get_by_id(media["id"])
- assert object.data["actor"] == User.ap_id(conn.assigns[:user])
+ media = Media.get_by_id(media["id"])
+ assert media.user_id == conn.assigns[:user].id
end
test "/api/v2/media", %{conn: conn, user: user, image: image} do
@@ -64,8 +63,8 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
assert media["description"] == desc
assert media["id"]
- object = Object.get_by_id(media["id"])
- assert object.data["actor"] == user.ap_id
+ media = Media.get_by_id(media["id"])
+ assert media.user_id == user.id
end
end
@@ -79,25 +78,25 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
filename: "an_image.jpg"
}
- {:ok, %Object{} = object} =
+ {:ok, %Media{} = media} =
ActivityPub.upload(
file,
- actor: User.ap_id(actor),
+ user: actor,
description: "test-m"
)
- [object: object]
+ [media: media]
end
- test "/api/v1/media/:id good request", %{conn: conn, object: object} do
- media =
+ test "/api/v1/media/:id good request", %{conn: conn, media: media} do
+ media2 =
conn
|> put_req_header("content-type", "multipart/form-data")
- |> put("/api/v1/media/#{object.id}", %{"description" => "test-media"})
+ |> put("/api/v1/media/#{media.id}", %{"description" => "test-media"})
|> json_response_and_validate_schema(:ok)
- assert media["description"] == "test-media"
- assert refresh_record(object).data["name"] == "test-media"
+ assert media2["description"] == "test-media"
+ assert refresh_record(media).name == "test-media"
end
end
@@ -111,35 +110,35 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
filename: "an_image.jpg"
}
- {:ok, %Object{} = object} =
+ {:ok, %Media{} = media} =
ActivityPub.upload(
file,
- actor: User.ap_id(actor),
+ user: actor,
description: "test-media"
)
- [object: object]
+ [media: media]
end
- test "it returns media object when requested by owner", %{conn: conn, object: object} do
- media =
+ test "it returns media object when requested by owner", %{conn: conn, media: media} do
+ media2 =
conn
- |> get("/api/v1/media/#{object.id}")
+ |> get("/api/v1/media/#{media.id}")
|> json_response_and_validate_schema(:ok)
- assert media["description"] == "test-media"
- assert media["type"] == "image"
- assert media["id"]
+ assert media2["description"] == "test-media"
+ assert media2["type"] == "image"
+ assert media2["id"]
end
- test "it returns 403 if media object requested by non-owner", %{object: object, user: user} do
+ test "it returns 403 if media object requested by non-owner", %{media: media, user: user} do
%{conn: conn, user: other_user} = oauth_access(["read:media"])
- assert object.data["actor"] == user.ap_id
+ assert media.user_id == user.id
refute user.id == other_user.id
conn
- |> get("/api/v1/media/#{object.id}")
+ |> get("/api/v1/media/#{media.id}")
|> json_response(403)
end
end
diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
index 8a2267099..2c018cb98 100644
--- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
@@ -168,7 +168,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
filename: "an_image.jpg"
}
- {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
+ {:ok, upload} = ActivityPub.upload(file, user: user)
conn =
conn
@@ -409,7 +409,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
filename: "an_image.jpg"
}
- {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
+ {:ok, upload} = ActivityPub.upload(file, user: user)
conn =
conn
diff --git a/test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs b/test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs
index c3b7f0f41..9794dcc3d 100644
--- a/test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs
@@ -27,11 +27,11 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do
filename: "an_image.jpg"
}
- {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
+ {:ok, media} = ActivityPub.upload(file, user: user)
attrs = %{
params: %{
- "media_ids" => [upload.id],
+ "media_ids" => [media.id],
"status" => "hi",
"sensitive" => true,
"spoiler_text" => "spoiler",
@@ -47,12 +47,12 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do
expected = %{
id: to_string(scheduled_activity.id),
media_attachments:
- %{media_ids: [upload.id]}
+ %{media_ids: [media.id]}
|> Utils.attachments_from_ids()
|> Enum.map(&StatusView.render("attachment.json", %{attachment: &1})),
params: %{
in_reply_to_id: to_string(activity.id),
- media_ids: [upload.id],
+ media_ids: [media.id],
poll: nil,
scheduled_at: nil,
sensitive: true,
diff --git a/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs
index 372613b8b..bb4b906ea 100644
--- a/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs
@@ -112,7 +112,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
filename: "an_image.jpg"
}
- {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
+ {:ok, upload} = ActivityPub.upload(file, user: user)
other_user = insert(:user)
diff --git a/test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs b/test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs
index 6deaa2102..6098d6e11 100644
--- a/test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs
+++ b/test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs
@@ -24,7 +24,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageReferenceViewTest do
filename: "an_image.jpg"
}
- {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
+ {:ok, upload} = ActivityPub.upload(file, user: user)
{:ok, activity} =
CommonAPI.post_chat_message(user, recipient, "kippis :firefox:", idempotency_key: "123")
diff --git a/test/pleroma/web/push/impl_test.exs b/test/pleroma/web/push/impl_test.exs
index b3ca1a337..ee4b38d4e 100644
--- a/test/pleroma/web/push/impl_test.exs
+++ b/test/pleroma/web/push/impl_test.exs
@@ -242,7 +242,7 @@ defmodule Pleroma.Web.Push.ImplTest do
filename: "an_image.jpg"
}
- {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
+ {:ok, upload} = ActivityPub.upload(file, user: user)
{:ok, chat} = CommonAPI.post_chat_message(user, recipient, nil, media_id: upload.id)
object = Object.normalize(chat, fetch: false)