require File.dirname(__FILE__) + "/test_helper.rb" class DreamyPrivateServerTest < Test::Unit::TestCase context "Creation" do setup do @xml = < 8675309 ps10034 web 200 2008-07-23 EOF end should "create a new PS from xml" do ps = Dreamy::PrivateServer.new_from_xml(Hpricot.XML(@xml)) assert_equal 8675309, ps.account_id assert_equal "ps10034", ps.name assert_equal "web", ps.type assert_equal 200, ps.memory assert_equal "2008-07-23", ps.start_date end end context "Settings" do setup do @xml = < apache2_enabled 1 comment courier_enabled 0 jabber_transports_enabled 1 lighttpd_enabled 0 machine ps12345 modphp_4_selected 1 php_cache_xcache 0 proftpd_enabled 1 success EOF end should "create settings hash from xml" do settings = Dreamy::PrivateServer.settings_from_xml(Hpricot.XML(@xml)) assert_equal "1", settings["apache2_enabled"] assert_equal "", settings["comment"] assert_equal "0", settings["courier_enabled"] assert_equal "1", settings["jabber_transports_enabled"] assert_equal "0", settings["lighttpd_enabled"] assert_equal "ps12345", settings["machine"] assert_equal "1", settings["modphp_4_selected"] assert_equal "0", settings["php_cache_xcache"] assert_equal "1", settings["proftpd_enabled"] end end context "Sizes" do setup do @xml = < 2300 0.00 0.0000 715 2009-04-29 16:28:28 EOF end should "create size hash from xml" do size = Dreamy::PrivateServer.size_from_xml(Hpricot.XML(@xml)) assert_equal 2300, size["memory_mb"] assert_equal 0.00, size["monthly_cost"] assert_equal 0.0000, size["period_cost"] assert_equal 715, size["period_seconds"] assert_equal "2009-04-29 16:28:28", size["stamp"] end end context "Usage" do setup do @xml = < 0.02 146 2009-05-02 17:26:44 EOF end should "create usage hash from xml" do usage = Dreamy::PrivateServer.usage_from_xml(Hpricot.XML(@xml)) assert_equal 0.02, usage["load"] assert_equal 146, usage["memory_mb"] assert_equal "2009-05-02 17:26:44", usage["stamp"] end end context "Pending servers" do setup do @xml = < 8675309 10.5.3.2 web 2009-03-12 06:43:48 EOF end should "create pending server hash from xml" do pending = Dreamy::PrivateServer.pending_from_xml(Hpricot.XML(@xml)) assert_equal "8675309", pending["account_id"] assert_equal "10.5.3.2", pending["ip"] assert_equal "2009-03-12 06:43:48", pending["stamp"] end end end