Add factories for testing.
authorRoger Braun <roger@rogerbraun.net>
Thu, 13 Apr 2017 13:49:24 +0000 (15:49 +0200)
committerRoger Braun <roger@rogerbraun.net>
Thu, 13 Apr 2017 13:49:24 +0000 (15:49 +0200)
mix.exs
mix.lock
test/support/factory.ex [new file with mode: 0644]
test/test_helper.exs

diff --git a/mix.exs b/mix.exs
index 43a93cc2c586155c95cbde0ed9ea22bdf9af9a47..590ecfb092f5ef72e420d5ae78ff9149f6cb4df2 100644 (file)
--- a/mix.exs
+++ b/mix.exs
@@ -38,6 +38,7 @@ defmodule Pleroma.Mixfile do
      {:trailing_format_plug, "~> 0.0.5" },
      {:html_sanitize_ex, "~> 1.0.0"},
      {:calendar, "~> 0.16.1"},
+     {:ex_machina, "~> 2.0", only: :test},
      {:mix_test_watch, "~> 0.2", only: :dev}]
   end
 
index 780a63221f915e6848211597e93fbafacc49224b..2cf62ddca8f87a642fae9fd99b25229aebed0fdc 100644 (file)
--- a/mix.lock
+++ b/mix.lock
@@ -8,6 +8,7 @@
   "decimal": {:hex, :decimal, "1.3.1", "157b3cedb2bfcb5359372a7766dd7a41091ad34578296e951f58a946fcab49c6", [:mix], []},
   "ecto": {:hex, :ecto, "2.1.4", "d1ba932813ec0e0d9db481ef2c17777f1cefb11fc90fa7c142ff354972dfba7e", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]},
   "elixir_make": {:hex, :elixir_make, "0.4.0", "992f38fabe705bb45821a728f20914c554b276838433349d4f2341f7a687cddf", [:mix], []},
+  "ex_machina": {:hex, :ex_machina, "2.0.0", "ec284c6f57233729cea9319e083f66e613e82549f78eccdb2059aeba5d0df9f3", [:mix], [{:ecto, "~> 2.1", [hex: :ecto, optional: true]}]},
   "fs": {:hex, :fs, "2.12.0", "ad631efacc9a5683c8eaa1b274e24fa64a1b8eb30747e9595b93bec7e492e25e", [:rebar3], []},
   "gettext": {:hex, :gettext, "0.13.1", "5e0daf4e7636d771c4c71ad5f3f53ba09a9ae5c250e1ab9c42ba9edccc476263", [:mix], []},
   "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, optional: false]}, {:idna, "4.0.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]},
diff --git a/test/support/factory.ex b/test/support/factory.ex
new file mode 100644 (file)
index 0000000..fcbdfbd
--- /dev/null
@@ -0,0 +1,47 @@
+defmodule Pleroma.Factory do
+  use ExMachina.Ecto, repo: Pleroma.Repo
+
+  def user_factory do
+    user = %Pleroma.User{
+      name: sequence(:name, &"Test User #{&1}"),
+      email: sequence(:email, &"user#{&1}@example.com"),
+      nickname: sequence(:nickname, &"nick#{&1}"),
+      password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
+      bio: sequence(:bio, &"Tester Number #{&1}"),
+    }
+    %{ user | ap_id: Pleroma.User.ap_id(user) }
+  end
+
+  def note_factory do
+    text = sequence(:text, &"This is note #{&1}")
+
+    user = insert(:user)
+    data = %{
+      "type" => "Note",
+      "content" => text,
+      "id" => Pleroma.Web.ActivityPub.ActivityPub.generate_object_id,
+      "actor" => user.ap_id,
+      "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+      "published_at" => DateTime.utc_now() |> DateTime.to_iso8601
+    }
+
+    %Pleroma.Object{
+      data: data
+    }
+  end
+
+  def note_activity_factory do
+    note = insert(:note)
+    data = %{
+      "id" => Pleroma.Web.ActivityPub.ActivityPub.generate_activity_id,
+      "actor" => note.data["actor"],
+      "to" => note.data["to"],
+      "object" => note.data,
+      "published_at" => DateTime.utc_now() |> DateTime.to_iso8601
+    }
+
+    %Pleroma.Activity{
+      data: data
+    }
+  end
+end
index 602c5fca49622750ff9f2eb62e703636930689ca..a2a9c7fd92294726906ee08994b463ed7950fa94 100644 (file)
@@ -1,4 +1,5 @@
 ExUnit.start()
 
 Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, :manual)
+{:ok, _} = Application.ensure_all_started(:ex_machina)