1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-29 03:15:27 +00:00
mobilizon/test/service/export/participants/pdf_test.exs
Thomas Citharel 0c667b13ae
Export participants to different formats
* CSV
* PDF (requires Python dependency `weasyprint`)
* ODS (requires Python dependency `pyexcel_ods3`)

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2021-10-05 10:52:55 +02:00

62 lines
1.6 KiB
Elixir

defmodule Mobilizon.Service.Export.Participants.PDFTest do
use Mobilizon.DataCase
import Mobilizon.Factory
alias Mobilizon.Events.Event
alias Mobilizon.Service.Export.Participants.PDF
setup do
test_format?()
end
describe "export event participants to PDF" do
test "export basic infos" do
%Event{} = event = insert(:event)
insert(:participant, event: event, role: :creator)
insert(:participant, event: event, role: :participant)
insert(:participant, event: event, role: :not_approved)
set_exports(Mobilizon.Service.Export.Participants.CSV)
refute PDF.ready?()
end
test "enable the exporter" do
set_exports(Mobilizon.Service.Export.Participants.PDF)
%Event{} = event = insert(:event)
insert(:participant, event: event, role: :creator)
insert(:participant, event: event, role: :participant)
insert(:participant, event: event, role: :not_approved)
assert PDF.dependencies_ok?()
assert PDF.enabled?()
assert {:ok, path} = PDF.export(event)
assert File.exists?("uploads/exports/pdf/" <> path)
set_exports(Mobilizon.Service.Export.Participants.CSV)
end
end
@spec set_exports(module()) :: :ok
defp set_exports(module) do
Mobilizon.Config.put(:exports,
formats: [module]
)
end
@spec test_format? :: :ok | {:ok, skip: true}
defp test_format? do
case System.get_env("EXPORT_FORMATS") do
nil ->
{:ok, skip: true}
formats ->
if "pdf" in String.split(formats, ",") do
:ok
else
{:ok, skip: true}
end
end
end
end