require File.dirname(__FILE__) + '/spec_helper.rb'
describe AMEE::Profile::Item do
before(:each) do
@item = AMEE::Profile::Item.new
end
it "should have common AMEE object properties" do
@item.is_a?(AMEE::Profile::Object).should be_true
end
it "should have values" do
@item.should respond_to(:values)
end
it "should initialize AMEE::Object data on creation" do
uid = 'ABCD1234'
@item = AMEE::Profile::Item.new(:uid => uid)
@item.uid.should == uid
end
it "can be created with hash of data" do
values = ["one", "two"]
@item = AMEE::Profile::Item.new(:values => values)
@item.values.should == values
end
it "should be able to create new profile items (XML)" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(1.0)
connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '/home/energy/quantity200901Quantityquantity000011-1-111000.000'))
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :kWhPerMonth => "10").and_return(flexmock(:body => '/home/energy/quantity200901Quantityquantity62BCC8C84D0CkgPerMonthkg Per Month0kgPerMonthkg Per MonthtruefalsekgDOUBLEkWhPerMonthkWh Per Month10kWhPerMonthkWh Per MonthtruefalsekWhDOUBLElitresPerMonthLitres Per Month0litresPerMonthLitres Per MonthtruefalselitreDOUBLEkWhReadingCurrentkWh reading current0kWhReadingCurrentkWh reading currenttruefalseamountDOUBLEkWhReadingLastkWh reading last0kWhReadingLastkWh reading lasttruefalseamountDOUBLEpaymentFrequencyPayment frequencypaymentFrequencyPayment frequencytruefalsetextTEXTgreenTariffGreen tariffgreenTariffGreen tarifftruefalsetextTEXTseasonSeasonseasonSeasontruefalsetextTEXTincludesHeatingIncludes HeatingfalseincludesHeatingIncludes HeatingtruefalsetextTEXTnumberOfDeliveriesNumber of deliveriesnumberOfDeliveriesNumber of deliveriestruefalseamountDOUBLE2.06020090101false', :'[]' => nil))
connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C", {}).and_return(flexmock(:body => '62BCC8C84D0CnumberOfDeliveriesNumber of deliveriesnumberOfDeliveriesNumber of deliveriestruefalseamountDOUBLEseasonSeasonseasonSeasontruefalsetextTEXTincludesHeatingIncludes HeatingfalseincludesHeatingIncludes HeatingtruefalsetextTEXTgreenTariffGreen tariffgreenTariffGreen tarifftruefalsetextTEXTpaymentFrequencyPayment frequencypaymentFrequencyPayment frequencytruefalsetextTEXTkWhReadingLastkWh reading last0kWhReadingLastkWh reading lasttruefalseamountDOUBLEkWhReadingCurrentkWh reading current0kWhReadingCurrentkWh reading currenttruefalseamountDOUBLEkgPerMonthkg Per Month0kgPerMonthkg Per MonthtruefalsekgDOUBLEkWhPerMonthkWh Per Month10kWhPerMonthkWh Per MonthtruefalsekWhDOUBLElitresPerMonthLitres Per Month0litresPerMonthLitres Per MonthtruefalselitreDOUBLEQuantityquantity2.06020090101false/home/energy/quantity/62BCC8C84D0C'))
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
item = AMEE::Profile::Item.create(category, '66056991EE23', :kWhPerMonth => "10")
item.value("kWhPerMonth").should eql "10"
item.total_amount.should be_close(2.06, 1e-9)
item.total_amount_unit.should == "kg/month"
end
it "should be able to create new profile items (JSON)" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(1.0)
connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '{"totalAmountPerMonth":0,"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"profileDate":"200901","path":"/home/energy/quantity","profile":{"uid":"E54C5525AA3E"},"children":{"pager":{"to":0,"lastPage":1,"start":0,"nextPage":-1,"items":0,"itemsPerPage":10,"from":0,"previousPage":-1,"requestedPage":1,"currentPage":1,"itemsFound":0},"dataCategories":[],"profileItems":{"rows":[],"label":"ProfileItems"}}}'))
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :kWhPerMonth => "10").and_return(flexmock(:body => '{"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"profileDate":"200901","path":"/home/energy/quantity","profile":{"uid":"E54C5525AA3E"},"profileItem":{"validFrom":"20090101","amountPerMonth":2.06,"itemValues":[{"value":"0","uid":"01591644B296","path":"kgPerMonth","name":"kg Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"36A771FC1D1A","name":"kg"},"uid":"51D072825D41","path":"kgPerMonth","name":"kg Per Month"}},{"value":"10","uid":"94B617C13137","path":"kWhPerMonth","name":"kWh Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"26A5C97D3728","name":"kWh"},"uid":"4DF458FD0E4D","path":"kWhPerMonth","name":"kWh Per Month"}},{"value":"0","uid":"1F5AF1A6BD65","path":"litresPerMonth","name":"Litres Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"06B8CFC5A521","name":"litre"},"uid":"C9B7E19269A5","path":"litresPerMonth","name":"Litres Per Month"}},{"value":"0","uid":"B2FBB1BFF60F","path":"kWhReadingCurrent","name":"kWh reading current","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"8A468E75C8E8","path":"kWhReadingCurrent","name":"kWh reading current"}},{"value":"0","uid":"A97ADD0FCB82","path":"kWhReadingLast","name":"kWh reading last","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"2328DC7F23AE","path":"kWhReadingLast","name":"kWh reading last"}},{"value":"","uid":"1D96093AD6D7","path":"paymentFrequency","name":"Payment frequency","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"E0EFED6FD7E6","path":"paymentFrequency","name":"Payment frequency"}},{"value":"","uid":"ED12DF35A1C3","path":"greenTariff","name":"Green tariff","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"63005554AE8A","path":"greenTariff","name":"Green tariff"}},{"value":"","uid":"9494FB0F7DE8","path":"season","name":"Season","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"527AADFB3B65","path":"season","name":"Season"}},{"value":"false","uid":"ECB936330FEF","path":"includesHeating","name":"Includes Heating","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"1740E500BDAB","path":"includesHeating","name":"Includes Heating"}},{"value":"","uid":"C85E51E8D26C","path":"numberOfDeliveries","name":"Number of deliveries","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"AA1D1C349119","path":"numberOfDeliveries","name":"Number of deliveries"}}],"end":"false","uid":"8C7BD1AB69D3","dataItem":{"uid":"66056991EE23"},"name":"8C7BD1AB69D3"}}', :'[]' => nil))
connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3", {}).and_return(flexmock(:body => '{"path":"/home/energy/quantity/8C7BD1AB69D3","profile":{"uid":"E54C5525AA3E"},"profileItem":{"created":"2009-01-29 00:11:33.0","itemValues":[{"value":"","uid":"9494FB0F7DE8","path":"season","name":"Season","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"527AADFB3B65","path":"season","name":"Season"}},{"value":"false","uid":"ECB936330FEF","path":"includesHeating","name":"Includes Heating","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"1740E500BDAB","path":"includesHeating","name":"Includes Heating"}},{"value":"","uid":"C85E51E8D26C","path":"numberOfDeliveries","name":"Number of deliveries","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"AA1D1C349119","path":"numberOfDeliveries","name":"Number of deliveries"}},{"value":"","uid":"ED12DF35A1C3","path":"greenTariff","name":"Green tariff","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"63005554AE8A","path":"greenTariff","name":"Green tariff"}},{"value":"","uid":"1D96093AD6D7","path":"paymentFrequency","name":"Payment frequency","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"E0EFED6FD7E6","path":"paymentFrequency","name":"Payment frequency"}},{"value":"0","uid":"A97ADD0FCB82","path":"kWhReadingLast","name":"kWh reading last","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"2328DC7F23AE","path":"kWhReadingLast","name":"kWh reading last"}},{"value":"0","uid":"B2FBB1BFF60F","path":"kWhReadingCurrent","name":"kWh reading current","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"8A468E75C8E8","path":"kWhReadingCurrent","name":"kWh reading current"}},{"value":"0","uid":"01591644B296","path":"kgPerMonth","name":"kg Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"36A771FC1D1A","name":"kg"},"uid":"51D072825D41","path":"kgPerMonth","name":"kg Per Month"}},{"value":"0","uid":"1F5AF1A6BD65","path":"litresPerMonth","name":"Litres Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"06B8CFC5A521","name":"litre"},"uid":"C9B7E19269A5","path":"litresPerMonth","name":"Litres Per Month"}},{"value":"10","uid":"94B617C13137","path":"kWhPerMonth","name":"kWh Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"26A5C97D3728","name":"kWh"},"uid":"4DF458FD0E4D","path":"kWhPerMonth","name":"kWh Per Month"}}],"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"end":"false","uid":"8C7BD1AB69D3","environment":{"uid":"5F5887BCF726"},"profile":{"uid":"E54C5525AA3E"},"modified":"2009-01-29 00:11:33.0","validFrom":"20090101","amountPerMonth":2.06,"itemDefinition":{"uid":"212C818D8F16"},"dataItem":{"uid":"66056991EE23"},"name":"8C7BD1AB69D3"}}'))
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
item = AMEE::Profile::Item.create(category, '66056991EE23', :kWhPerMonth => "10")
item.value("kWhPerMonth").should eql "10"
item.total_amount.should be_close(2.06, 1e-9)
item.total_amount_unit.should == "kg/month"
end
it "should be able to create new profile items (V2 XML)" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:get).with("/profiles/7V1FQMSWX64O/home/energy/quantity", {}).and_return(flexmock(:body => '/home/energy/quantity200901Quantityquantity000011-1-111000.000'))
connection.should_receive(:post).with("/profiles/7V1FQMSWX64O/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10", :representation => "full").and_return(flexmock(:body => fixture('create_item.xml'), :'[]' => 'http://example.server.com/profiles/7V1FQMSWX64O/home/energy/quantity/62BCC8C84D0C'))
category = AMEE::Profile::Category.get(connection, "/profiles/7V1FQMSWX64O/home/energy/quantity")
item = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10")
item.value("energyConsumption").should eql "10"
item.total_amount.should be_close(2.037, 1e-9)
item.total_amount_unit.should == "kg/year"
end
it "should be able to create new profile items (V2 JSON)" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:get).with("/profiles/7V1FQMSWX64O/home/energy/quantity", {}).and_return(flexmock(:body => '{"totalAmountPerMonth":0,"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"profileDate":"200901","path":"/home/energy/quantity","profile":{"uid":"7V1FQMSWX64O"},"children":{"pager":{"to":0,"lastPage":1,"start":0,"nextPage":-1,"items":0,"itemsPerPage":10,"from":0,"previousPage":-1,"requestedPage":1,"currentPage":1,"itemsFound":0},"dataCategories":[],"profileItems":{"rows":[],"label":"ProfileItems"}}}'))
connection.should_receive(:post).with("/profiles/7V1FQMSWX64O/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10", :representation => "full").and_return(flexmock(:body => fixture('create_item.json'), :'[]' => 'http://example.server.com/profiles/7V1FQMSWX64O/home/energy/quantity/8C7BD1AB69D3'))
category = AMEE::Profile::Category.get(connection, "/profiles/7V1FQMSWX64O/home/energy/quantity")
item = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10")
item.value("energyConsumption").should eql "10"
item.total_amount.should be_close(2.037, 1e-9)
item.total_amount_unit.should == "kg/year"
end
it "should be able to create new profile items and just get location of new resource (XML)" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(1.0)
connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '/home/energy/quantity200901Quantityquantity000011-1-111000.000'))
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :kWhPerMonth => "10").and_return(flexmock(:body => '/home/energy/quantity200901Quantityquantity62BCC8C84D0CkgPerMonthkg Per Month0kgPerMonthkg Per MonthtruefalsekgDOUBLEkWhPerMonthkWh Per Month10kWhPerMonthkWh Per MonthtruefalsekWhDOUBLElitresPerMonthLitres Per Month0litresPerMonthLitres Per MonthtruefalselitreDOUBLEkWhReadingCurrentkWh reading current0kWhReadingCurrentkWh reading currenttruefalseamountDOUBLEkWhReadingLastkWh reading last0kWhReadingLastkWh reading lasttruefalseamountDOUBLEpaymentFrequencyPayment frequencypaymentFrequencyPayment frequencytruefalsetextTEXTgreenTariffGreen tariffgreenTariffGreen tarifftruefalsetextTEXTseasonSeasonseasonSeasontruefalsetextTEXTincludesHeatingIncludes HeatingfalseincludesHeatingIncludes HeatingtruefalsetextTEXTnumberOfDeliveriesNumber of deliveriesnumberOfDeliveriesNumber of deliveriestruefalseamountDOUBLE2.06020090101false', :'[]' => nil))
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
location = AMEE::Profile::Item.create(category, '66056991EE23', :kWhPerMonth => "10", :get_item => false)
location.should == "/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C"
end
it "should be able to create new profile items and just get location of new resource (JSON)" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(1.0)
connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '{"totalAmountPerMonth":0,"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"profileDate":"200901","path":"/home/energy/quantity","profile":{"uid":"E54C5525AA3E"},"children":{"pager":{"to":0,"lastPage":1,"start":0,"nextPage":-1,"items":0,"itemsPerPage":10,"from":0,"previousPage":-1,"requestedPage":1,"currentPage":1,"itemsFound":0},"dataCategories":[],"profileItems":{"rows":[],"label":"ProfileItems"}}}'))
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :kWhPerMonth => "10").and_return(flexmock(:body => '{"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"profileDate":"200901","path":"/home/energy/quantity","profile":{"uid":"E54C5525AA3E"},"profileItem":{"validFrom":"20090101","amountPerMonth":2.06,"itemValues":[{"value":"0","uid":"01591644B296","path":"kgPerMonth","name":"kg Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"36A771FC1D1A","name":"kg"},"uid":"51D072825D41","path":"kgPerMonth","name":"kg Per Month"}},{"value":"10","uid":"94B617C13137","path":"kWhPerMonth","name":"kWh Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"26A5C97D3728","name":"kWh"},"uid":"4DF458FD0E4D","path":"kWhPerMonth","name":"kWh Per Month"}},{"value":"0","uid":"1F5AF1A6BD65","path":"litresPerMonth","name":"Litres Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"06B8CFC5A521","name":"litre"},"uid":"C9B7E19269A5","path":"litresPerMonth","name":"Litres Per Month"}},{"value":"0","uid":"B2FBB1BFF60F","path":"kWhReadingCurrent","name":"kWh reading current","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"8A468E75C8E8","path":"kWhReadingCurrent","name":"kWh reading current"}},{"value":"0","uid":"A97ADD0FCB82","path":"kWhReadingLast","name":"kWh reading last","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"2328DC7F23AE","path":"kWhReadingLast","name":"kWh reading last"}},{"value":"","uid":"1D96093AD6D7","path":"paymentFrequency","name":"Payment frequency","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"E0EFED6FD7E6","path":"paymentFrequency","name":"Payment frequency"}},{"value":"","uid":"ED12DF35A1C3","path":"greenTariff","name":"Green tariff","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"63005554AE8A","path":"greenTariff","name":"Green tariff"}},{"value":"","uid":"9494FB0F7DE8","path":"season","name":"Season","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"527AADFB3B65","path":"season","name":"Season"}},{"value":"false","uid":"ECB936330FEF","path":"includesHeating","name":"Includes Heating","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"1740E500BDAB","path":"includesHeating","name":"Includes Heating"}},{"value":"","uid":"C85E51E8D26C","path":"numberOfDeliveries","name":"Number of deliveries","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"AA1D1C349119","path":"numberOfDeliveries","name":"Number of deliveries"}}],"end":"false","uid":"8C7BD1AB69D3","dataItem":{"uid":"66056991EE23"},"name":"8C7BD1AB69D3"}}', :'[]' => nil))
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
location = AMEE::Profile::Item.create(category, '66056991EE23', :kWhPerMonth => "10", :get_item => false)
location.should == "/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3"
end
it "should be able to create new profile items and just get location of new resource (V2 XML)" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '/home/energy/quantity200901Quantityquantity000011-1-111000.000'))
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10").and_return(flexmock(:body => '', :'[]' => 'http://example.server.com/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C'))
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
location = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10", :get_item => false)
location.should == "/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C"
end
it "should be able to create new profile items and just get location of new resource (V2 JSON)" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '{"totalAmountPerMonth":0,"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"profileDate":"200901","path":"/home/energy/quantity","profile":{"uid":"E54C5525AA3E"},"children":{"pager":{"to":0,"lastPage":1,"start":0,"nextPage":-1,"items":0,"itemsPerPage":10,"from":0,"previousPage":-1,"requestedPage":1,"currentPage":1,"itemsFound":0},"dataCategories":[],"profileItems":{"rows":[],"label":"ProfileItems"}}}'))
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10").and_return(flexmock(:body => '', :'[]' => 'http://example.server.com/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3'))
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
location = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10", :get_item => false)
location.should == "/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3"
end
it "should be able to create new profile items and just get location of new resource (V2 XML SSL)" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '/home/energy/quantity200901Quantityquantity000011-1-111000.000'))
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10").and_return(flexmock(:body => '', :'[]' => 'https://example.server.com/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C'))
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
location = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10", :get_item => false)
location.should == "/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C"
end
it "should be able to create new profile items and just get location of new resource (V2 JSON SSL)" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '{"totalAmountPerMonth":0,"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"profileDate":"200901","path":"/home/energy/quantity","profile":{"uid":"E54C5525AA3E"},"children":{"pager":{"to":0,"lastPage":1,"start":0,"nextPage":-1,"items":0,"itemsPerPage":10,"from":0,"previousPage":-1,"requestedPage":1,"currentPage":1,"itemsFound":0},"dataCategories":[],"profileItems":{"rows":[],"label":"ProfileItems"}}}'))
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10").and_return(flexmock(:body => '', :'[]' => 'https://example.server.com/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3'))
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
location = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10", :get_item => false)
location.should == "/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3"
end
end
describe AMEE::Profile::Item, "with an authenticated XML connection" do
it "should load Profile Item" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(1.0)
connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '6E9B1517D753kgPerMonthkg Per Month10kgPerMonthkg Per MonthtruefalsekgDOUBLEkWhPerMonthkWh Per Month0kWhPerMonthkWh Per MonthtruefalsekWhDOUBLElitresPerMonthLitres Per Month0litresPerMonthLitres Per MonthtruefalselitreDOUBLEkWhReadingCurrentkWh reading current0kWhReadingCurrentkWh reading currenttruefalseamountDOUBLEkWhReadingLastkWh reading last0kWhReadingLastkWh reading lasttruefalseamountDOUBLEQuantityquantity25.20020080901false/home/energy/quantity/6E9B1517D753'))
@item = AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
@item.profile_uid.should == "92C8DB30F46B"
@item.uid.should == "6E9B1517D753"
@item.name.should == "6E9B1517D753"
@item.path.should == "/home/energy/quantity/6E9B1517D753"
@item.total_amount.should be_close(25.2, 1e-9)
@item.total_amount_unit.should == "kg/month"
@item.valid_from.should == DateTime.new(2008, 9, 1)
@item.end.should be_false
@item.full_path.should == "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753"
end
it "should parse values" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(1.0)
connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '6E9B1517D753kgPerMonthkg Per Month10kgPerMonthkg Per MonthtruefalsekgDOUBLEkWhPerMonthkWh Per Month0kWhPerMonthkWh Per MonthtruefalsekWhDOUBLElitresPerMonthLitres Per Month0litresPerMonthLitres Per MonthtruefalselitreDOUBLEkWhReadingCurrentkWh reading current0kWhReadingCurrentkWh reading currenttruefalseamountDOUBLEkWhReadingLastkWh reading last0kWhReadingLastkWh reading lasttruefalseamountDOUBLEQuantityquantity25.20020080901false/home/energy/quantity/6E9B1517D753'))
@item = AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
@item.values.size.should be(5)
@item.values[0][:uid].should == "0A671BF3D593"
@item.values[0][:name].should == "kg Per Month"
@item.values[0][:path].should == "kgPerMonth"
@item.values[0][:value].should == "10"
@item.values[1][:uid].should == "0E4CF565A5AB"
@item.values[1][:name].should == "kWh Per Month"
@item.values[1][:path].should == "kWhPerMonth"
@item.values[1][:value].should == "0"
end
it "should fail gracefully with incorrect data" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(1.0)
xml = ''
connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => xml))
lambda{AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")}.should raise_error(AMEE::BadData)
end
end
describe AMEE::Profile::Item, "with an authenticated V2 XML connection" do
it "should load Profile Item" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:get).with("/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033", {}).and_return(flexmock(:body => ' gaspaymentFrequencyPayment frequencypaymentFrequencyPayment frequencytextTEXTtruefalsegreenTariffGreen tariffgreenTariffGreen tarifftextTEXTtruefalseseasonSeasonseasonSeasontextTEXTtruefalseincludesHeatingIncludes HeatingfalseincludesHeatingIncludes HeatingtextTEXTtruefalsemassPerTimeMass Per TimekgyearmassPerTimeMass Per TimeamountDOUBLEkgyeartruefalseenergyConsumptionEnergy Consumption12kWhmonthenergyConsumptionEnergy ConsumptionamountDOUBLEkWhyeartruefalsecurrentReadingCurrent ReadingkWhcurrentReadingCurrent ReadingamountDOUBLEkWhtruefalselastReadingLast ReadingkWhlastReadingLast ReadingamountDOUBLEkWhtruefalsevolumePerTimeVolume Per TimeLyearvolumePerTimeVolume Per TimeamountDOUBLELyeartruefalsedeliveriesNumber of deliveriesyeardeliveriesNumber of deliveriesamountDOUBLEyeartruefalseQuantityquantity302.42008-09-02T01:00+0100/home/energy/quantity/30C00AD33033'))
@item = AMEE::Profile::Item.get(connection, "/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033")
@item.profile_uid.should == "9BFB0C1CD78A"
@item.uid.should == "30C00AD33033"
@item.name.should == "gas"
@item.path.should == "/home/energy/quantity/30C00AD33033"
@item.total_amount.should be_close(302.4, 1e-9)
@item.total_amount_unit.should == "kg/year"
@item.start_date.should == DateTime.new(2008, 9, 2)
@item.full_path.should == "/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033"
end
it "should parse values" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:get).with("/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033", {}).and_return(flexmock(:body => ' gaspaymentFrequencyPayment frequencypaymentFrequencyPayment frequencytextTEXTtruefalsegreenTariffGreen tariffgreenTariffGreen tarifftextTEXTtruefalseseasonSeasonseasonSeasontextTEXTtruefalseincludesHeatingIncludes HeatingfalseincludesHeatingIncludes HeatingtextTEXTtruefalsemassPerTimeMass Per TimekgyearmassPerTimeMass Per TimeamountDOUBLEkgyeartruefalseenergyConsumptionEnergy Consumption12kWhmonthenergyConsumptionEnergy ConsumptionamountDOUBLEkWhyeartruefalsecurrentReadingCurrent ReadingkWhcurrentReadingCurrent ReadingamountDOUBLEkWhtruefalselastReadingLast ReadingkWhlastReadingLast ReadingamountDOUBLEkWhtruefalsevolumePerTimeVolume Per TimeLyearvolumePerTimeVolume Per TimeamountDOUBLELyeartruefalsedeliveriesNumber of deliveriesyeardeliveriesNumber of deliveriesamountDOUBLEyeartruefalseQuantityquantity302.42008-09-02T01:00+0100/home/energy/quantity/30C00AD33033'))
@item = AMEE::Profile::Item.get(connection, "/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033")
@item.values.size.should be(10)
@item.values[4][:uid].should == "20FC928B045A"
@item.values[4][:name].should == "Mass Per Time"
@item.values[4][:path].should == "massPerTime"
@item.values[4][:value].should be_nil
@item.values[5][:uid].should == "3835DF705F9D"
@item.values[5][:name].should == "Energy Consumption"
@item.values[5][:path].should == "energyConsumption"
@item.values[5][:value].should == "12"
@item.values[5][:unit].should == "kWh"
@item.values[5][:per_unit].should == "month"
end
it "should parse multiple return values" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:get).with("/profiles/F8C2D1052BF7/home/energy/quantity/3BCDB0BB2B96", {}).and_return(flexmock(:body => 'gascurrentReadingCurrent Reading0kWhyear2010-07-16T10:44:00-04:00currentReadingCurrent ReadingamountDECIMALkWhyeartruefalsefalseenergyConsumptionEnergy Consumption13kWhmonth2010-07-16T10:44:00-04:00energyConsumptionEnergy ConsumptionamountDECIMALkWhyeartruefalsefalseincludesHeatingIncludes Heatingfalse2010-07-16T10:44:00-04:00includesHeatingIncludes HeatingtextTEXTtruefalsefalseseasonSeason2010-07-16T10:44:00-04:00seasonSeasontextTEXTtruefalsefalsegreenTariffGreen tariff2010-07-16T10:44:00-04:00greenTariffGreen tarifftextTEXTtruefalsefalsepaymentFrequencyPayment frequency2010-07-16T10:44:00-04:00paymentFrequencyPayment frequencytextTEXTtruefalsefalsemassPerTimeMass Per Time0kgyear2010-07-16T10:44:00-04:00massPerTimeMass Per TimeamountDECIMALkgyeartruefalsefalselastReadingLast Reading0kWhyear2010-07-16T10:44:00-04:00lastReadingLast ReadingamountDECIMALkWhyeartruefalsefalsevolumePerTimeVolume Per Time0Lyear2010-07-16T10:44:00-04:00volumePerTimeVolume Per TimeamountDECIMALLyeartruefalsefalsedeliveriesNumber of deliveriesyear2010-07-16T10:44:00-04:00deliveriesNumber of deliveriesamountDECIMALyeartruefalsefalseQuantityquantityfalse31.777231.77724.2This is a text nodeThis is another text node2010-07-16T10:44:00-04:00/home/energy/quantity/3BCDB0BB2B96'))
@item = AMEE::Profile::Item.get(connection, "/profiles/F8C2D1052BF7/home/energy/quantity/3BCDB0BB2B96")
@item.total_amount.should be_close(31.7772, 1e-4)
@item.total_amount_unit.should == 'kg/year'
@item.amounts.size.should be(2)
@item.amounts[0][:type].should == "CO2"
@item.amounts[0][:value].should be_close(31.7772, 1e-4)
@item.amounts[0][:unit].should == 'kg'
@item.amounts[0][:per_unit].should == 'year'
@item.amounts[0][:default].should be_true
@item.amounts[1][:type].should == "CH4"
@item.amounts[1][:value].should be_close(4.2, 1e-2)
@item.amounts[1][:unit].should == 'kg'
@item.amounts[1][:per_unit].should be_nil
@item.notes.size.should be(2)
@item.notes[0][:type].should == 'comment'
@item.notes[0][:value].should == 'This is a text node'
@item.notes[1][:type].should == 'comment'
@item.notes[1][:value].should == 'This is another text node'
end
it "should fail gracefully with incorrect data" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
xml = ' '
connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => xml))
lambda{AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")}.should raise_error(AMEE::BadData)
end
end
describe AMEE::Profile::Item, "with an authenticated V2 ATOM connection" do
it "should load Profile Item" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:get).with("/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033", {}).and_return(flexmock(:body => 'gasTue, 2 Sep 2008 01:00:00 BSTurn:item:30C00AD330332008-09-02T00:00:00.000Z2008-09-02T00:00:00.000Z<div class="vevent"><div class="summary">302.4 kg/year</div><abbr class="dtstart" title="2008-09-02T01:00+0100"> Tue, 2 Sep 2008 01:00:00 BST</abbr></div>2008-09-02T01:00+0100302.4Payment frequencyN/AGreen tariffN/ASeasonN/AIncludes HeatingfalseMass Per TimeN/AkgyearEnergy Consumption13kWhmonthCurrent ReadingN/AkWhLast ReadingN/AkWhVolume Per TimeN/ALyearNumber of deliveriesN/Ayear'))
@item = AMEE::Profile::Item.get(connection, "/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033")
@item.profile_uid.should == "9BFB0C1CD78A"
@item.uid.should == "30C00AD33033"
@item.name.should == "gas"
@item.path.should == "/home/energy/quantity/30C00AD33033"
@item.total_amount.should be_close(302.4, 1e-9)
@item.total_amount_unit.should == "kg/year"
@item.start_date.should == DateTime.new(2008, 9, 2)
@item.full_path.should == "/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033"
end
it "should parse values" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:get).with("/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033", {}).and_return(flexmock(:body => 'gasTue, 2 Sep 2008 01:00:00 BSTurn:item:30C00AD330332008-09-02T00:00:00.000Z2008-09-02T00:00:00.000Z<div class="vevent"><div class="summary">302.4 kg/year</div><abbr class="dtstart" title="2008-09-02T01:00+0100"> Tue, 2 Sep 2008 01:00:00 BST</abbr></div>2008-09-02T01:00+0100302.4Payment frequencyN/AGreen tariffN/ASeasonN/AIncludes HeatingfalseMass Per TimeN/AkgyearEnergy Consumption13kWhmonthCurrent ReadingN/AkWhLast ReadingN/AkWhVolume Per TimeN/ALyearNumber of deliveriesN/Ayear'))
@item = AMEE::Profile::Item.get(connection, "/profiles/9BFB0C1CD78A/home/energy/quantity/30C00AD33033")
@item.values.size.should be(10)
#@item.values[4][:uid].should == "20FC928B045A"
@item.values[4][:name].should == "Mass Per Time"
@item.values[4][:path].should == "massPerTime"
@item.values[4][:value].should be_nil
#@item.values[5][:uid].should == "3835DF705F9D"
@item.values[5][:name].should == "Energy Consumption"
@item.values[5][:path].should == "energyConsumption"
@item.values[5][:value].should == "13"
@item.values[5][:unit].should == "kWh"
@item.values[5][:per_unit].should == "month"
end
it "should fail gracefully with incorrect data" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
atom = ''
connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => atom))
lambda{AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")}.should raise_error(AMEE::BadData)
end
end
describe AMEE::Profile::Item, "with an authenticated JSON connection" do
it "should load Profile Item" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(1.0)
connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '{"path":"/home/energy/quantity/6E9B1517D753","profile":{"uid":"92C8DB30F46B"},"profileItem":{"created":"2008-09-12 17:20:32.0","itemValues":[{"value":"10","uid":"0A671BF3D593","path":"kgPerMonth","name":"kg Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"36A771FC1D1A","name":"kg"},"uid":"51D072825D41","path":"kgPerMonth","name":"kg Per Month"}},{"value":"0","uid":"0E4CF565A5AB","path":"kWhPerMonth","name":"kWh Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"26A5C97D3728","name":"kWh"},"uid":"4DF458FD0E4D","path":"kWhPerMonth","name":"kWh Per Month"}},{"value":"0","uid":"D58700708731","path":"litresPerMonth","name":"Litres Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"06B8CFC5A521","name":"litre"},"uid":"C9B7E19269A5","path":"litresPerMonth","name":"Litres Per Month"}},{"value":"0","uid":"BD1267F2D001","path":"kWhReadingCurrent","name":"kWh reading current","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"8A468E75C8E8","path":"kWhReadingCurrent","name":"kWh reading current"}},{"value":"0","uid":"B199A908A259","path":"kWhReadingLast","name":"kWh reading last","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"2328DC7F23AE","path":"kWhReadingLast","name":"kWh reading last"}}],"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"end":"false","uid":"6E9B1517D753","environment":{"uid":"5F5887BCF726"},"profile":{"uid":"92C8DB30F46B"},"modified":"2008-09-12 17:20:32.0","validFrom":"20080901","amountPerMonth":25.2,"itemDefinition":{"uid":"212C818D8F16"},"dataItem":{"uid":"A70149AF0F26"},"name":"6E9B1517D753"}}'))
@item = AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
@item.profile_uid.should == "92C8DB30F46B"
@item.uid.should == "6E9B1517D753"
@item.name.should == "6E9B1517D753"
@item.path.should == "/home/energy/quantity/6E9B1517D753"
@item.total_amount.should be_close(25.2, 1e-9)
@item.total_amount_unit.should == "kg/month"
@item.valid_from.should == DateTime.new(2008, 9, 1)
@item.end.should be_false
@item.full_path.should == "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753"
end
it "should parse values" do
connection = flexmock "connection"
connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '{"path":"/home/energy/quantity/6E9B1517D753","profile":{"uid":"92C8DB30F46B"},"profileItem":{"created":"2008-09-12 17:20:32.0","itemValues":[{"value":"10","uid":"0A671BF3D593","path":"kgPerMonth","name":"kg Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"36A771FC1D1A","name":"kg"},"uid":"51D072825D41","path":"kgPerMonth","name":"kg Per Month"}},{"value":"0","uid":"0E4CF565A5AB","path":"kWhPerMonth","name":"kWh Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"26A5C97D3728","name":"kWh"},"uid":"4DF458FD0E4D","path":"kWhPerMonth","name":"kWh Per Month"}},{"value":"0","uid":"D58700708731","path":"litresPerMonth","name":"Litres Per Month","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"06B8CFC5A521","name":"litre"},"uid":"C9B7E19269A5","path":"litresPerMonth","name":"Litres Per Month"}},{"value":"0","uid":"BD1267F2D001","path":"kWhReadingCurrent","name":"kWh reading current","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"8A468E75C8E8","path":"kWhReadingCurrent","name":"kWh reading current"}},{"value":"0","uid":"B199A908A259","path":"kWhReadingLast","name":"kWh reading last","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"45433E48B39F","name":"amount"},"uid":"2328DC7F23AE","path":"kWhReadingLast","name":"kWh reading last"}}],"dataCategory":{"uid":"A92693A99BAD","path":"quantity","name":"Quantity"},"end":"false","uid":"6E9B1517D753","environment":{"uid":"5F5887BCF726"},"profile":{"uid":"92C8DB30F46B"},"modified":"2008-09-12 17:20:32.0","validFrom":"20080901","amountPerMonth":25.2,"itemDefinition":{"uid":"212C818D8F16"},"dataItem":{"uid":"A70149AF0F26"},"name":"6E9B1517D753"}}'))
@item = AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
@item.values.size.should be(5)
@item.values[0][:uid].should == "0A671BF3D593"
@item.values[0][:name].should == "kg Per Month"
@item.values[0][:path].should == "kgPerMonth"
@item.values[0][:value].should == "10"
@item.values[1][:uid].should == "0E4CF565A5AB"
@item.values[1][:name].should == "kWh Per Month"
@item.values[1][:path].should == "kWhPerMonth"
@item.values[1][:value].should == "0"
end
it "should fail gracefully with incorrect data" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(1.0)
json = '{}'
connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => json))
lambda{AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")}.should raise_error(AMEE::BadData)
end
end
describe AMEE::Profile::Item, "with an authenticated V2 JSON connection" do
it "should load Profile Item" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:get).with("/profiles/447C40EB29FB/home/energy/quantity/4A69B256D62D", {}).and_return(flexmock(:body => '{"apiVersion":"2.0","profileItem":{"uid":"4A69B256D62D","itemValues":[{"itemValueDefinition":{"uid":"E0EFED6FD7E6","name":"Payment frequency","path":"paymentFrequency","valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 09:30:44.0"}},"perUnit":"","uid":"B732461AB225","unit":"","name":"Payment frequency","value":"","path":"paymentFrequency","displayPath":"paymentFrequency","displayName":"Payment frequency"},{"itemValueDefinition":{"uid":"63005554AE8A","name":"Green tariff","path":"greenTariff","valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 09:30:44.0"}},"perUnit":"","uid":"1B5F54675626","unit":"","name":"Green tariff","value":"","path":"greenTariff","displayPath":"greenTariff","displayName":"Green tariff"},{"itemValueDefinition":{"uid":"527AADFB3B65","name":"Season","path":"season","valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 09:30:44.0"}},"perUnit":"","uid":"EBCDC97E8866","unit":"","name":"Season","value":"","path":"season","displayPath":"season","displayName":"Season"},{"itemValueDefinition":{"uid":"1740E500BDAB","choices":"true=true,false=false","name":"Includes Heating","path":"includesHeating","valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 09:30:44.0"}},"perUnit":"","uid":"F3400F402132","unit":"","name":"Includes Heating","value":"false","path":"includesHeating","displayPath":"includesHeating","displayName":"Includes Heating"},{"itemValueDefinition":{"perUnit":"year","uid":"9337F5526A61","unit":"kg","choices":"0","name":"Mass Per Time","path":"massPerTime","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"16BEF21E6ADD","unit":"kg","name":"Mass Per Time","value":"0","path":"massPerTime","displayPath":"massPerTime","displayName":"Mass Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"9B455839C862","unit":"kWh","choices":"0","name":"Energy Consumption","path":"energyConsumption","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"month","uid":"8BB3F49E2BB3","unit":"kWh","name":"Energy Consumption","value":"13","path":"energyConsumption","displayPath":"energyConsumption","displayName":"Energy Consumption"},{"itemValueDefinition":{"perUnit":"year","uid":"DAEC096CF138","unit":"kWh","choices":"0","name":"Current Reading","path":"currentReading","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"8CDC8101111C","unit":"kWh","name":"Current Reading","value":"0","path":"currentReading","displayPath":"currentReading","displayName":"Current Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"F08A18BEE5E8","unit":"kWh","choices":"0","name":"Last Reading","path":"lastReading","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"3D9E46FBFDBF","unit":"kWh","name":"Last Reading","value":"0","path":"lastReading","displayPath":"lastReading","displayName":"Last Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"87E2DB9BE8BD","unit":"L","choices":"0","name":"Volume Per Time","path":"volumePerTime","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"5D354D0A1E9B","unit":"L","name":"Volume Per Time","value":"0","path":"volumePerTime","displayPath":"volumePerTime","displayName":"Volume Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"F0DE162CA7E7","choices":"0","name":"Number of deliveries","path":"deliveries","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"7071D7893AD4","unit":"","name":"Number of deliveries","value":"0","path":"deliveries","displayPath":"deliveries","displayName":"Number of deliveries"}],"dataCategory":{"uid":"A92693A99BAD","name":"Quantity","path":"quantity"},"startDate":"2008-09-02T01:00+0100","itemDefinition":{"uid":"212C818D8F16","name":"Energy Quantity","drillDown":"type"},"endDate":"","dataItem":{"uid":"66056991EE23","Label":"gas"},"modified":"2009-02-19T12:16+0000","amount":{"unit":"kg/year","value":32.058},"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10},"created":"2009-02-19T12:15+0000","name":"gas","profile":{"uid":"447C40EB29FB"}},"path":"/home/energy/quantity/4A69B256D62D","actions":{"allowCreate":true,"allowView":true,"allowList":true,"allowModify":true,"allowDelete":true},"profile":{"uid":"447C40EB29FB"}}'))
@item = AMEE::Profile::Item.get(connection, "/profiles/447C40EB29FB/home/energy/quantity/4A69B256D62D")
@item.profile_uid.should == "447C40EB29FB"
@item.uid.should == "4A69B256D62D"
@item.name.should == "gas"
@item.path.should == "/home/energy/quantity/4A69B256D62D"
@item.total_amount.should be_close(32.058, 1e-9)
@item.total_amount_unit.should == "kg/year"
@item.start_date.should == DateTime.new(2008, 9, 2)
@item.full_path.should == "/profiles/447C40EB29FB/home/energy/quantity/4A69B256D62D"
end
it "should parse values" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:get).with("/profiles/447C40EB29FB/home/energy/quantity/4A69B256D62D", {}).and_return(flexmock(:body => '{"apiVersion":"2.0","profileItem":{"uid":"4A69B256D62D","itemValues":[{"itemValueDefinition":{"uid":"E0EFED6FD7E6","name":"Payment frequency","path":"paymentFrequency","valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 09:30:44.0"}},"perUnit":"","uid":"B732461AB225","unit":"","name":"Payment frequency","value":"","path":"paymentFrequency","displayPath":"paymentFrequency","displayName":"Payment frequency"},{"itemValueDefinition":{"uid":"63005554AE8A","name":"Green tariff","path":"greenTariff","valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 09:30:44.0"}},"perUnit":"","uid":"1B5F54675626","unit":"","name":"Green tariff","value":"","path":"greenTariff","displayPath":"greenTariff","displayName":"Green tariff"},{"itemValueDefinition":{"uid":"527AADFB3B65","name":"Season","path":"season","valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 09:30:44.0"}},"perUnit":"","uid":"EBCDC97E8866","unit":"","name":"Season","value":"","path":"season","displayPath":"season","displayName":"Season"},{"itemValueDefinition":{"uid":"1740E500BDAB","choices":"true=true,false=false","name":"Includes Heating","path":"includesHeating","valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 09:30:44.0"}},"perUnit":"","uid":"F3400F402132","unit":"","name":"Includes Heating","value":"false","path":"includesHeating","displayPath":"includesHeating","displayName":"Includes Heating"},{"itemValueDefinition":{"perUnit":"year","uid":"9337F5526A61","unit":"kg","choices":"0","name":"Mass Per Time","path":"massPerTime","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"16BEF21E6ADD","unit":"kg","name":"Mass Per Time","value":"0","path":"massPerTime","displayPath":"massPerTime","displayName":"Mass Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"9B455839C862","unit":"kWh","choices":"0","name":"Energy Consumption","path":"energyConsumption","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"month","uid":"8BB3F49E2BB3","unit":"kWh","name":"Energy Consumption","value":"13","path":"energyConsumption","displayPath":"energyConsumption","displayName":"Energy Consumption"},{"itemValueDefinition":{"perUnit":"year","uid":"DAEC096CF138","unit":"kWh","choices":"0","name":"Current Reading","path":"currentReading","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"8CDC8101111C","unit":"kWh","name":"Current Reading","value":"0","path":"currentReading","displayPath":"currentReading","displayName":"Current Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"F08A18BEE5E8","unit":"kWh","choices":"0","name":"Last Reading","path":"lastReading","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"3D9E46FBFDBF","unit":"kWh","name":"Last Reading","value":"0","path":"lastReading","displayPath":"lastReading","displayName":"Last Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"87E2DB9BE8BD","unit":"L","choices":"0","name":"Volume Per Time","path":"volumePerTime","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"5D354D0A1E9B","unit":"L","name":"Volume Per Time","value":"0","path":"volumePerTime","displayPath":"volumePerTime","displayName":"Volume Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"F0DE162CA7E7","choices":"0","name":"Number of deliveries","path":"deliveries","valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 09:30:44.0","description":"","name":"amount","valueType":"DOUBLE","modified":"2007-07-27 09:30:44.0"}},"perUnit":"year","uid":"7071D7893AD4","unit":"","name":"Number of deliveries","value":"0","path":"deliveries","displayPath":"deliveries","displayName":"Number of deliveries"}],"dataCategory":{"uid":"A92693A99BAD","name":"Quantity","path":"quantity"},"startDate":"2008-09-02T01:00+0100","itemDefinition":{"uid":"212C818D8F16","name":"Energy Quantity","drillDown":"type"},"endDate":"","dataItem":{"uid":"66056991EE23","Label":"gas"},"modified":"2009-02-19T12:16+0000","amount":{"unit":"kg/year","value":32.058},"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10},"created":"2009-02-19T12:15+0000","name":"gas","profile":{"uid":"447C40EB29FB"}},"path":"/home/energy/quantity/4A69B256D62D","actions":{"allowCreate":true,"allowView":true,"allowList":true,"allowModify":true,"allowDelete":true},"profile":{"uid":"447C40EB29FB"}}'))
@item = AMEE::Profile::Item.get(connection, "/profiles/447C40EB29FB/home/energy/quantity/4A69B256D62D")
@item.values.size.should be(10)
@item.values[4][:uid].should == "16BEF21E6ADD"
@item.values[4][:name].should == "Mass Per Time"
@item.values[4][:path].should == "massPerTime"
@item.values[4][:value].should == "0"
@item.values[5][:uid].should == "8BB3F49E2BB3"
@item.values[5][:name].should == "Energy Consumption"
@item.values[5][:path].should == "energyConsumption"
@item.values[5][:value].should == "13"
@item.values[5][:unit].should == "kWh"
@item.values[5][:per_unit].should == "month"
end
it "should parse multiple return values" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:get).with("/profiles/F8C2D1052BF7/home/energy/quantity/3BCDB0BB2B96", {}).and_return(flexmock(:body => '{"apiVersion":"2.0","profileItem":{"uid":"3BCDB0BB2B96","itemValues":[{"itemValueDefinition":{"perUnit":"year","uid":"67B7476423C0","unit":"kWh","name":"Current Reading","fromData":false,"path":"currentReading","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"06F553CED9F7","startDate":"2010-07-16T10:44:00-04:00","unit":"kWh","name":"Current Reading","value":"0","path":"currentReading","displayPath":"currentReading","displayName":"Current Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"068A0D6D03F7","unit":"kWh","name":"Energy Consumption","fromData":false,"path":"energyConsumption","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"month","uid":"4CF7691084DB","startDate":"2010-07-16T10:44:00-04:00","unit":"kWh","name":"Energy Consumption","value":"13","path":"energyConsumption","displayPath":"energyConsumption","displayName":"Energy Consumption"},{"itemValueDefinition":{"uid":"1740E500BDAB","choices":"true=true,false=false","name":"Includes Heating","fromData":false,"path":"includesHeating","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"","uid":"1CA0D40208F0","startDate":"2010-07-16T10:44:00-04:00","unit":"","name":"Includes Heating","value":"false","path":"includesHeating","displayPath":"includesHeating","displayName":"Includes Heating"},{"itemValueDefinition":{"uid":"527AADFB3B65","name":"Season","fromData":false,"path":"season","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"","uid":"1ACEB4784A42","startDate":"2010-07-16T10:44:00-04:00","unit":"","name":"Season","value":"","path":"season","displayPath":"season","displayName":"Season"},{"itemValueDefinition":{"uid":"63005554AE8A","name":"Green tariff","fromData":false,"path":"greenTariff","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"","uid":"036262B5D69D","startDate":"2010-07-16T10:44:00-04:00","unit":"","name":"Green tariff","value":"","path":"greenTariff","displayPath":"greenTariff","displayName":"Green tariff"},{"itemValueDefinition":{"uid":"E0EFED6FD7E6","name":"Payment frequency","fromData":false,"path":"paymentFrequency","fromProfile":true,"valueDefinition":{"uid":"CCEB59CACE1B","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"text","valueType":"TEXT","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"","uid":"A568643CD1D7","startDate":"2010-07-16T10:44:00-04:00","unit":"","name":"Payment frequency","value":"","path":"paymentFrequency","displayPath":"paymentFrequency","displayName":"Payment frequency"},{"itemValueDefinition":{"perUnit":"year","uid":"CF12B3EBAD02","unit":"kg","name":"Mass Per Time","fromData":false,"path":"massPerTime","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"990F69A6BD48","startDate":"2010-07-16T10:44:00-04:00","unit":"kg","name":"Mass Per Time","value":"0","path":"massPerTime","displayPath":"massPerTime","displayName":"Mass Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"40AB7E90980C","unit":"kWh","name":"Last Reading","fromData":false,"path":"lastReading","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"A5BB73E6CBD2","startDate":"2010-07-16T10:44:00-04:00","unit":"kWh","name":"Last Reading","value":"0","path":"lastReading","displayPath":"lastReading","displayName":"Last Reading"},{"itemValueDefinition":{"perUnit":"year","uid":"324EC808AC30","unit":"L","name":"Volume Per Time","fromData":false,"path":"volumePerTime","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"DA93374B62C2","startDate":"2010-07-16T10:44:00-04:00","unit":"L","name":"Volume Per Time","value":"0","path":"volumePerTime","displayPath":"volumePerTime","displayName":"Volume Per Time"},{"itemValueDefinition":{"perUnit":"year","uid":"177D4642A07A","name":"Number of deliveries","fromData":false,"path":"deliveries","fromProfile":true,"valueDefinition":{"uid":"45433E48B39F","environment":{"uid":"5F5887BCF726"},"created":"2007-07-27 08:30:44.0","description":"","name":"amount","valueType":"DECIMAL","modified":"2007-07-27 08:30:44.0"},"drillDown":false},"perUnit":"year","uid":"FA09F1FF043D","startDate":"2010-07-16T10:44:00-04:00","unit":"","name":"Number of deliveries","value":"","path":"deliveries","displayPath":"deliveries","displayName":"Number of deliveries"}],"dataCategory":{"uid":"A92693A99BAD","deprecated":false,"name":"Quantity","path":"quantity"},"startDate":"2010-07-16T10:44:00-04:00","itemDefinition":{"uid":"212C818D8F16","name":"Energy Quantity","drillDown":"type"},"endDate":"","dataItem":{"uid":"66056991EE23","Label":"gas"},"modified":"2010-07-16T14:45:03Z","amount":{"unit":"kg/year","value":31.7772},"environment":{"uid":"5F5887BCF726","itemsPerFeed":10,"description":"","name":"AMEE","owner":"","path":"","itemsPerPage":10},"amounts":{"amount":[{"perUnit":"year","unit":"kg","default":"true","value":31.7772,"type":"CO2"},{"type":"CH4","unit":"kg","value":4.2}],"note":[{"type" : "comment","value" : "This is a text node"},{"type" : "comment","value" : "This is another text node"}]},"created":"2010-07-16T14:44:43Z","name":"gas","profile":{"uid":"F8C2D1052BF7"}},"path":"/home/energy/quantity/3BCDB0BB2B96","profile":{"uid":"F8C2D1052BF7"}}'))
@item = AMEE::Profile::Item.get(connection, "/profiles/F8C2D1052BF7/home/energy/quantity/3BCDB0BB2B96")
@item.total_amount.should be_close(31.7772, 1e-4)
@item.total_amount_unit.should == 'kg/year'
@item.amounts.size.should be(2)
@item.amounts[0][:type].should == "CO2"
@item.amounts[0][:value].should be_close(31.7772, 1e-4)
@item.amounts[0][:unit].should == 'kg'
@item.amounts[0][:per_unit].should == 'year'
@item.amounts[0][:default].should be_true
@item.amounts[1][:type].should == "CH4"
@item.amounts[1][:value].should be_close(4.2, 1e-2)
@item.amounts[1][:unit].should == 'kg'
@item.amounts[1][:per_unit].should be_nil
@item.notes.size.should be(2)
@item.notes[0][:type].should == 'comment'
@item.notes[0][:value].should == 'This is a text node'
@item.notes[1][:type].should == 'comment'
@item.notes[1][:value].should == 'This is another text node'
end
it "should fail gracefully with incorrect data" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
json = '{"apiVersion":"2.0"}'
connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => json))
lambda{AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")}.should raise_error(AMEE::BadData)
end
end
describe AMEE::Profile::Item, "should be able to update profile items" do
it " given an existing item" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(1.0)
connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '6E9B1517D753kgPerMonthkg Per Month10kgPerMonthkg Per MonthtruefalsekgDOUBLEkWhPerMonthkWh Per Month0kWhPerMonthkWh Per MonthtruefalsekWhDOUBLElitresPerMonthLitres Per Month0litresPerMonthLitres Per MonthtruefalselitreDOUBLEkWhReadingCurrentkWh reading current0kWhReadingCurrentkWh reading currenttruefalseamountDOUBLEkWhReadingLastkWh reading last0kWhReadingLastkWh reading lasttruefalseamountDOUBLEQuantityquantity25.20020080901false/home/energy/quantity/6E9B1517D753'))
connection.should_receive(:put).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '6E9B1517D753kgPerMonthkg Per Month10kgPerMonthkg Per MonthtruefalsekgDOUBLEkWhPerMonthkWh Per Month0kWhPerMonthkWh Per MonthtruefalsekWhDOUBLElitresPerMonthLitres Per Month0litresPerMonthLitres Per MonthtruefalselitreDOUBLEkWhReadingCurrentkWh reading current0kWhReadingCurrentkWh reading currenttruefalseamountDOUBLEkWhReadingLastkWh reading last0kWhReadingLastkWh reading lasttruefalseamountDOUBLEQuantityquantity25.20020080901false/home/energy/quantity/6E9B1517D753'))
item = AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
item.update()
end
it "without having an existing item" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(1.0)
connection.should_receive(:put).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '6E9B1517D753kgPerMonthkg Per Month10kgPerMonthkg Per MonthtruefalsekgDOUBLEkWhPerMonthkWh Per Month0kWhPerMonthkWh Per MonthtruefalsekWhDOUBLElitresPerMonthLitres Per Month0litresPerMonthLitres Per MonthtruefalselitreDOUBLEkWhReadingCurrentkWh reading current0kWhReadingCurrentkWh reading currenttruefalseamountDOUBLEkWhReadingLastkWh reading last0kWhReadingLastkWh reading lasttruefalseamountDOUBLEQuantityquantity25.20020080901false/home/energy/quantity/6E9B1517D753'))
AMEE::Profile::Item.update(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
end
end
describe AMEE::Profile::Item, "should be able to update profile items (v2 behaviour)" do
it " given an existing item" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '6E9B1517D753kgPerMonthkg Per Month10kgPerMonthkg Per MonthtruefalsekgDOUBLEkWhPerMonthkWh Per Month0kWhPerMonthkWh Per MonthtruefalsekWhDOUBLElitresPerMonthLitres Per Month0litresPerMonthLitres Per MonthtruefalselitreDOUBLEkWhReadingCurrentkWh reading current0kWhReadingCurrentkWh reading currenttruefalseamountDOUBLEkWhReadingLastkWh reading last0kWhReadingLastkWh reading lasttruefalseamountDOUBLEQuantityquantity25.20020080901false/home/energy/quantity/6E9B1517D753'))
connection.should_receive(:put).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => ''))
connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '6E9B1517D753kgPerMonthkg Per Month10kgPerMonthkg Per MonthtruefalsekgDOUBLEkWhPerMonthkWh Per Month0kWhPerMonthkWh Per MonthtruefalsekWhDOUBLElitresPerMonthLitres Per Month0litresPerMonthLitres Per MonthtruefalselitreDOUBLEkWhReadingCurrentkWh reading current0kWhReadingCurrentkWh reading currenttruefalseamountDOUBLEkWhReadingLastkWh reading last0kWhReadingLastkWh reading lasttruefalseamountDOUBLEQuantityquantity25.20020080901false/home/energy/quantity/6E9B1517D753'))
item = AMEE::Profile::Item.get(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
item.update()
end
it "without having an existing item" do
connection = flexmock "connection"
connection.should_receive(:version).and_return(2.0)
connection.should_receive(:put).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => ''))
connection.should_receive(:get).with("/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753", {}).and_return(flexmock(:body => '6E9B1517D753kgPerMonthkg Per Month10kgPerMonthkg Per MonthtruefalsekgDOUBLEkWhPerMonthkWh Per Month0kWhPerMonthkWh Per MonthtruefalsekWhDOUBLElitresPerMonthLitres Per Month0litresPerMonthLitres Per MonthtruefalselitreDOUBLEkWhReadingCurrentkWh reading current0kWhReadingCurrentkWh reading currenttruefalseamountDOUBLEkWhReadingLastkWh reading last0kWhReadingLastkWh reading lasttruefalseamountDOUBLEQuantityquantity25.20020080901false/home/energy/quantity/6E9B1517D753'))
AMEE::Profile::Item.update(connection, "/profiles/92C8DB30F46B/home/energy/quantity/6E9B1517D753")
end
end