logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

request_builder_test.exs (2900B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.HTTP.RequestBuilderTest do
  5. use ExUnit.Case
  6. use Pleroma.Tests.Helpers
  7. alias Pleroma.HTTP.Request
  8. alias Pleroma.HTTP.RequestBuilder
  9. describe "headers/2" do
  10. test "don't send pleroma user agent" do
  11. assert RequestBuilder.headers(%Request{}, []) == %Request{headers: []}
  12. end
  13. test "send pleroma user agent" do
  14. clear_config([:http, :send_user_agent], true)
  15. clear_config([:http, :user_agent], :default)
  16. assert RequestBuilder.headers(%Request{}, []) == %Request{
  17. headers: [{"user-agent", Pleroma.Application.user_agent()}]
  18. }
  19. end
  20. test "send custom user agent" do
  21. clear_config([:http, :send_user_agent], true)
  22. clear_config([:http, :user_agent], "totally-not-pleroma")
  23. assert RequestBuilder.headers(%Request{}, []) == %Request{
  24. headers: [{"user-agent", "totally-not-pleroma"}]
  25. }
  26. end
  27. end
  28. describe "add_param/4" do
  29. test "add file parameter" do
  30. assert match?(
  31. %Request{
  32. body: %Tesla.Multipart{
  33. boundary: _,
  34. content_type_params: [],
  35. parts: [
  36. %Tesla.Multipart.Part{
  37. body: %File.Stream{
  38. line_or_bytes: 2048,
  39. modes: [:raw, :read_ahead, :binary],
  40. path: "some-path/filename.png",
  41. raw: true
  42. },
  43. dispositions: [name: "filename.png", filename: "filename.png"],
  44. headers: []
  45. }
  46. ]
  47. }
  48. },
  49. RequestBuilder.add_param(
  50. %Request{},
  51. :file,
  52. "filename.png",
  53. "some-path/filename.png"
  54. )
  55. )
  56. end
  57. test "add key to body" do
  58. %{
  59. body: %Tesla.Multipart{
  60. boundary: _,
  61. content_type_params: [],
  62. parts: [
  63. %Tesla.Multipart.Part{
  64. body: "\"someval\"",
  65. dispositions: [name: "somekey"],
  66. headers: [{"content-type", "application/json"}]
  67. }
  68. ]
  69. }
  70. } = RequestBuilder.add_param(%{}, :body, "somekey", "someval")
  71. end
  72. test "add form parameter" do
  73. assert RequestBuilder.add_param(%{}, :form, "somename", "someval") == %{
  74. body: %{"somename" => "someval"}
  75. }
  76. end
  77. test "add for location" do
  78. assert RequestBuilder.add_param(%{}, :some_location, "somekey", "someval") == %{
  79. some_location: [{"somekey", "someval"}]
  80. }
  81. end
  82. end
  83. end