test/api_test.rb in ardtweeno-0.3.1 vs test/api_test.rb in ardtweeno-0.4.0

- old
+ new

@@ -11,13 +11,11 @@ class APITest < Test::Unit::TestCase include Rack::Test::Methods - attr_accessor :dispatch, :nodelist, :params, :date, :hour, :minute, :confdata - # Test suite fixtures def setup begin @@ -49,11 +47,11 @@ @dispatch = Ardtweeno::Dispatcher.instance # Create a DateTime instance today = DateTime.now - theDate = today.year.to_s() + "-" + "%02d" % today.month.to_s() + "-" + "%02d" % today.day.to_s() + theDate = today.year.to_s() + "-" + "%02d" % today.month.to_s() + "-" + "%02d" % today.day.to_s() # Default values @date = theDate @hour = ("%02d" % today.hour).to_s @minute = ("%02d" % today.min).to_s @@ -83,11 +81,10 @@ :withhour=> {:hour=>@hour}, :withdatewrong=> {:date=>"11-111-1111"}, :withhourwrong=> {:hour=>"022"}, :withminute=> {:minute=>@minute}, :withminutewrong=> {:minute=>"022"}, - :withseqno=> {:seqno=>35}, :withseqnowrong=> {:seqno=>50000}, :withversion=> {:version=> "0.5.0"}, :withversionwrong=> {:version=> "0.0.0"}, :withname=> {:name=>"node0"}, :withnamewrong=> {:name=>"node28"}, @@ -99,10 +96,49 @@ 5.times do |i| @dispatch.store('{"data":[23.5,997.5,65],"key":"abcdef1"}') end + @punchData = Array.new + + 144.times do + @punchData << 0 + end + + (1..today.hour).each do + @punchData << 0 + end + + @punchData << 5 + + ((today.hour + 1)..23).each do + @punchData << 0 + end + + @punchDays = Array.new + + theStart = today - 6 + + (theStart..today).each do |i| + @punchDays << i.strftime('%a') + end + + @punchDays.reverse! + + theStartDay = "%02d" % theStart.day + theStartMonth = "%02d" % theStart.month + theStartYear = theStart.year.to_s + + theEndDay = "%02d" % today.day + theEndMonth = "%02d" % today.month + theEndYear = today.year.to_s + + startRange = theStartYear + "-" + theStartMonth + "-" + theStartDay + endRange = theEndYear + "-" + theEndMonth + "-" + theEndDay + + @punchRange = "#{startRange} to #{endRange}" + rescue Exception => e puts e.message puts e.backtrace exit end @@ -127,12 +163,11 @@ results = Ardtweeno::API.retrievezones(@confdata, @params[:empty]) assert_equal(2, results[:zones].size) end - - + # Test the retrievenodes method def test_retrievenodes results = @dispatch.retrieve_nodes(@params[:empty]) assert_equal(5, results[:nodes].size) end @@ -182,17 +217,23 @@ end # Test the handleSeqNo method def test_handleSeqNo - results = @dispatch.retrieve_packets(@params[:withseqno]) + initial = @dispatch.retrieve_packets(@params[:empty]) + value = initial[:packets].first + + sequenceNo = {:seqno=>value.seqNo} + + results = @dispatch.retrieve_packets(sequenceNo) assert_equal(1, results[:packets].size) results = @dispatch.retrieve_packets(@params[:withseqnowrong]) assert_equal(0, results[:packets].size) end + # Test the handleMinute method def test_handleMinute results = @dispatch.retrieve_packets(@params[:withminute]) assert_equal(5, results[:packets].size) @@ -271,7 +312,19 @@ if val2 < val1 then return true; else return false; end end end + + + # Test the buildPunchcard method + def test_buildPunchcard + data, days, range = Ardtweeno::API.buildPunchcard(@nodeList, {:node=>"node1"}) + + assert_equal(data, @punchData) + assert_equal(days, @punchDays) + assert_equal(range, @punchRange) + end + + end \ No newline at end of file