Commit 2592b3c8 authored by kaniini's avatar kaniini
Browse files

Merge branch 'support/issue_442' into 'develop'

[#442] fix warnings

See merge request pleroma/pleroma!536
parents 2999a08e 89b3729a
defmodule Pleroma.Web.MastodonApi.MastodonSocketTest do
use Pleroma.DataCase
alias Pleroma.Web.MastodonApi.MastodonSocket
alias Pleroma.Web.{Streamer, CommonAPI}
alias Pleroma.User
import Pleroma.Factory
......
......@@ -71,7 +71,7 @@ test "delete authorizations" do
{:ok, auth} = Authorization.create_authorization(app, user)
{:ok, auth} = Authorization.use_token(auth)
{auths, _} = Authorization.delete_user_authorizations(user)
Authorization.delete_user_authorizations(user)
{_, invalid} = Authorization.use_token(auth)
......
......@@ -54,8 +54,8 @@ test "deletes all tokens of a user" do
{:ok, auth1} = Authorization.create_authorization(app1, user)
{:ok, auth2} = Authorization.create_authorization(app2, user)
{:ok, token1} = Token.exchange_token(app1, auth1)
{:ok, token2} = Token.exchange_token(app2, auth2)
{:ok, _token1} = Token.exchange_token(app1, auth1)
{:ok, _token2} = Token.exchange_token(app2, auth2)
{tokens, _} = Token.delete_user_tokens(user)
......
......@@ -42,8 +42,8 @@ test "decodes a salmon with a changed magic key", %{conn: conn} do
"RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
})
cng =
Ecto.Changeset.change(salmon_user)
salmon_user
|> Ecto.Changeset.change()
|> Ecto.Changeset.put_embed(:info, info_cng)
|> Repo.update()
......@@ -97,82 +97,58 @@ test "gets an object", %{conn: conn} do
test "404s on private objects", %{conn: conn} do
note_activity = insert(:direct_note_activity)
user = User.get_by_ap_id(note_activity.data["actor"])
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
url = "/objects/#{uuid}"
conn =
conn
|> get(url)
assert response(conn, 404)
|> get("/objects/#{uuid}")
|> response(404)
end
test "404s on nonexisting objects", %{conn: conn} do
url = "/objects/123"
conn =
conn
|> get(url)
assert response(conn, 404)
|> get("/objects/123")
|> response(404)
end
test "gets an activity", %{conn: conn} do
note_activity = insert(:note_activity)
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
url = "/activities/#{uuid}"
conn =
conn
|> get(url)
assert response(conn, 200)
|> get("/activities/#{uuid}")
|> response(200)
end
test "404s on private activities", %{conn: conn} do
note_activity = insert(:direct_note_activity)
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
url = "/activities/#{uuid}"
conn =
conn
|> get(url)
assert response(conn, 404)
|> get("/activities/#{uuid}")
|> response(404)
end
test "404s on nonexistent activities", %{conn: conn} do
url = "/activities/123"
conn =
conn
|> get(url)
assert response(conn, 404)
|> get("/activities/123")
|> response(404)
end
test "gets a notice", %{conn: conn} do
note_activity = insert(:note_activity)
url = "/notice/#{note_activity.id}"
conn =
conn
|> get(url)
assert response(conn, 200)
|> get("/notice/#{note_activity.id}")
|> response(200)
end
test "gets a notice in AS2 format", %{conn: conn} do
note_activity = insert(:note_activity)
url = "/notice/#{note_activity.id}"
conn =
conn
|> put_req_header("accept", "application/activity+json")
|> get(url)
assert json_response(conn, 200)
|> get("/notice/#{note_activity.id}")
|> json_response(200)
end
test "only gets a notice in AS2 format for Create messages", %{conn: conn} do
......
......@@ -511,7 +511,7 @@ test "Article objects are not representable" do
|> Map.put("type", "Article")
cs = Object.change(note_object, %{data: note_data})
{:ok, article_object} = Repo.update(cs)
{:ok, _article_object} = Repo.update(cs)
# the underlying object is now an Article instead of a note, so this should fail
refute OStatus.is_representable?(note_activity)
......
......@@ -4,7 +4,7 @@ def publish_one(ret) do
end
end
defmodule Pleroma.ActivityTest do
defmodule Pleroma.Web.Federator.RetryQueueTest do
use Pleroma.DataCase
alias Pleroma.Web.Federator.RetryQueue
......
......@@ -3,7 +3,6 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
alias Pleroma.Web.Salmon
alias Pleroma.{Repo, Activity, User}
import Pleroma.Factory
import Tesla.Mock
@magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
......@@ -11,8 +10,8 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
@magickey_friendica "RSA.AMwa8FUs2fWEjX0xN7yRQgegQffhBpuKNC6fa5VNSVorFjGZhRrlPMn7TQOeihlc9lBz2OsHlIedbYn2uJ7yCs0.AQAB"
setup do
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok
end
......@@ -75,7 +74,7 @@ test "it gets a magic key" do
test "it pushes an activity to remote accounts it's addressed to" do
user_data = %{
info: %{
"salmon" => "http://example.org/salmon"
salmon: "http://test-example.org/salmon"
},
local: false
}
......@@ -97,8 +96,8 @@ test "it pushes an activity to remote accounts it's addressed to" do
user = Repo.get_by(User, ap_id: activity.data["actor"])
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
poster = fn url, _data, _headers, _options ->
assert url == "http://example.org/salmon"
poster = fn url, _data, _headers ->
assert url == "http://test-example.org/salmon"
end
Salmon.publish(user, activity, poster)
......
......@@ -3,7 +3,6 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
alias Pleroma.{User, Activity, Object}
alias Pleroma.Web.TwitterAPI.Representers.{ActivityRepresenter, ObjectRepresenter}
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Builders.UserBuilder
alias Pleroma.Web.TwitterAPI.UserView
import Pleroma.Factory
......
......@@ -12,20 +12,18 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
import Pleroma.Factory
@banner "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
describe "POST /api/account/update_profile_banner" do
test "it updates the banner", %{conn: conn} do
user = insert(:user)
new_banner =
"data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
response =
conn
|> assign(:user, user)
|> post(authenticated_twitter_api__path(conn, :update_banner), %{"banner" => new_banner})
|> post(authenticated_twitter_api__path(conn, :update_banner), %{"banner" => @banner})
|> json_response(200)
user = Repo.get(User, user.id)
user = refresh_record(user)
assert user.info.banner["type"] == "Image"
end
end
......@@ -34,16 +32,12 @@ test "it updates the banner", %{conn: conn} do
test "it updates the background", %{conn: conn} do
user = insert(:user)
new_bg =
"data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
response =
conn
|> assign(:user, user)
|> post(authenticated_twitter_api__path(conn, :update_background), %{"img" => new_bg})
|> post(authenticated_twitter_api__path(conn, :update_background), %{"img" => @banner})
|> json_response(200)
user = Repo.get(User, user.id)
user = refresh_record(user)
assert user.info.background["type"] == "Image"
end
end
......@@ -57,12 +51,12 @@ test "without valid credentials", %{conn: conn} do
end
test "with credentials", %{conn: conn, user: user} do
conn =
response =
conn
|> with_credentials(user.nickname, "test")
|> post("/api/account/verify_credentials.json")
|> json_response(200)
assert response = json_response(conn, 200)
assert response == UserView.render("show.json", %{user: user, token: response["token"]})
end
end
......@@ -84,17 +78,28 @@ test "with credentials", %{conn: conn, user: user} do
"error" => "Client must provide a 'status' parameter with a value."
}
conn = conn_with_creds |> post(request_path)
conn =
conn_with_creds
|> post(request_path)
assert json_response(conn, 400) == error_response
conn = conn_with_creds |> post(request_path, %{status: ""})
conn =
conn_with_creds
|> post(request_path, %{status: ""})
assert json_response(conn, 400) == error_response
conn = conn_with_creds |> post(request_path, %{status: " "})
conn =
conn_with_creds
|> post(request_path, %{status: " "})
assert json_response(conn, 400) == error_response
# we post with visibility private in order to avoid triggering relay
conn = conn_with_creds |> post(request_path, %{status: "Nice meme.", visibility: "private"})
conn =
conn_with_creds
|> post(request_path, %{status: "Nice meme.", visibility: "private"})
assert json_response(conn, 200) ==
ActivityRepresenter.to_map(Repo.one(Activity), %{user: user})
......@@ -117,7 +122,7 @@ test "returns statuses", %{conn: conn} do
assert length(response) == 10
end
test "returns 403 to unauthenticated request when the instance is not public" do
test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
instance =
Application.get_env(:pleroma, :instance)
|> Keyword.put(:public, false)
......@@ -135,7 +140,7 @@ test "returns 403 to unauthenticated request when the instance is not public" do
Application.put_env(:pleroma, :instance, instance)
end
test "returns 200 to unauthenticated request when the instance is public" do
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
conn
|> get("/api/statuses/public_timeline.json")
|> json_response(200)
......@@ -143,7 +148,7 @@ test "returns 200 to unauthenticated request when the instance is public" do
end
describe "GET /statuses/public_and_external_timeline.json" do
test "returns 403 to unauthenticated request when the instance is not public" do
test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
instance =
Application.get_env(:pleroma, :instance)
|> Keyword.put(:public, false)
......@@ -161,7 +166,7 @@ test "returns 403 to unauthenticated request when the instance is not public" do
Application.put_env(:pleroma, :instance, instance)
end
test "returns 200 to unauthenticated request when the instance is public" do
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
conn
|> get("/api/statuses/public_and_external_timeline.json")
|> json_response(200)
......@@ -654,14 +659,13 @@ test "unimplemented mutes without valid credentials", %{conn: conn} do
end
test "unimplemented mutes with credentials", %{conn: conn, user: current_user} do
conn =
response =
conn
|> with_credentials(current_user.nickname, "test")
|> get("/api/qvitter/mutes.json")
|> json_response(200)
current_user = Repo.get(User, current_user.id)
assert [] = json_response(conn, 200)
assert [] = response
end
end
......@@ -893,15 +897,16 @@ test "it returns empty for a hidden network", %{conn: conn} do
follower_two = insert(:user)
not_follower = insert(:user)
{:ok, follower_one} = User.follow(follower_one, user)
{:ok, follower_two} = User.follow(follower_two, user)
{:ok, _follower_one} = User.follow(follower_one, user)
{:ok, _follower_two} = User.follow(follower_two, user)
conn =
response =
conn
|> assign(:user, not_follower)
|> get("/api/statuses/followers", %{"user_id" => user.id})
|> json_response(200)
assert [] == json_response(conn, 200)
assert [] == response
end
test "it returns the followers for a hidden network if requested by the user themselves", %{
......@@ -910,10 +915,10 @@ test "it returns the followers for a hidden network if requested by the user the
user = insert(:user, %{info: %{hide_network: true}})
follower_one = insert(:user)
follower_two = insert(:user)
not_follower = insert(:user)
_not_follower = insert(:user)
{:ok, follower_one} = User.follow(follower_one, user)
{:ok, follower_two} = User.follow(follower_two, user)
{:ok, _follower_one} = User.follow(follower_one, user)
{:ok, _follower_two} = User.follow(follower_two, user)
conn =
conn
......@@ -989,17 +994,18 @@ test "it returns friends for a hidden network if the user themselves request it"
user = insert(:user, %{info: %{hide_network: true}})
followed_one = insert(:user)
followed_two = insert(:user)
not_followed = insert(:user)
_not_followed = insert(:user)
{:ok, user} = User.follow(user, followed_one)
{:ok, user} = User.follow(user, followed_two)
{:ok, _user} = User.follow(user, followed_one)
{:ok, _user} = User.follow(user, followed_two)
conn =
response =
conn
|> assign(:user, user)
|> get("/api/statuses/friends", %{"user_id" => user.id})
|> json_response(200)
refute [] == json_response(conn, 200)
refute [] == response
end
test "it returns a given user's friends with screen_name", %{conn: conn} do
......
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
use Pleroma.DataCase
alias Pleroma.Builders.UserBuilder
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView}
alias Pleroma.{Activity, User, Object, Repo, UserInviteToken}
alias Pleroma.Web.ActivityPub.ActivityPub
......
......@@ -8,7 +8,6 @@ defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
alias Pleroma.Web.TwitterAPI.ActivityView
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Builders.UserBuilder
import Pleroma.Factory
......@@ -67,7 +66,7 @@ test "A retweet notification" do
user = User.get_cached_by_ap_id(note_activity.data["actor"])
repeater = insert(:user)
{:ok, activity} = TwitterAPI.repeat(repeater, note_activity.id)
{:ok, _activity} = TwitterAPI.repeat(repeater, note_activity.id)
[notification] = Notification.for_user(user)
represented = %{
......@@ -89,7 +88,7 @@ test "A like notification" do
user = User.get_cached_by_ap_id(note_activity.data["actor"])
liker = insert(:user)
{:ok, activity} = TwitterAPI.fav(liker, note_activity.id)
{:ok, _activity} = TwitterAPI.fav(liker, note_activity.id)
[notification] = Notification.for_user(user)
represented = %{
......
......@@ -4,7 +4,6 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
alias Pleroma.User
alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Builders.UserBuilder
import Pleroma.Factory
......@@ -27,7 +26,7 @@ test "A user with an avatar object", %{user: user} do
assert represented["profile_image_url"] == image
end
test "A user with emoji in username", %{user: user} do
test "A user with emoji in username" do
expected =
"<img height=\"32px\" width=\"32px\" alt=\"karjalanpiirakka\" title=\"karjalanpiirakka\" src=\"/file.png\" /> man"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment