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>
This commit is contained in:
@@ -5,7 +5,6 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
|
||||
import Mobilizon.Factory
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Follower
|
||||
alias Mobilizon.Federation.ActivityPub
|
||||
alias Mobilizon.Federation.ActivityPub.{Actions, Activity, Transmogrifier}
|
||||
|
||||
describe "handle incoming follow requests" do
|
||||
|
||||
@@ -6,7 +6,6 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.JoinTest do
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.{Event, Participant}
|
||||
alias Mobilizon.Federation.ActivityPub
|
||||
alias Mobilizon.Federation.ActivityPub.{Actions, Transmogrifier}
|
||||
|
||||
describe "handle incoming join activities" do
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
defmodule Mobilizon.Service.ICalendarTest do
|
||||
use Mobilizon.DataCase
|
||||
use Mobilizon.DataCase, async: true
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
|
||||
28
test/service/export/participants/common_test.exs
Normal file
28
test/service/export/participants/common_test.exs
Normal file
@@ -0,0 +1,28 @@
|
||||
defmodule Mobilizon.Service.Export.Participants.CommonTest do
|
||||
use Mobilizon.DataCase, async: true
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.Export.Participants.Common
|
||||
|
||||
test "convert participants to list items" do
|
||||
participant = insert(:participant)
|
||||
actor = insert(:actor)
|
||||
name = Actor.display_name_and_username(actor)
|
||||
assert [^name, _, ""] = Common.to_list({participant, actor})
|
||||
end
|
||||
|
||||
test "convert participants with metadata to list items" do
|
||||
participant = insert(:participant, metadata: %{message: "a message"})
|
||||
actor = insert(:actor)
|
||||
name = Actor.display_name_and_username(actor)
|
||||
assert [^name, _, "a message"] = Common.to_list({participant, actor})
|
||||
end
|
||||
|
||||
test "convert anonymous participants to list items" do
|
||||
participant = insert(:participant)
|
||||
actor = insert(:actor, domain: nil, preferred_username: "anonymous")
|
||||
assert ["Anonymous participant", _, ""] = Common.to_list({participant, actor})
|
||||
end
|
||||
end
|
||||
22
test/service/export/participants/csv_test.exs
Normal file
22
test/service/export/participants/csv_test.exs
Normal file
@@ -0,0 +1,22 @@
|
||||
defmodule Mobilizon.Service.Export.Participants.CSVTest do
|
||||
use Mobilizon.DataCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Service.Export.Participants.CSV
|
||||
|
||||
describe "export event participants to csv" 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)
|
||||
|
||||
assert CSV.ready?()
|
||||
assert {:ok, path} = CSV.export(event)
|
||||
assert content = File.read!("uploads/exports/csv/" <> path)
|
||||
assert content =~ "Participant name,Participant status,Participant message"
|
||||
end
|
||||
end
|
||||
end
|
||||
62
test/service/export/participants/ods_test.exs
Normal file
62
test/service/export/participants/ods_test.exs
Normal file
@@ -0,0 +1,62 @@
|
||||
defmodule Mobilizon.Service.Export.Participants.ODSTest do
|
||||
use Mobilizon.DataCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Service.Export.Participants.ODS
|
||||
|
||||
setup do
|
||||
test_format?()
|
||||
end
|
||||
|
||||
describe "export event participants to ods" 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 ODS.ready?()
|
||||
end
|
||||
|
||||
test "enable the exporter" do
|
||||
set_exports(Mobilizon.Service.Export.Participants.ODS)
|
||||
|
||||
%Event{} = event = insert(:event)
|
||||
insert(:participant, event: event, role: :creator)
|
||||
insert(:participant, event: event, role: :participant)
|
||||
insert(:participant, event: event, role: :not_approved)
|
||||
|
||||
assert ODS.dependencies_ok?()
|
||||
assert ODS.enabled?()
|
||||
assert {:ok, path} = ODS.export(event)
|
||||
assert File.exists?("uploads/exports/ods/" <> 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 "ods" in String.split(formats, ",") do
|
||||
:ok
|
||||
else
|
||||
{:ok, skip: true}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
62
test/service/export/participants/pdf_test.exs
Normal file
62
test/service/export/participants/pdf_test.exs
Normal file
@@ -0,0 +1,62 @@
|
||||
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
|
||||
14
test/service/workers/export_cleaner_worker.ex
Normal file
14
test/service/workers/export_cleaner_worker.ex
Normal file
@@ -0,0 +1,14 @@
|
||||
defmodule Mobilizon.Service.Workers.ExportCleanerWorkerTest do
|
||||
@moduledoc """
|
||||
Test the export cleaner worker
|
||||
"""
|
||||
|
||||
alias Mobilizon.Service.Workers.ExportCleanerWorker
|
||||
alias Oban.Job
|
||||
|
||||
use Mobilizon.DataCase
|
||||
|
||||
test "Run clean" do
|
||||
assert :ok == ExportCleanerWorker.perform(%Job{})
|
||||
end
|
||||
end
|
||||
@@ -7,6 +7,7 @@ defmodule Mix.Tasks.Mobilizon.UsersTest do
|
||||
|
||||
alias Mobilizon.{Actors, Config, Users}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.Auth.MobilizonAuthenticator
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
Mix.shell(Mix.Shell.Process)
|
||||
@@ -317,13 +318,11 @@ defmodule Mix.Tasks.Mobilizon.UsersTest do
|
||||
insert(:user, email: @email)
|
||||
Modify.run([@email, "--password", @modified_password])
|
||||
|
||||
assert {:ok, %User{}} =
|
||||
Mobilizon.Service.Auth.MobilizonAuthenticator.login(@email, @modified_password)
|
||||
assert {:ok, %User{}} = MobilizonAuthenticator.login(@email, @modified_password)
|
||||
|
||||
Modify.run([@email, "--password", "changed again"])
|
||||
|
||||
assert {:error, :bad_password} =
|
||||
Mobilizon.Service.Auth.MobilizonAuthenticator.login(@email, @modified_password)
|
||||
assert {:error, :bad_password} = MobilizonAuthenticator.login(@email, @modified_password)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user