add some tests

pull/263/head
connor rigby 2017-03-03 13:54:18 -08:00
parent 4148a81ce1
commit 42d65e614e
5 changed files with 99 additions and 45 deletions

View File

@ -1,7 +1,7 @@
# THIS FILE WAS GENERATED BY `build_makefile.exs`
# 19474c3
# Fri Mar 3 09:52:40 2017 -0800
# add-a-log-when-movement-is-done
# 4148a81
# Fri Mar 3 12:22:54 2017 -0800
# bump-version
default: rpi3
@ -59,7 +59,7 @@ firmware-rpi:
scripts/build_firmware.sh rpi
release-rpi: rpi
scripts/build_release_images.sh rpi 3.0.8-rc.1
scripts/build_release_images.sh rpi 3.0.8-rc.2
## end rpi portion.
## begin rpi3 portion.
@ -87,7 +87,7 @@ firmware-rpi3:
scripts/build_firmware.sh rpi3
release-rpi3: rpi3
scripts/build_release_images.sh rpi3 3.0.8-rc.1
scripts/build_release_images.sh rpi3 3.0.8-rc.2
## end rpi3 portion.
## begin rpi2 portion.
@ -115,7 +115,7 @@ firmware-rpi2:
scripts/build_firmware.sh rpi2
release-rpi2: rpi2
scripts/build_release_images.sh rpi2 3.0.8-rc.1
scripts/build_release_images.sh rpi2 3.0.8-rc.2
## end rpi2 portion.

View File

@ -587,38 +587,6 @@ defmodule Farmbot.CeleryScript.Command do
|> Farmware.Worker.add_envs
end
@doc ~s"""
Adds a point to the API
args: %{location: coordinate.t, radius: integer}
body: [pair]
"""
@spec add_point(%{location: coordinate_ast, radius: integer}, [pair])
:: no_return
def add_point(%{location: location, radius: radius}, pairs) do
# Turn the meta data into a map
meta =
pairs
|> pairs_to_tuples
|> Map.new
# validate the location
coord = ast_to_coord(location)
c_args = coord.args
json =
%{x: c_args.x, y: c_args.y, z: c_args.z, radius: radius, meta: meta}
|> Poison.encode!
Farmbot.HTTP.post("/api/points", json)
end
@doc """
Removes a point from the API
args: %{point_id: integer},
body: []
"""
@spec remove_point(%{point_id: integer}, []) :: no_return
def remove_point(%{point_id: p_id}, []),
do: Farmbot.HTTP.delete("/api/points/#{p_id}")
@doc ~s"""
Executes an ast node.
"""

View File

