diff options
| author | Mark Felder <feld@FreeBSD.org> | 2020-09-23 11:56:22 -0500 | 
|---|---|---|
| committer | Mark Felder <feld@FreeBSD.org> | 2020-09-23 11:56:22 -0500 | 
| commit | f3a1f9c3bbb7321876a09b3846b5e10ecf4af94f (patch) | |
| tree | bcfd29188a841470cdeca478b1c5a3bbd4cc930a /test/support | |
| parent | 34d7e864db8f9cc7fb73ce2fef8466ce8e09ed85 (diff) | |
| parent | e02101e15c425416975f756aca7f3b058006668d (diff) | |
| download | pleroma-f3a1f9c3bbb7321876a09b3846b5e10ecf4af94f.tar.gz pleroma-f3a1f9c3bbb7321876a09b3846b5e10ecf4af94f.zip | |
Merge branch 'develop' into feature/bulk-confirmation
Diffstat (limited to 'test/support')
| -rw-r--r-- | test/support/data_case.ex | 15 | ||||
| -rw-r--r-- | test/support/factory.ex | 20 | ||||
| -rw-r--r-- | test/support/http_request_mock.ex | 191 | 
3 files changed, 33 insertions, 193 deletions
| diff --git a/test/support/data_case.ex b/test/support/data_case.ex index ba8848952..d5456521c 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -27,6 +27,21 @@ defmodule Pleroma.DataCase do        import Ecto.Query        import Pleroma.DataCase        use Pleroma.Tests.Helpers + +      # Sets up OAuth access with specified scopes +      defp oauth_access(scopes, opts \\ []) do +        user = +          Keyword.get_lazy(opts, :user, fn -> +            Pleroma.Factory.insert(:user) +          end) + +        token = +          Keyword.get_lazy(opts, :oauth_token, fn -> +            Pleroma.Factory.insert(:oauth_token, user: user, scopes: scopes) +          end) + +        %{user: user, token: token} +      end      end    end diff --git a/test/support/factory.ex b/test/support/factory.ex index 486eda8da..fb82be0c4 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -31,6 +31,7 @@ defmodule Pleroma.Factory do        nickname: sequence(:nickname, &"nick#{&1}"),        password_hash: Pbkdf2.hash_pwd_salt("test"),        bio: sequence(:bio, &"Tester Number #{&1}"), +      discoverable: true,        last_digest_emailed_at: NaiveDateTime.utc_now(),        last_refreshed_at: NaiveDateTime.utc_now(),        notification_settings: %Pleroma.User.NotificationSetting{}, @@ -200,25 +201,6 @@ defmodule Pleroma.Factory do      |> Map.merge(attrs)    end -  defp expiration_offset_by_minutes(attrs, minutes) do -    scheduled_at = -      NaiveDateTime.utc_now() -      |> NaiveDateTime.add(:timer.minutes(minutes), :millisecond) -      |> NaiveDateTime.truncate(:second) - -    %Pleroma.ActivityExpiration{} -    |> Map.merge(attrs) -    |> Map.put(:scheduled_at, scheduled_at) -  end - -  def expiration_in_the_past_factory(attrs \\ %{}) do -    expiration_offset_by_minutes(attrs, -60) -  end - -  def expiration_in_the_future_factory(attrs \\ %{}) do -    expiration_offset_by_minutes(attrs, 61) -  end -    def article_activity_factory do      article = insert(:article) diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex index a0ebf65d9..cb022333f 100644 --- a/test/support/http_request_mock.ex +++ b/test/support/http_request_mock.ex @@ -103,14 +103,6 @@ defmodule HttpRequestMock do       }}    end -  def get("https://mastodon.social/users/emelie.atom", _, _, _) do -    {:ok, -     %Tesla.Env{ -       status: 200, -       body: File.read!("test/fixtures/tesla_mock/emelie.atom") -     }} -  end -    def get(          "https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com",          _, @@ -137,14 +129,6 @@ defmodule HttpRequestMock do       }}    end -  def get("https://pawoo.net/users/pekorino.atom", _, _, _) do -    {:ok, -     %Tesla.Env{ -       status: 200, -       body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.atom") -     }} -  end -    def get(          "https://pawoo.net/.well-known/webfinger?resource=acct:https://pawoo.net/users/pekorino",          _, @@ -159,19 +143,6 @@ defmodule HttpRequestMock do    end    def get( -        "https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/18330.atom", -        _, -        _, -        _ -      ) do -    {:ok, -     %Tesla.Env{ -       status: 200, -       body: File.read!("test/fixtures/tesla_mock/atarifrosch_feed.xml") -     }} -  end - -  def get(          "https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=acct:https://social.stopwatchingus-heidelberg.de/user/18330",          _,          _, @@ -184,27 +155,6 @@ defmodule HttpRequestMock do       }}    end -  def get("https://mamot.fr/users/Skruyb.atom", _, _, _) do -    {:ok, -     %Tesla.Env{ -       status: 200, -       body: File.read!("test/fixtures/tesla_mock/https___mamot.fr_users_Skruyb.atom") -     }} -  end - -  def get( -        "https://mamot.fr/.well-known/webfinger?resource=acct:https://mamot.fr/users/Skruyb", -        _, -        _, -        [{"accept", "application/xrd+xml,application/jrd+json"}] -      ) do -    {:ok, -     %Tesla.Env{ -       status: 200, -       body: File.read!("test/fixtures/tesla_mock/skruyb@mamot.fr.atom") -     }} -  end -    def get(          "https://social.heldscal.la/.well-known/webfinger?resource=nonexistant@social.heldscal.la",          _, @@ -507,19 +457,6 @@ defmodule HttpRequestMock do       }}    end -  def get( -        "https://mamot.fr/.well-known/webfinger?resource=https://mamot.fr/users/Skruyb", -        _, -        _, -        _ -      ) do -    {:ok, -     %Tesla.Env{ -       status: 200, -       body: File.read!("test/fixtures/tesla_mock/skruyb@mamot.fr.atom") -     }} -  end -    def get("http://pawoo.net/.well-known/host-meta", _, _, _) do      {:ok,       %Tesla.Env{ @@ -647,17 +584,6 @@ defmodule HttpRequestMock do       }}    end -  def get("https://pleroma.soykaf.com/users/lain/feed.atom", _, _, _) do -    {:ok, -     %Tesla.Env{ -       status: 200, -       body: -         File.read!( -           "test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml" -         ) -     }} -  end -    def get(url, _, _, [{"accept", "application/xrd+xml,application/jrd+json"}])        when url in [               "https://pleroma.soykaf.com/.well-known/webfinger?resource=acct:https://pleroma.soykaf.com/users/lain", @@ -670,17 +596,6 @@ defmodule HttpRequestMock do       }}    end -  def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _, _, _) do -    {:ok, -     %Tesla.Env{ -       status: 200, -       body: -         File.read!( -           "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml" -         ) -     }} -  end -    def get(          "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",          _, @@ -694,37 +609,10 @@ defmodule HttpRequestMock do       }}    end -  def get("https://shitposter.club/notice/2827873", _, _, _) do -    {:ok, -     %Tesla.Env{ -       status: 200, -       body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_notice_2827873.json") -     }} -  end - -  def get("https://shitposter.club/api/statuses/show/2827873.atom", _, _, _) do -    {:ok, -     %Tesla.Env{ -       status: 200, -       body: -         File.read!( -           "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml" -         ) -     }} -  end -    def get("https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b", _, _, _) do      {:ok, %Tesla.Env{status: 200}}    end -  def get("https://shitposter.club/api/statuses/user_timeline/5381.atom", _, _, _) do -    {:ok, -     %Tesla.Env{ -       status: 200, -       body: File.read!("test/fixtures/tesla_mock/spc_5381.atom") -     }} -  end -    def get(          "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",          _, @@ -746,14 +634,6 @@ defmodule HttpRequestMock do       }}    end -  def get("https://shitposter.club/api/statuses/show/7369654.atom", _, _, _) do -    {:ok, -     %Tesla.Env{ -       status: 200, -       body: File.read!("test/fixtures/tesla_mock/7369654.atom") -     }} -  end -    def get("https://shitposter.club/notice/4027863", _, _, _) do      {:ok,       %Tesla.Env{ @@ -762,14 +642,6 @@ defmodule HttpRequestMock do       }}    end -  def get("https://social.sakamoto.gq/users/eal/feed.atom", _, _, _) do -    {:ok, -     %Tesla.Env{ -       status: 200, -       body: File.read!("test/fixtures/tesla_mock/sakamoto_eal_feed.atom") -     }} -  end -    def get("http://social.sakamoto.gq/.well-known/host-meta", _, _, _) do      {:ok,       %Tesla.Env{ @@ -791,15 +663,6 @@ defmodule HttpRequestMock do       }}    end -  def get( -        "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056", -        _, -        _, -        [{"accept", "application/atom+xml"}] -      ) do -    {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sakamoto.atom")}} -  end -    def get("http://mastodon.social/.well-known/host-meta", _, _, _) do      {:ok,       %Tesla.Env{ @@ -853,28 +716,6 @@ defmodule HttpRequestMock do      {:ok, %Tesla.Env{status: 406, body: ""}}    end -  def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _, _, _) do -    {:ok, -     %Tesla.Env{ -       status: 200, -       body: -         File.read!( -           "test/fixtures/tesla_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml" -         ) -     }} -  end - -  def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _, _, _) do -    {:ok, -     %Tesla.Env{ -       status: 200, -       body: -         File.read!( -           "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml" -         ) -     }} -  end -    def get("http://squeet.me/.well-known/host-meta", _, _, _) do      {:ok,       %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}} @@ -996,17 +837,6 @@ defmodule HttpRequestMock do       }}    end -  def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _, _, _) do -    {:ok, -     %Tesla.Env{ -       status: 200, -       body: -         File.read!( -           "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml" -         ) -     }} -  end -    def get(          "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",          _, @@ -1036,10 +866,6 @@ defmodule HttpRequestMock do       }}    end -  def get("https://mastodon.social/users/lambadalambda.atom", _, _, _) do -    {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}} -  end -    def get("https://mastodon.social/users/lambadalambda", _, _, _) do      {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.json")}}    end @@ -1436,4 +1262,21 @@ defmodule HttpRequestMock do         inspect(headers)       }"}    end + +  # Most of the rich media mocks are missing HEAD requests, so we just return 404. +  @rich_media_mocks [ +    "https://example.com/ogp", +    "https://example.com/ogp-missing-data", +    "https://example.com/twitter-card" +  ] +  def head(url, _query, _body, _headers) when url in @rich_media_mocks do +    {:ok, %Tesla.Env{status: 404, body: ""}} +  end + +  def head(url, query, body, headers) do +    {:error, +     "Mock response not implemented for HEAD #{inspect(url)}, #{query}, #{inspect(body)}, #{ +       inspect(headers) +     }"} +  end  end | 
