logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

uploads_test.exs (1587B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Mix.Tasks.Pleroma.UploadsTest do
  5. alias Pleroma.Upload
  6. use Pleroma.DataCase
  7. import Mock
  8. setup_all do
  9. Mix.shell(Mix.Shell.Process)
  10. on_exit(fn ->
  11. Mix.shell(Mix.Shell.IO)
  12. end)
  13. :ok
  14. end
  15. describe "running migrate_local" do
  16. test "uploads migrated" do
  17. with_mock Upload,
  18. store: fn %Upload{name: _file, path: _path}, _opts -> {:ok, %{}} end do
  19. Mix.Tasks.Pleroma.Uploads.run(["migrate_local", "S3"])
  20. assert_received {:mix_shell, :info, [message]}
  21. assert message =~ "Migrating files from local"
  22. assert_received {:mix_shell, :info, [message]}
  23. assert %{"total_count" => total_count} =
  24. Regex.named_captures(~r"^Found (?<total_count>\d+) uploads$", message)
  25. assert_received {:mix_shell, :info, [message]}
  26. # @logevery in Mix.Tasks.Pleroma.Uploads
  27. count =
  28. min(50, String.to_integer(total_count))
  29. |> to_string()
  30. assert %{"count" => ^count, "total_count" => ^total_count} =
  31. Regex.named_captures(
  32. ~r"^Uploaded (?<count>\d+)/(?<total_count>\d+) files$",
  33. message
  34. )
  35. end
  36. end
  37. test "nonexistent uploader" do
  38. assert_raise RuntimeError, ~r/The uploader .* is not an existing/, fn ->
  39. Mix.Tasks.Pleroma.Uploads.run(["migrate_local", "nonexistent"])
  40. end
  41. end
  42. end
  43. end