@ -25,25 +25,25 @@ defmodule Farmbot.Sync do
[:id, :planting_area_id, :name, :webcam_url], singular: true
syncable Peripheral, "/api/peripherals",
[:id, :device_id, :pin, :mode, :label, :created_at, :updated_at]
[:id, :pin, :mode, :label, :created_at, :updated_at]
syncable Plant, "/api/plants",
[:id, :device_id, :name, :x, :y, :radius]
[:id, :name, :x, :y, :radius]
syncable Point, "/api/points",
[:id, :radius, :x, :y, :z, :meta]
syncable Regimen, "/api/regimens",
[:id, :color, :name, :device_id, :regimen_items]
[:id, :color, :name, :regimen_items]
# syncable RegimenItem, "/api/regimen_items",
# [:id, :time_offset, :regimen_id, :sequence_id]
syncable Sequence, "/api/sequences",
[:id, :args, :body, :color, :device_id, :kind, :name]
[:id, :args, :body, :color, :kind, :name]
syncable ToolBay, "/api/tool_bays",
[:id, :device_id, :name]
[:id, :name]
syncable ToolSlot, "/api/tool_slots",
[:id, :tool_bay_id, :tool_id, :name, :x, :y, :z]
@ -52,7 +52,7 @@ defmodule Farmbot.Sync do
[:id, :name]
syncable User, "/api/users",
[:id, :device_id, :name, :email, :created_at, :updated_at]
[:id, :name, :email, :created_at, :updated_at]
syncable FarmEvent, "/api/farm_events",
[:id, :start_time, :end_time, :next_time,

View File

@ -2,6 +2,8 @@ defmodule CommandTest do
use ExUnit.Case
alias Farmbot.CeleryScript.Ast
alias Farmbot.CeleryScript.Command
use Farmbot.Sync.Database
test "doesnt freak out on no instruction" do
json = ~s"""
{
@ -13,4 +15,88 @@ defmodule CommandTest do
r = Command.do_command(cs)
assert r == :no_instruction
end
test "converts a coordinate to coordinates" do
# a coordinate is already a coordinate
ast_a = %Ast{kind: "coordinate", args: %{x: 1, y: 1, z: 1}, body: []}
coord_a = Command.ast_to_coord(ast_a)
assert ast_a.kind == coord_a.kind
end
test "converts a tool to a coodinate" do
use Amnesia
use ToolBay
use ToolSlot
use Tool
x = 1
y = 2
z = 3
{_tool_bay, tool_slot, _tool} = Amnesia.transaction do
tool_bay = %ToolBay{id: 999, name: "byron_bay"} |> ToolBay.write
tool_slot = %ToolSlot{id: 503,
tool_bay_id: 999, tool_id: 97, name: "uh", x: 1, y: 2, z: 3}
|> ToolSlot.write
tool = %Tool{id: 97, name: "lazer"} |> Tool.write
{tool_bay, tool_slot, tool}
end
ast = %Ast{kind: "tool", args: %{tool_id: 97}, body: []}
coord = Command.ast_to_coord(ast)
coord_x = coord.args.x
assert coord_x == x
assert coord_x == tool_slot.x
coord_z = coord.args.z
assert coord_z == z
assert coord_z == tool_slot.z
coord_y = coord.args.y
assert coord_y == y
assert coord_y == tool_slot.y
bad_tool = %Ast{kind: "tool", args: %{tool_id: 98}, body: []}
r = Command.ast_to_coord(bad_tool)
assert r == :error
end
test "gives the origin on nothing" do
nothing = %Ast{kind: "nothing", args: %{}, body: []}
coord = Command.ast_to_coord(nothing)
assert coord.args.x == 0
assert coord.args.y == 0
assert coord.args.z == 0
end
test "gives an error on unknown asts" do
blerp = %Ast{kind: "blerp", args: %{}, body: []}
coord = Command.ast_to_coord(blerp)
assert coord == :error
end
test "doesnt implode if a sequence relies on itself" do
use Amnesia
use Sequence
real_sequence = %Sequence{args: %{"is_outdated" => false,
"version" => 4},
body: [%{"args" => %{"_else" => %{"args" => %{}, "kind" => "nothing"},
"_then" => %{"args" => %{"sequence_id" => 40000}, "kind" => "execute"},
"lhs" => "x", "op" => "not", "rhs" => 10000}, "kind" => "_if"}],
color: "gray", id: 40000, kind: "sequence", name: "seq_a"}
Amnesia.transaction do
real_sequence |> Sequence.write
end
sequence = %Ast{kind: "execute", args: %{sequence_id: 40000}, body: []}
assert_raise(RuntimeError, "TO MUCH RECURSION", fn() ->
Command.do_command(sequence)
end)
end
end

View File

@ -14,7 +14,7 @@ defmodule SequenceRunnerTest do
%Sequence{args: %{"is_outdated" => false,
"version" => 4},
body: [%{"args" => %{"message" => "Bot is at position {{ x }}, {{ y }}, {{ z }}.",
"message_type" => "success"}, "kind" => "send_message"}], color: "blue", device_id: nil, id: 186,
"message_type" => "success"}, "kind" => "send_message"}], color: "blue", id: 186,
kind: "sequence", name: "errrrp"}
end
end