Fix tests

pull/369/head
Connor Rigby 2017-11-29 22:18:52 -08:00
parent ab317e83c0
commit cec26b5fed
8 changed files with 31 additions and 7 deletions

View File

@ -21,7 +21,8 @@ config :farmbot, :transport, []
config :farmbot, :behaviour,
authorization: Farmbot.Bootstrap.Authorization,
system_tasks: Farmbot.Test.SystemTasks
system_tasks: Farmbot.Test.SystemTasks,
update_handler: FarmbotTestSupport.TestUpdateHandler
config :farmbot, Farmbot.Repo.A,

View File

@ -9,6 +9,7 @@ defmodule Mix.Tasks.Farmbot.Firmware.Slack do
token = slack_token()
{keywords, comment, _} = opts |> OptionParser.parse(switches: [signed: :boolean, channels: :string])
signed? = Keyword.get(keywords, :signed, false)
Application.ensure_all_started(:timex)
Application.ensure_all_started(:httpoison)
fw_file_to_upload = if signed?, do: signed_fw_file(), else: fw_file()

View File

@ -98,8 +98,8 @@ defmodule Farmbot.Mixfile do
{:joken, "~> 1.1"},
{:socket, "~> 0.3"},
{:amqp, "~> 1.0.0-pre.2"},
{:nerves_ssdp_server, "~> 0.2.2", only: :dev},
{:nerves_ssdp_client, "~> 0.1.0", only: :dev},
{:nerves_ssdp_server, "~> 0.2.2", only: [:dev, :test]},
{:nerves_ssdp_client, "~> 0.1.0", only: [:dev, :test]},
{:ex_syslogger, "~> 1.4", only: :prod}
]

View File

@ -22,11 +22,13 @@ defmodule Farmbot.Bootstrap.AuthorizationTest do
end
test "Authorizes with the farmbot web api.", ctx do
Farmbot.System.ConfigStorage.update_config_value(:bool, "settings", "first_boot", true)
res = Auth.authorize(ctx.email, ctx.password, ctx.server)
assert match?({:ok, _}, res)
{:ok, bin_tkn} = res
tkn = Farmbot.Jwt.decode!(bin_tkn)
assert tkn.bot == "device_2"
Farmbot.System.ConfigStorage.update_config_value(:bool, "settings", "first_boot", false)
end
test "gives a nice error on bad credentials.", ctx do

View File

@ -67,8 +67,8 @@ defmodule Farmbot.BotStateTest do
end
test "sets user environment" do
key = "some_key"
val = "hey! this should be in the bot's state!"
key = inspect self()
:ok = BotState.set_user_env(key, val)
res = BotState.get_user_env

View File

@ -28,7 +28,6 @@ defmodule Farmbot.Repo.FarmEventTest do
import Ecto.Query
id = @farm_event_seq["id"]
[fe] = from(fe in FarmEvent, where: fe.id == ^id, select: fe) |> Repo.A.all()
assert fe.start_time.__struct__ == DateTime
assert match?([_], from(fe in FarmEvent, where: fe.id == ^id, select: fe) |> Repo.A.all())
end
end

View File

@ -40,9 +40,10 @@ defmodule FarmbotTestSupport do
email = Application.get_env(:farmbot, :authorization)[:email]
password = Application.get_env(:farmbot, :authorization)[:password]
Logger.info("Preflight check: api: #{server}")
Farmbot.System.ConfigStorage.update_config_value(:bool, "settings", "first_boot", true)
case Farmbot.Bootstrap.Authorization.authorize(email, password, server) do
{:error, _reason} ->
Farmbot.System.ConfigStorage.update_config_value(:bool, "settings", "first_boot", false)
:api
{:ok, tkn} ->

View File

@ -0,0 +1,20 @@
defmodule FarmbotTestSupport.TestUpdateHandler do
@moduledoc "Handles prep and post OTA update."
@behaviour Farmbot.System.UpdateHandler
use Farmbot.Logger
# Update Handler callbacks
def apply_firmware(_file_path) do
:ok
end
def before_update do
:ok
end
def post_update do
:ok
end
end