amee 4.3.2 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.txt +6 -0
- data/Gemfile +7 -1
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/amee.gemspec +57 -6
- data/amee_test_credentials.example.yml +11 -0
- data/cassettes/AMEE_Connection/v2/raising_unhandled_errors.yml +36 -0
- data/cassettes/AMEE_Connection/v3/retries/502.yml +36 -0
- data/cassettes/AMEE_Connection/v3/retries/503.yml +36 -0
- data/cassettes/AMEE_Connection/v3/retries/504.yml +36 -0
- data/cassettes/AMEE_Connection/v3/retries/AMEE_TimeOut.yml +36 -0
- data/cassettes/AMEE_Connection/v3/should_be_able_to_get_from_meta_server.yml +30 -0
- data/cassettes/AMEE_Connection/v3/should_be_able_to_handle_failed_gets_from_meta_server.yml +30 -0
- data/cassettes/AMEE_Connection/v3/should_be_able_to_post_to_meta_server.yml +59 -0
- data/cassettes/AMEE_Connection/v3/should_have_a_connection_to_meta_server.yml +36 -0
- data/cassettes/AMEE_Connection/v3/should_login_and_know_the_path_to_the_server.yml +36 -0
- data/cassettes/AMEE_Connection_Caching_Off/authenticating.yml +36 -0
- data/cassettes/AMEE_Connection_Caching_Off/first_request.yml +40 -0
- data/cassettes/AMEE_Connection_Caching_Off/second_request.yml +40 -0
- data/cassettes/AMEE_Connection_Caching_On/authenticating.yml +36 -0
- data/cassettes/AMEE_Connection_Caching_On/first_request.yml +40 -0
- data/cassettes/AMEE_Connection_Caching_clear_all/second_request.yml +40 -0
- data/cassettes/AMEE_Connection_Caching_clear_manually/second_request.yml +40 -0
- data/cassettes/AMEE_Connection_Caching_further_down_tree/second_request.yml +79 -0
- data/cassettes/AMEE_Connection_with_authentication/handling_404s.yml +69 -0
- data/cassettes/AMEE_Connection_with_authentication/hitting_private_urls.yml +75 -0
- data/cassettes/AMEE_Connection_with_authentication/raising_errors_if_permission_denied.yml +69 -0
- data/cassettes/AMEE_Connection_with_authentication/should_re-authenticate_and_refresh_authtoken_when_authtoken_expires.yml +104 -0
- data/cassettes/AMEE_Connection_with_authentication/should_refresh_authtoken_when_authtoken_is_changed.yml +114 -0
- data/cassettes/AMEE_Connection_with_authentication/using_a_v1_key.yml +71 -0
- data/cassettes/AMEE_Connection_with_authentication/using_a_v2_key/detects_the_API_version_for_JSON.yml +36 -0
- data/cassettes/AMEE_Connection_with_authentication/using_a_v2_key/detects_the_API_version_for_XML.yml +36 -0
- data/cassettes/AMEE_Connection_with_authentication_doing_write-requests.yml +75 -0
- data/cassettes/AMEE_Connection_with_authentication_doing_write-requests/working_with_an_existing_profile/deleting_existing_items.yml +108 -0
- data/cassettes/AMEE_Connection_with_authentication_doing_write-requests/working_with_an_existing_profile/sending_updates_to_existing_items.yml +108 -0
- data/cassettes/AMEE_Connection_with_bad_authentication_information/hitting_a_private_url.yml +29 -0
- data/cassettes/AMEE_Connection_with_bad_authentication_information/hitting_a_public_url.yml +32 -0
- data/cassettes/AMEE_Connection_with_incorrect_server_name.yml +16 -0
- data/cassettes/AMEE_Connection_with_retry_enabled.yml +36 -0
- data/lib/amee/connection.rb +234 -110
- data/lib/amee/data_category.rb +2 -2
- data/lib/amee/data_item.rb +45 -2
- data/lib/amee/data_item_value.rb +1 -1
- data/lib/amee/exceptions.rb +5 -2
- data/lib/amee/parse_helper.rb +2 -0
- data/lib/amee/profile_item.rb +6 -2
- data/lib/amee/v3/connection.rb +77 -70
- data/lib/amee/v3/item_value_definition.rb +1 -1
- data/lib/amee/v3/return_value_definition.rb +1 -1
- data/spec/cache_spec.rb +107 -48
- data/spec/connection_spec.rb +224 -183
- data/spec/data_item_spec.rb +12 -0
- data/spec/data_item_value_history_spec.rb +4 -4
- data/spec/data_item_value_spec.rb +2 -2
- data/spec/fixtures/AD63A83B4D41.json +1 -1
- data/spec/fixtures/AD63A83B4D41.xml +1 -1
- data/spec/profile_item_spec.rb +14 -10
- data/spec/spec_helper.rb +29 -0
- data/spec/v3/connection_spec.rb +77 -65
- data/spec/v3/item_value_definition_spec.rb +1 -0
- data/spec/v3/return_value_definition_spec.rb +1 -1
- metadata +140 -24
- data/Gemfile.lock +0 -63
data/spec/data_item_spec.rb
CHANGED
@@ -63,6 +63,12 @@ describe AMEE::Data::Item, "with an authenticated connection" do
|
|
63
63
|
@data.values[0][:path].should == "kgCO2PerPassengerJourney"
|
64
64
|
@data.values[0][:value].should == "0"
|
65
65
|
@data.values[0][:uid].should == "127612FA4921"
|
66
|
+
@data.amounts[0][:type].should == "CO2"
|
67
|
+
@data.amounts[0][:value].should == 20.0
|
68
|
+
@data.amounts[0][:unit].should == "kg"
|
69
|
+
@data.amounts[1][:type].should == "N2O"
|
70
|
+
@data.amounts[1][:value].should == 2.0
|
71
|
+
@data.amounts[1][:unit].should == "kg"
|
66
72
|
end
|
67
73
|
|
68
74
|
it "should parse choices correctly from XML" do
|
@@ -102,6 +108,12 @@ describe AMEE::Data::Item, "with an authenticated connection" do
|
|
102
108
|
@data.values[0][:path].should == "kgCO2PerPassengerJourney"
|
103
109
|
@data.values[0][:value].should == "0"
|
104
110
|
@data.values[0][:uid].should == "127612FA4921"
|
111
|
+
@data.amounts[0][:type].should == "CO2"
|
112
|
+
@data.amounts[0][:value].should == 20.0
|
113
|
+
@data.amounts[0][:unit].should == "kg"
|
114
|
+
@data.amounts[1][:type].should == "N2O"
|
115
|
+
@data.amounts[1][:value].should == 2.0
|
116
|
+
@data.amounts[1][:unit].should == "kg"
|
105
117
|
end
|
106
118
|
|
107
119
|
it "should parse choices correctly from JSON" do
|
@@ -274,9 +274,9 @@ describe AMEE::Data::ItemValueHistory, "after loading" do
|
|
274
274
|
@connection.should_receive(:put).with(MockDataItemPath+"/127612FA4922", :value => 6, :startDate => AMEE::Epoch+1).once.and_return(flexmock(:body => ''))
|
275
275
|
@connection.should_receive(:delete).with(MockDataItemPath+"/127612FA4923").once.and_return(flexmock(:body => ''))
|
276
276
|
@connection.should_receive(:post).with(MockDataItemPath,
|
277
|
-
:kgCO2PerPassengerJourney => 7, :startDate => AMEE::Epoch+5).once.and_return({'Location'=>'http://foo.com/'})
|
277
|
+
:kgCO2PerPassengerJourney => 7, :startDate => AMEE::Epoch+5).once.and_return(flexmock(:headers_hash => {'Location'=>'http://foo.com/'}))
|
278
278
|
@connection.should_receive(:post).with(MockDataItemPath,
|
279
|
-
:kgCO2PerPassengerJourney => 11, :startDate => AMEE::Epoch+9).once.and_return({'Location'=>'http://foo.com/'})
|
279
|
+
:kgCO2PerPassengerJourney => 11, :startDate => AMEE::Epoch+9).once.and_return(flexmock(:headers_hash => {'Location'=>'http://foo.com/'}))
|
280
280
|
lambda {
|
281
281
|
@val.series = TestSeriesTwo
|
282
282
|
@val.save!
|
@@ -289,9 +289,9 @@ describe AMEE::Data::ItemValueHistory, "after loading" do
|
|
289
289
|
@connection.should_receive(:put).with(MockDataItemPath+"/127612FA4922", :value => 6, :startDate => AMEE::Epoch+1).once.and_return(flexmock(:body => ''))
|
290
290
|
@connection.should_receive(:delete).with(MockDataItemPath+"/127612FA4923").once.and_return(flexmock(:body => ''))
|
291
291
|
@connection.should_receive(:post).with(MockDataItemPath,
|
292
|
-
:kgCO2PerPassengerJourney => 7, :startDate => AMEE::Epoch+5).once.and_return({'Location'=>'https://foo.com/'})
|
292
|
+
:kgCO2PerPassengerJourney => 7, :startDate => AMEE::Epoch+5).once.and_return(flexmock(:headers_hash => {'Location'=>'https://foo.com/'}))
|
293
293
|
@connection.should_receive(:post).with(MockDataItemPath,
|
294
|
-
:kgCO2PerPassengerJourney => 11, :startDate => AMEE::Epoch+9).once.and_return({'Location'=>'https://foo.com/'})
|
294
|
+
:kgCO2PerPassengerJourney => 11, :startDate => AMEE::Epoch+9).once.and_return(flexmock(:headers_hash => {'Location'=>'https://foo.com/'}))
|
295
295
|
lambda {
|
296
296
|
@val.series = TestSeriesTwo
|
297
297
|
@val.save!
|
@@ -206,7 +206,7 @@ describe AMEE::Data::ItemValue, "after loading" do
|
|
206
206
|
with(MockResourceDataItemPath,
|
207
207
|
:kgCO2PerPassengerJourney=>42,
|
208
208
|
:startDate=>(AMEE::Epoch+3).xmlschema).
|
209
|
-
and_return({'Location'=>'http://foo.com/'})
|
209
|
+
and_return(flexmock(:headers_hash => {'Location'=>'http://foo.com/'}))
|
210
210
|
@new=AMEE::Data::ItemValue.new(:value=>42,
|
211
211
|
:start_date=>AMEE::Epoch+3,
|
212
212
|
:connection=>@connection,
|
@@ -221,7 +221,7 @@ describe AMEE::Data::ItemValue, "after loading" do
|
|
221
221
|
with(MockResourceDataItemPath,
|
222
222
|
:kgCO2PerPassengerJourney=>42,
|
223
223
|
:startDate=>(AMEE::Epoch+3).xmlschema).
|
224
|
-
and_return({'Location'=>'https://foo.com/'})
|
224
|
+
and_return(flexmock(:headers_hash => {'Location'=>'https://foo.com/'}))
|
225
225
|
@new=AMEE::Data::ItemValue.new(:value=>42,
|
226
226
|
:start_date=>AMEE::Epoch+3,
|
227
227
|
:connection=>@connection,
|
@@ -1 +1 @@
|
|
1
|
-
{"amountPerMonth":0,"userValueChoices":{"choices":[{"value":"","name":"distanceKmPerYear"},{"value":"","name":"journeysPerYear"},{"value":"-999","name":"lat1"},{"value":"-999","name":"lat2"},{"value":"-999","name":"long1"},{"value":"-999","name":"long2"}],"name":"userValueChoices"},"path":"/transport/plane/generic/AD63A83B4D41","dataItem":{"modified":"2007-08-01 09:00:41.0","created":"2007-08-01 09:00:41.0","itemDefinition":{"uid":"441BF4BEA15B"},"itemValues":[{"value":"0","uid":"127612FA4921","path":"kgCO2PerPassengerJourney","name":"kgCO2 Per Passenger Journey","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"8CB8A1789CD6","name":"kgCO2PerJourney"},"uid":"653828811D42","path":"kgCO2PerPassengerJourney","name":"kgCO2 Per Passenger Journey"}},{"value":"0.158","uid":"7F27A5707101","path":"kgCO2PerPassengerKm","name":"kgCO2 Per Passenger Km","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"996AE5477B3F","name":"kgCO2PerKm"},"uid":"D7B4340D9404","path":"kgCO2PerPassengerKm","name":"kgCO2 Per Passenger Km"}},{"value":"-","uid":"FF50EC918A8E","path":"size","name":"Size","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"5D7FB5F552A5","path":"size","name":"Size"}},{"value":"domestic","uid":"FDD62D27AA15","path":"type","name":"Type","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"C376560CB19F","path":"type","name":"Type"}},{"value":"DfT INAS Division, 29 March 2007","uid":"9BE08FBEC54E","path":"source","name":"Source","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"0F0592F05AAC","path":"source","name":"Source"}}],"label":"domestic","dataCategory":{"uid":"FBA97B70DBDF","path":"generic","name":"Generic"},"uid":"AD63A83B4D41","environment":{"uid":"5F5887BCF726"},"path":"","name":"AD63A83B4D41"}}
|
1
|
+
{"amountPerMonth":0,"amounts":{"amount":[{"unit":"kg","value":20,"type":"CO2"},{"unit":"kg","value":2,"type":"N2O"},{"unit":"kg","value":5,"type":"CH4"}],"note":[{"value":"No global warming potentials are applied in this calculation","type":"comment"}]},"userValueChoices":{"choices":[{"value":"","name":"distanceKmPerYear"},{"value":"","name":"journeysPerYear"},{"value":"-999","name":"lat1"},{"value":"-999","name":"lat2"},{"value":"-999","name":"long1"},{"value":"-999","name":"long2"}],"name":"userValueChoices"},"path":"/transport/plane/generic/AD63A83B4D41","dataItem":{"modified":"2007-08-01 09:00:41.0","created":"2007-08-01 09:00:41.0","itemDefinition":{"uid":"441BF4BEA15B"},"itemValues":[{"value":"0","uid":"127612FA4921","path":"kgCO2PerPassengerJourney","name":"kgCO2 Per Passenger Journey","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"8CB8A1789CD6","name":"kgCO2PerJourney"},"uid":"653828811D42","path":"kgCO2PerPassengerJourney","name":"kgCO2 Per Passenger Journey"}},{"value":"0.158","uid":"7F27A5707101","path":"kgCO2PerPassengerKm","name":"kgCO2 Per Passenger Km","itemValueDefinition":{"valueDefinition":{"valueType":"DOUBLE","uid":"996AE5477B3F","name":"kgCO2PerKm"},"uid":"D7B4340D9404","path":"kgCO2PerPassengerKm","name":"kgCO2 Per Passenger Km"}},{"value":"-","uid":"FF50EC918A8E","path":"size","name":"Size","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"5D7FB5F552A5","path":"size","name":"Size"}},{"value":"domestic","uid":"FDD62D27AA15","path":"type","name":"Type","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"C376560CB19F","path":"type","name":"Type"}},{"value":"DfT INAS Division, 29 March 2007","uid":"9BE08FBEC54E","path":"source","name":"Source","itemValueDefinition":{"valueDefinition":{"valueType":"TEXT","uid":"CCEB59CACE1B","name":"text"},"uid":"0F0592F05AAC","path":"source","name":"Source"}}],"label":"domestic","dataCategory":{"uid":"FBA97B70DBDF","path":"generic","name":"Generic"},"uid":"AD63A83B4D41","environment":{"uid":"5F5887BCF726"},"path":"","name":"AD63A83B4D41"}}
|
@@ -1 +1 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?><Resources><DataItemResource><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="AD63A83B4D41"><Name>AD63A83B4D41</Name><ItemValues><ItemValue uid="127612FA4921"><Path>kgCO2PerPassengerJourney</Path><Name>kgCO2 Per Passenger Journey</Name><Value>0</Value><ItemValueDefinition uid="653828811D42"><Path>kgCO2PerPassengerJourney</Path><Name>kgCO2 Per Passenger Journey</Name><FromProfile>false</FromProfile><FromData>true</FromData><ValueDefinition uid="8CB8A1789CD6"><Name>kgCO2PerJourney</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="7F27A5707101"><Path>kgCO2PerPassengerKm</Path><Name>kgCO2 Per Passenger Km</Name><Value>0.158</Value><ItemValueDefinition uid="D7B4340D9404"><Path>kgCO2PerPassengerKm</Path><Name>kgCO2 Per Passenger Km</Name><FromProfile>false</FromProfile><FromData>true</FromData><ValueDefinition uid="996AE5477B3F"><Name>kgCO2PerKm</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="FF50EC918A8E"><Path>size</Path><Name>Size</Name><Value>-</Value><ItemValueDefinition uid="5D7FB5F552A5"><Path>size</Path><Name>Size</Name><FromProfile>false</FromProfile><FromData>true</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="FDD62D27AA15"><Path>type</Path><Name>Type</Name><Value>domestic</Value><ItemValueDefinition uid="C376560CB19F"><Path>type</Path><Name>Type</Name><FromProfile>false</FromProfile><FromData>true</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="9BE08FBEC54E"><Path>source</Path><Name>Source</Name><Value>DfT INAS Division, 29 March 2007</Value><ItemValueDefinition uid="0F0592F05AAC"><Path>source</Path><Name>Source</Name><FromProfile>false</FromProfile><FromData>true</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><Environment uid="5F5887BCF726"/><ItemDefinition uid="441BF4BEA15B"/><DataCategory uid="FBA97B70DBDF"><Name>Generic</Name><Path>generic</Path></DataCategory><Path>AD63A83B4D41</Path><Label>domestic</Label></DataItem><Path>/transport/plane/generic/AD63A83B4D41</Path><Choices><Name>userValueChoices</Name><Choices><Choice><Name>distanceKmPerYear</Name><Value/></Choice><Choice><Name>journeysPerYear</Name><Value/></Choice><Choice><Name>lat1</Name><Value>-999</Value></Choice><Choice><Name>lat2</Name><Value>-999</Value></Choice><Choice><Name>long1</Name><Value>-999</Value></Choice><Choice><Name>long2</Name><Value>-999</Value></Choice></Choices></Choices><AmountPerMonth>0.000</AmountPerMonth></DataItemResource></Resources>
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?><Resources><DataItemResource><DataItem created="2007-08-01 09:00:41.0" modified="2007-08-01 09:00:41.0" uid="AD63A83B4D41"><Name>AD63A83B4D41</Name><ItemValues><ItemValue uid="127612FA4921"><Path>kgCO2PerPassengerJourney</Path><Name>kgCO2 Per Passenger Journey</Name><Value>0</Value><ItemValueDefinition uid="653828811D42"><Path>kgCO2PerPassengerJourney</Path><Name>kgCO2 Per Passenger Journey</Name><FromProfile>false</FromProfile><FromData>true</FromData><ValueDefinition uid="8CB8A1789CD6"><Name>kgCO2PerJourney</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="7F27A5707101"><Path>kgCO2PerPassengerKm</Path><Name>kgCO2 Per Passenger Km</Name><Value>0.158</Value><ItemValueDefinition uid="D7B4340D9404"><Path>kgCO2PerPassengerKm</Path><Name>kgCO2 Per Passenger Km</Name><FromProfile>false</FromProfile><FromData>true</FromData><ValueDefinition uid="996AE5477B3F"><Name>kgCO2PerKm</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="FF50EC918A8E"><Path>size</Path><Name>Size</Name><Value>-</Value><ItemValueDefinition uid="5D7FB5F552A5"><Path>size</Path><Name>Size</Name><FromProfile>false</FromProfile><FromData>true</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="FDD62D27AA15"><Path>type</Path><Name>Type</Name><Value>domestic</Value><ItemValueDefinition uid="C376560CB19F"><Path>type</Path><Name>Type</Name><FromProfile>false</FromProfile><FromData>true</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="9BE08FBEC54E"><Path>source</Path><Name>Source</Name><Value>DfT INAS Division, 29 March 2007</Value><ItemValueDefinition uid="0F0592F05AAC"><Path>source</Path><Name>Source</Name><FromProfile>false</FromProfile><FromData>true</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><Environment uid="5F5887BCF726"/><ItemDefinition uid="441BF4BEA15B"/><DataCategory uid="FBA97B70DBDF"><Name>Generic</Name><Path>generic</Path></DataCategory><Path>AD63A83B4D41</Path><Label>domestic</Label></DataItem><Path>/transport/plane/generic/AD63A83B4D41</Path><Choices><Name>userValueChoices</Name><Choices><Choice><Name>distanceKmPerYear</Name><Value/></Choice><Choice><Name>journeysPerYear</Name><Value/></Choice><Choice><Name>lat1</Name><Value>-999</Value></Choice><Choice><Name>lat2</Name><Value>-999</Value></Choice><Choice><Name>long1</Name><Value>-999</Value></Choice><Choice><Name>long2</Name><Value>-999</Value></Choice></Choices></Choices><AmountPerMonth>0.000</AmountPerMonth><Amount unit="kg/year">10.89855</Amount><Amounts><Amount perUnit="" type="CO2" unit="kg">20</Amount><Amount perUnit="" type="N2O" unit="kg">2</Amount><Amount perUnit="" type="CO2" unit="kg">5</Amount><Note type="comment">No global warming potentials are applied in this calculation</Note></Amounts></DataItemResource></Resources>
|
data/spec/profile_item_spec.rb
CHANGED
@@ -33,57 +33,61 @@ describe AMEE::Profile::Item do
|
|
33
33
|
connection = flexmock "connection"
|
34
34
|
connection.should_receive(:version).and_return(1.0)
|
35
35
|
connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home/energy/quantity</Path><ProfileDate>200901</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><Children><ProfileCategories/><ProfileItems/><Pager><Start>0</Start><From>0</From><To>0</To><Items>0</Items><CurrentPage>1</CurrentPage><RequestedPage>1</RequestedPage><NextPage>-1</NextPage><PreviousPage>-1</PreviousPage><LastPage>1</LastPage><ItemsPerPage>10</ItemsPerPage><ItemsFound>0</ItemsFound></Pager></Children><TotalAmountPerMonth>0.000</TotalAmountPerMonth></ProfileCategoryResource></Resources>'))
|
36
|
-
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :kWhPerMonth => "10").and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home/energy/quantity</Path><ProfileDate>200901</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><ProfileItem uid="62BCC8C84D0C"><Name>62BCC8C84D0C</Name><ItemValues><ItemValue uid="D281CE71180D"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>0</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="67DD1D3A00C4"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>10</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="2BEEF89EFCAB"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="7C8968300299"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="F68E3F8F988B"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="1932882328F0"><Path>paymentFrequency</Path><Name>Payment frequency</Name><Value/><ItemValueDefinition uid="E0EFED6FD7E6"><Path>paymentFrequency</Path><Name>Payment frequency</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="826512435B43"><Path>greenTariff</Path><Name>Green tariff</Name><Value/><ItemValueDefinition uid="63005554AE8A"><Path>greenTariff</Path><Name>Green tariff</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="4D2D471F2F04"><Path>season</Path><Name>Season</Name><Value/><ItemValueDefinition uid="527AADFB3B65"><Path>season</Path><Name>Season</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="583D56F63CD5"><Path>includesHeating</Path><Name>Includes Heating</Name><Value>false</Value><ItemValueDefinition uid="1740E500BDAB"><Path>includesHeating</Path><Name>Includes Heating</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="95DF5F127142"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><Value/><ItemValueDefinition uid="AA1D1C349119"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><AmountPerMonth>2.060</AmountPerMonth><ValidFrom>20090101</ValidFrom><End>false</End><DataItem uid="66056991EE23"/></ProfileItem></ProfileCategoryResource></Resources>', :'
|
36
|
+
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :kWhPerMonth => "10").and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home/energy/quantity</Path><ProfileDate>200901</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><ProfileItem uid="62BCC8C84D0C"><Name>62BCC8C84D0C</Name><ItemValues><ItemValue uid="D281CE71180D"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>0</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="67DD1D3A00C4"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>10</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="2BEEF89EFCAB"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="7C8968300299"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="F68E3F8F988B"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="1932882328F0"><Path>paymentFrequency</Path><Name>Payment frequency</Name><Value/><ItemValueDefinition uid="E0EFED6FD7E6"><Path>paymentFrequency</Path><Name>Payment frequency</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="826512435B43"><Path>greenTariff</Path><Name>Green tariff</Name><Value/><ItemValueDefinition uid="63005554AE8A"><Path>greenTariff</Path><Name>Green tariff</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="4D2D471F2F04"><Path>season</Path><Name>Season</Name><Value/><ItemValueDefinition uid="527AADFB3B65"><Path>season</Path><Name>Season</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="583D56F63CD5"><Path>includesHeating</Path><Name>Includes Heating</Name><Value>false</Value><ItemValueDefinition uid="1740E500BDAB"><Path>includesHeating</Path><Name>Includes Heating</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="95DF5F127142"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><Value/><ItemValueDefinition uid="AA1D1C349119"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><AmountPerMonth>2.060</AmountPerMonth><ValidFrom>20090101</ValidFrom><End>false</End><DataItem uid="66056991EE23"/></ProfileItem></ProfileCategoryResource></Resources>', :headers_hash => { 'Location' => nil}))
|
37
37
|
connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileItemResource><ProfileItem created="2009-01-28 23:35:00.0" modified="2009-01-28 23:35:00.0" uid="62BCC8C84D0C"><Name>62BCC8C84D0C</Name><ItemValues><ItemValue uid="95DF5F127142"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><Value/><ItemValueDefinition uid="AA1D1C349119"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="4D2D471F2F04"><Path>season</Path><Name>Season</Name><Value/><ItemValueDefinition uid="527AADFB3B65"><Path>season</Path><Name>Season</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="583D56F63CD5"><Path>includesHeating</Path><Name>Includes Heating</Name><Value>false</Value><ItemValueDefinition uid="1740E500BDAB"><Path>includesHeating</Path><Name>Includes Heating</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="826512435B43"><Path>greenTariff</Path><Name>Green tariff</Name><Value/><ItemValueDefinition uid="63005554AE8A"><Path>greenTariff</Path><Name>Green tariff</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="1932882328F0"><Path>paymentFrequency</Path><Name>Payment frequency</Name><Value/><ItemValueDefinition uid="E0EFED6FD7E6"><Path>paymentFrequency</Path><Name>Payment frequency</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="F68E3F8F988B"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="7C8968300299"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="D281CE71180D"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>0</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="67DD1D3A00C4"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>10</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="2BEEF89EFCAB"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><Environment uid="5F5887BCF726"/><ItemDefinition uid="212C818D8F16"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><AmountPerMonth>2.060</AmountPerMonth><ValidFrom>20090101</ValidFrom><End>false</End><DataItem uid="66056991EE23"/><Profile uid="E54C5525AA3E"/></ProfileItem><Path>/home/energy/quantity/62BCC8C84D0C</Path><Profile uid="E54C5525AA3E"/></ProfileItemResource></Resources>'))
|
38
38
|
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
|
39
39
|
item = AMEE::Profile::Item.create(category, '66056991EE23', :kWhPerMonth => "10")
|
40
40
|
item.value("kWhPerMonth").should eql "10"
|
41
41
|
item.total_amount.should be_within(1.0e-09).of(2.06)
|
42
42
|
item.total_amount_unit.should == "kg/month"
|
43
|
+
item.full_path.should == '/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C'
|
43
44
|
end
|
44
45
|
|
45
46
|
it "should be able to create new profile items (JSON)" do
|
46
47
|
connection = flexmock "connection"
|
47
48
|
connection.should_receive(:version).and_return(1.0)
|
48
49
|
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"}}}'))
|
49
|
-
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"}}', :'
|
50
|
+
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"}}', :headers_hash => { 'Location' => nil}))
|
50
51
|
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"}}'))
|
51
52
|
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
|
52
53
|
item = AMEE::Profile::Item.create(category, '66056991EE23', :kWhPerMonth => "10")
|
53
54
|
item.value("kWhPerMonth").should eql "10"
|
54
55
|
item.total_amount.should be_within(1.0e-09).of(2.06)
|
55
56
|
item.total_amount_unit.should == "kg/month"
|
57
|
+
item.full_path.should == '/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3'
|
56
58
|
end
|
57
59
|
|
58
60
|
it "should be able to create new profile items (V2 XML)" do
|
59
61
|
connection = flexmock "connection"
|
60
62
|
connection.should_receive(:version).and_return(2.0)
|
61
63
|
connection.should_receive(:get).with("/profiles/7V1FQMSWX64O/home/energy/quantity", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home/energy/quantity</Path><ProfileDate>200901</ProfileDate><Profile uid="7V1FQMSWX64O"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><Children><ProfileCategories/><ProfileItems/><Pager><Start>0</Start><From>0</From><To>0</To><Items>0</Items><CurrentPage>1</CurrentPage><RequestedPage>1</RequestedPage><NextPage>-1</NextPage><PreviousPage>-1</PreviousPage><LastPage>1</LastPage><ItemsPerPage>10</ItemsPerPage><ItemsFound>0</ItemsFound></Pager></Children><TotalAmountPerMonth>0.000</TotalAmountPerMonth></ProfileCategoryResource></Resources>'))
|
62
|
-
connection.should_receive(:post).with("/profiles/7V1FQMSWX64O/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10", :representation => "full").and_return(flexmock(:body => fixture('create_item.xml'), :'
|
64
|
+
connection.should_receive(:post).with("/profiles/7V1FQMSWX64O/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10", :representation => "full").and_return(flexmock(:body => fixture('create_item.xml'), :headers_hash => { 'Location' => 'http://example.server.com/profiles/7V1FQMSWX64O/home/energy/quantity/62BCC8C84D0C'}))
|
63
65
|
category = AMEE::Profile::Category.get(connection, "/profiles/7V1FQMSWX64O/home/energy/quantity")
|
64
66
|
item = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10")
|
65
67
|
item.value("energyConsumption").should eql "10"
|
66
68
|
item.total_amount.should be_within(1.0e-09).of(2.037)
|
67
69
|
item.total_amount_unit.should == "kg/year"
|
70
|
+
item.full_path.should == '/profiles/7V1FQMSWX64O/home/energy/quantity/40OAI5AZMPTJ'
|
68
71
|
end
|
69
72
|
|
70
73
|
it "should be able to create new profile items (V2 JSON)" do
|
71
74
|
connection = flexmock "connection"
|
72
75
|
connection.should_receive(:version).and_return(2.0)
|
73
76
|
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"}}}'))
|
74
|
-
connection.should_receive(:post).with("/profiles/7V1FQMSWX64O/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10", :representation => "full").and_return(flexmock(:body => fixture('create_item.json'), :'
|
77
|
+
connection.should_receive(:post).with("/profiles/7V1FQMSWX64O/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10", :representation => "full").and_return(flexmock(:body => fixture('create_item.json'), :headers_hash => { 'Location' => 'http://example.server.com/profiles/7V1FQMSWX64O/home/energy/quantity/8C7BD1AB69D3'}))
|
75
78
|
category = AMEE::Profile::Category.get(connection, "/profiles/7V1FQMSWX64O/home/energy/quantity")
|
76
79
|
item = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10")
|
77
80
|
item.value("energyConsumption").should eql "10"
|
78
81
|
item.total_amount.should be_within(1.0e-09).of(2.037)
|
79
82
|
item.total_amount_unit.should == "kg/year"
|
83
|
+
item.full_path.should == '/profiles/7V1FQMSWX64O/home/energy/quantity/DWR15I7XMTZI'
|
80
84
|
end
|
81
85
|
|
82
86
|
it "should be able to create new profile items and just get location of new resource (XML)" do
|
83
87
|
connection = flexmock "connection"
|
84
88
|
connection.should_receive(:version).and_return(1.0)
|
85
89
|
connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home/energy/quantity</Path><ProfileDate>200901</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><Children><ProfileCategories/><ProfileItems/><Pager><Start>0</Start><From>0</From><To>0</To><Items>0</Items><CurrentPage>1</CurrentPage><RequestedPage>1</RequestedPage><NextPage>-1</NextPage><PreviousPage>-1</PreviousPage><LastPage>1</LastPage><ItemsPerPage>10</ItemsPerPage><ItemsFound>0</ItemsFound></Pager></Children><TotalAmountPerMonth>0.000</TotalAmountPerMonth></ProfileCategoryResource></Resources>'))
|
86
|
-
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :kWhPerMonth => "10").and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home/energy/quantity</Path><ProfileDate>200901</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><ProfileItem uid="62BCC8C84D0C"><Name>62BCC8C84D0C</Name><ItemValues><ItemValue uid="D281CE71180D"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>0</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="67DD1D3A00C4"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>10</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="2BEEF89EFCAB"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="7C8968300299"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="F68E3F8F988B"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="1932882328F0"><Path>paymentFrequency</Path><Name>Payment frequency</Name><Value/><ItemValueDefinition uid="E0EFED6FD7E6"><Path>paymentFrequency</Path><Name>Payment frequency</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="826512435B43"><Path>greenTariff</Path><Name>Green tariff</Name><Value/><ItemValueDefinition uid="63005554AE8A"><Path>greenTariff</Path><Name>Green tariff</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="4D2D471F2F04"><Path>season</Path><Name>Season</Name><Value/><ItemValueDefinition uid="527AADFB3B65"><Path>season</Path><Name>Season</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="583D56F63CD5"><Path>includesHeating</Path><Name>Includes Heating</Name><Value>false</Value><ItemValueDefinition uid="1740E500BDAB"><Path>includesHeating</Path><Name>Includes Heating</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="95DF5F127142"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><Value/><ItemValueDefinition uid="AA1D1C349119"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><AmountPerMonth>2.060</AmountPerMonth><ValidFrom>20090101</ValidFrom><End>false</End><DataItem uid="66056991EE23"/></ProfileItem></ProfileCategoryResource></Resources>', :'
|
90
|
+
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :kWhPerMonth => "10").and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home/energy/quantity</Path><ProfileDate>200901</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><ProfileItem uid="62BCC8C84D0C"><Name>62BCC8C84D0C</Name><ItemValues><ItemValue uid="D281CE71180D"><Path>kgPerMonth</Path><Name>kg Per Month</Name><Value>0</Value><ItemValueDefinition uid="51D072825D41"><Path>kgPerMonth</Path><Name>kg Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="36A771FC1D1A"><Name>kg</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="67DD1D3A00C4"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><Value>10</Value><ItemValueDefinition uid="4DF458FD0E4D"><Path>kWhPerMonth</Path><Name>kWh Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="26A5C97D3728"><Name>kWh</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="2BEEF89EFCAB"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><Value>0</Value><ItemValueDefinition uid="C9B7E19269A5"><Path>litresPerMonth</Path><Name>Litres Per Month</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="06B8CFC5A521"><Name>litre</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="7C8968300299"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><Value>0</Value><ItemValueDefinition uid="8A468E75C8E8"><Path>kWhReadingCurrent</Path><Name>kWh reading current</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="F68E3F8F988B"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><Value>0</Value><ItemValueDefinition uid="2328DC7F23AE"><Path>kWhReadingLast</Path><Name>kWh reading last</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="1932882328F0"><Path>paymentFrequency</Path><Name>Payment frequency</Name><Value/><ItemValueDefinition uid="E0EFED6FD7E6"><Path>paymentFrequency</Path><Name>Payment frequency</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="826512435B43"><Path>greenTariff</Path><Name>Green tariff</Name><Value/><ItemValueDefinition uid="63005554AE8A"><Path>greenTariff</Path><Name>Green tariff</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="4D2D471F2F04"><Path>season</Path><Name>Season</Name><Value/><ItemValueDefinition uid="527AADFB3B65"><Path>season</Path><Name>Season</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="583D56F63CD5"><Path>includesHeating</Path><Name>Includes Heating</Name><Value>false</Value><ItemValueDefinition uid="1740E500BDAB"><Path>includesHeating</Path><Name>Includes Heating</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="CCEB59CACE1B"><Name>text</Name><ValueType>TEXT</ValueType></ValueDefinition></ItemValueDefinition></ItemValue><ItemValue uid="95DF5F127142"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><Value/><ItemValueDefinition uid="AA1D1C349119"><Path>numberOfDeliveries</Path><Name>Number of deliveries</Name><FromProfile>true</FromProfile><FromData>false</FromData><ValueDefinition uid="45433E48B39F"><Name>amount</Name><ValueType>DOUBLE</ValueType></ValueDefinition></ItemValueDefinition></ItemValue></ItemValues><AmountPerMonth>2.060</AmountPerMonth><ValidFrom>20090101</ValidFrom><End>false</End><DataItem uid="66056991EE23"/></ProfileItem></ProfileCategoryResource></Resources>', :headers_hash => { 'Location' => nil}))
|
87
91
|
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
|
88
92
|
location = AMEE::Profile::Item.create(category, '66056991EE23', :kWhPerMonth => "10", :get_item => false)
|
89
93
|
location.should == "/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C"
|
@@ -93,7 +97,7 @@ describe AMEE::Profile::Item do
|
|
93
97
|
connection = flexmock "connection"
|
94
98
|
connection.should_receive(:version).and_return(1.0)
|
95
99
|
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"}}}'))
|
96
|
-
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"}}', :'
|
100
|
+
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"}}', :headers_hash => { 'Location' => nil}))
|
97
101
|
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
|
98
102
|
location = AMEE::Profile::Item.create(category, '66056991EE23', :kWhPerMonth => "10", :get_item => false)
|
99
103
|
location.should == "/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3"
|
@@ -103,7 +107,7 @@ describe AMEE::Profile::Item do
|
|
103
107
|
connection = flexmock "connection"
|
104
108
|
connection.should_receive(:version).and_return(2.0)
|
105
109
|
connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home/energy/quantity</Path><ProfileDate>200901</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><Children><ProfileCategories/><ProfileItems/><Pager><Start>0</Start><From>0</From><To>0</To><Items>0</Items><CurrentPage>1</CurrentPage><RequestedPage>1</RequestedPage><NextPage>-1</NextPage><PreviousPage>-1</PreviousPage><LastPage>1</LastPage><ItemsPerPage>10</ItemsPerPage><ItemsFound>0</ItemsFound></Pager></Children><TotalAmountPerMonth>0.000</TotalAmountPerMonth></ProfileCategoryResource></Resources>'))
|
106
|
-
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10").and_return(flexmock(:body => '', :'
|
110
|
+
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10").and_return(flexmock(:body => '', :headers_hash => { 'Location' => 'http://example.server.com/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C'}))
|
107
111
|
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
|
108
112
|
location = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10", :get_item => false)
|
109
113
|
location.should == "/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C"
|
@@ -113,7 +117,7 @@ describe AMEE::Profile::Item do
|
|
113
117
|
connection = flexmock "connection"
|
114
118
|
connection.should_receive(:version).and_return(2.0)
|
115
119
|
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"}}}'))
|
116
|
-
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10").and_return(flexmock(:body => '', :'
|
120
|
+
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10").and_return(flexmock(:body => '', :headers_hash => { 'Location' => 'http://example.server.com/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3'}))
|
117
121
|
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
|
118
122
|
location = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10", :get_item => false)
|
119
123
|
location.should == "/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3"
|
@@ -123,7 +127,7 @@ describe AMEE::Profile::Item do
|
|
123
127
|
connection = flexmock "connection"
|
124
128
|
connection.should_receive(:version).and_return(2.0)
|
125
129
|
connection.should_receive(:get).with("/profiles/E54C5525AA3E/home/energy/quantity", {}).and_return(flexmock(:body => '<?xml version="1.0" encoding="UTF-8"?><Resources><ProfileCategoryResource><Path>/home/energy/quantity</Path><ProfileDate>200901</ProfileDate><Profile uid="E54C5525AA3E"/><DataCategory uid="A92693A99BAD"><Name>Quantity</Name><Path>quantity</Path></DataCategory><Children><ProfileCategories/><ProfileItems/><Pager><Start>0</Start><From>0</From><To>0</To><Items>0</Items><CurrentPage>1</CurrentPage><RequestedPage>1</RequestedPage><NextPage>-1</NextPage><PreviousPage>-1</PreviousPage><LastPage>1</LastPage><ItemsPerPage>10</ItemsPerPage><ItemsFound>0</ItemsFound></Pager></Children><TotalAmountPerMonth>0.000</TotalAmountPerMonth></ProfileCategoryResource></Resources>'))
|
126
|
-
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10").and_return(flexmock(:body => '', :'
|
130
|
+
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10").and_return(flexmock(:body => '', :headers_hash => { 'Location' => 'https://example.server.com/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C'}))
|
127
131
|
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
|
128
132
|
location = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10", :get_item => false)
|
129
133
|
location.should == "/profiles/E54C5525AA3E/home/energy/quantity/62BCC8C84D0C"
|
@@ -133,7 +137,7 @@ describe AMEE::Profile::Item do
|
|
133
137
|
connection = flexmock "connection"
|
134
138
|
connection.should_receive(:version).and_return(2.0)
|
135
139
|
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"}}}'))
|
136
|
-
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10").and_return(flexmock(:body => '', :'
|
140
|
+
connection.should_receive(:post).with("/profiles/E54C5525AA3E/home/energy/quantity", :dataItemUid => '66056991EE23', :energyConsumption => "10").and_return(flexmock(:body => '', :headers_hash => { 'Location' => 'https://example.server.com/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3'}))
|
137
141
|
category = AMEE::Profile::Category.get(connection, "/profiles/E54C5525AA3E/home/energy/quantity")
|
138
142
|
location = AMEE::Profile::Item.create(category, '66056991EE23', :energyConsumption => "10", :get_item => false)
|
139
143
|
location.should == "/profiles/E54C5525AA3E/home/energy/quantity/8C7BD1AB69D3"
|
data/spec/spec_helper.rb
CHANGED
@@ -4,12 +4,41 @@
|
|
4
4
|
require 'rubygems'
|
5
5
|
require 'rspec'
|
6
6
|
require 'logger'
|
7
|
+
require 'vcr'
|
8
|
+
require 'pry'
|
9
|
+
require 'webmock/rspec'
|
7
10
|
|
8
11
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
9
12
|
require 'amee'
|
10
13
|
|
14
|
+
def test_credentials(filename)
|
15
|
+
test_creds = File.read File.dirname(__FILE__)+'/../'+filename
|
16
|
+
YAML.load(test_creds)
|
17
|
+
end
|
18
|
+
|
19
|
+
AMEE_V1_API_KEY = test_credentials('amee_test_credentials.yml')['v1']['api_key']
|
20
|
+
AMEE_V1_PASSWORD = test_credentials('amee_test_credentials.yml')['v1']['password']
|
21
|
+
AMEE_V2_API_KEY = test_credentials('amee_test_credentials.yml')['v2']['api_key']
|
22
|
+
AMEE_V2_PASSWORD = test_credentials('amee_test_credentials.yml')['v2']['password']
|
23
|
+
AMEE_V3_API_KEY = test_credentials('amee_test_credentials.yml')['v3']['api_key']
|
24
|
+
AMEE_V3_PASSWORD = test_credentials('amee_test_credentials.yml')['v3']['password']
|
25
|
+
|
26
|
+
|
27
|
+
VCR.config do |c|
|
28
|
+
c.stub_with :webmock
|
29
|
+
c.default_cassette_options = { :record => :once }
|
30
|
+
c.cassette_library_dir = 'cassettes'
|
31
|
+
c.filter_sensitive_data('<AMEE_V1_API_KEY>') { AMEE_V1_API_KEY}
|
32
|
+
c.filter_sensitive_data('<AMEE_V1_PASSWORD>') { AMEE_V1_PASSWORD}
|
33
|
+
c.filter_sensitive_data('<AMEE_V2_API_KEY>') { AMEE_V2_API_KEY}
|
34
|
+
c.filter_sensitive_data('<AMEE_V2_PASSWORD>') { AMEE_V2_PASSWORD}
|
35
|
+
c.filter_sensitive_data('<AMEE_V3_API_KEY>') { AMEE_V3_API_KEY }
|
36
|
+
c.filter_sensitive_data('<AMEE_V3_PASSWORD>') { AMEE_V3_PASSWORD }
|
37
|
+
end
|
38
|
+
|
11
39
|
RSpec.configure do |config|
|
12
40
|
config.mock_with :flexmock
|
41
|
+
config.extend VCR::RSpec::Macros
|
13
42
|
end
|
14
43
|
|
15
44
|
# Stub activerecord for rails tests
|
data/spec/v3/connection_spec.rb
CHANGED
@@ -6,64 +6,44 @@ require 'spec_helper.rb'
|
|
6
6
|
describe AMEE::Connection do
|
7
7
|
|
8
8
|
before :each do
|
9
|
-
@c = AMEE::Connection.new('
|
9
|
+
@c = AMEE::Connection.new('stage.amee.com', AMEE_V3_API_KEY, AMEE_V3_PASSWORD)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should have a connection to meta server" do
|
13
|
-
|
14
|
-
|
13
|
+
VCR.use_cassette("AMEE_Connection/v3/should have a connection to meta server") do
|
14
|
+
@c.authenticate.should_not be_nil
|
15
|
+
end
|
15
16
|
end
|
16
17
|
|
17
18
|
it "should login and know the path to the server" do
|
18
|
-
|
19
|
-
|
19
|
+
VCR.use_cassette("AMEE_Connection/v3/should login and know the path to the server") do
|
20
|
+
@c.authenticate.should_not be_nil
|
20
21
|
end
|
21
|
-
flexmock(Net::HTTP).should_receive(:new).with('platform-api-server.example.com', 80).once.and_return {
|
22
|
-
mock=flexmock
|
23
|
-
mock.should_receive(:start => nil)
|
24
|
-
mock.should_receive(:started? => true)
|
25
|
-
mock.should_receive(:request).and_return(flexmock(:code => '200', :body => "OK"))
|
26
|
-
mock.should_receive(:finish => nil)
|
27
|
-
mock
|
28
|
-
}
|
29
|
-
@c.v3_get("/#{AMEE::Connection.api_version}/categories/SomeCategory").should == "OK"
|
30
22
|
end
|
31
23
|
|
32
24
|
it "should be able to get from meta server" do
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
mock.should_receive(:finish => nil)
|
25
|
+
VCR.use_cassette("AMEE_Connection/v3/should be able to get from meta server") do
|
26
|
+
@get_request = @c.v3_get("/#{AMEE::Connection.api_version}/categories/Api_test")
|
27
|
+
@get_request.include?("<Status>OK</Status>").should be_true
|
37
28
|
end
|
38
|
-
@c.v3_get("/#{AMEE::Connection.api_version}/categories/SomeCategory").should == "OK"
|
39
29
|
end
|
40
30
|
|
41
31
|
it "should be able to handle failed gets from meta server" do
|
42
|
-
|
43
|
-
mock.should_receive(:start => nil)
|
44
|
-
mock.should_receive(:request).and_return(flexmock(:code => '404'))
|
45
|
-
mock.should_receive(:finish => nil)
|
46
|
-
end
|
32
|
+
VCR.use_cassette("AMEE_Connection/v3/should be able to handle failed gets from meta server") do
|
47
33
|
lambda {
|
48
34
|
@c.v3_get("/#{AMEE::Connection.api_version}/categories/SomeCategory").should == nil
|
49
35
|
}.should raise_error(AMEE::NotFound, "The URL was not found on the server.\nRequest: GET /#{AMEE::Connection.api_version}/categories/SomeCategory")
|
50
36
|
end
|
37
|
+
end
|
51
38
|
|
52
39
|
it "should be able to post to meta server" do
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
mock.should_receive(:finish => nil)
|
40
|
+
VCR.use_cassette("AMEE_Connection/v3/should be able to post to meta server") do
|
41
|
+
@post_request = @c.v3_post("/#{AMEE::Connection.api_version}/categories/039DCB9BA67D/items", {:'values.question' => Time.now.to_i, :returnobj => true})
|
42
|
+
@post_request.code.should == 201
|
57
43
|
end
|
58
|
-
@c.v3_put("/#{AMEE::Connection.api_version}/categories/SomeCategory", {:arg => "test"}).should == "OK"
|
59
44
|
end
|
60
45
|
|
61
|
-
it "should be able to handle failed
|
62
|
-
flexmock(Net::HTTP).new_instances do |mock|
|
63
|
-
mock.should_receive(:start => nil)
|
64
|
-
mock.should_receive(:request).and_return(flexmock(:code => '404'))
|
65
|
-
mock.should_receive(:finish => nil)
|
66
|
-
end
|
46
|
+
it "should be able to handle failed puts to meta server" do
|
67
47
|
lambda {
|
68
48
|
@c.v3_put("/#{AMEE::Connection.api_version}/categories/SomeCategory", {:arg => "test"}).should == "OK"
|
69
49
|
}.should raise_error
|
@@ -99,39 +79,50 @@ end
|
|
99
79
|
describe AMEE::Connection, "with retry enabled" do
|
100
80
|
|
101
81
|
before :each do
|
102
|
-
@c = AMEE::Connection.new('
|
82
|
+
@c = AMEE::Connection.new('stage.amee.com', AMEE_V3_API_KEY, AMEE_V3_PASSWORD, :retries => 2)
|
83
|
+
|
84
|
+
@timeout_response = {
|
85
|
+
:status => 408,
|
86
|
+
:body => "",
|
87
|
+
:time => 30
|
88
|
+
}
|
89
|
+
@successful_response = {
|
90
|
+
:status => 200,
|
91
|
+
:body => "",
|
92
|
+
:time => 30
|
93
|
+
}
|
94
|
+
|
103
95
|
end
|
104
96
|
|
105
97
|
[
|
106
|
-
|
107
|
-
Errno::EINVAL,
|
108
|
-
Errno::ECONNRESET,
|
109
|
-
EOFError,
|
110
|
-
Net::HTTPBadResponse,
|
111
|
-
Net::HTTPHeaderSyntaxError,
|
112
|
-
Net::ProtocolError
|
98
|
+
AMEE::TimeOut
|
113
99
|
].each do |e|
|
114
100
|
|
115
101
|
it "should retry after #{e.name} the correct number of times" do
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
mock.should_receive(:request).and_return(flexmock(:code => '200', :body => '{}')).once
|
120
|
-
mock.should_receive(:finish => nil)
|
102
|
+
|
103
|
+
VCR.use_cassette("AMEE_Connection/v3/retries/#{e.name}") do
|
104
|
+
@c.authenticate
|
121
105
|
end
|
106
|
+
|
107
|
+
stub_request(:any, /.*#{AMEE::Connection.api_version}\/categories\/Api_test.*/).
|
108
|
+
to_return(@timeout_response).times(2).
|
109
|
+
then.to_return(@successful_response)
|
122
110
|
lambda {
|
123
|
-
@c.v3_get("/#{AMEE::Connection.api_version}/categories/
|
111
|
+
@c.v3_get("/#{AMEE::Connection.api_version}/categories/Api_test")
|
124
112
|
}.should_not raise_error
|
125
113
|
end
|
126
114
|
|
127
115
|
it "should retry #{e.name} the correct number of times and raise error on failure" do
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
mock.should_receive(:finish => nil)
|
116
|
+
|
117
|
+
VCR.use_cassette("AMEE_Connection/v3/retries/#{e.name}") do
|
118
|
+
@c.authenticate
|
132
119
|
end
|
120
|
+
|
121
|
+
stub_request(:any, /.*#{AMEE::Connection.api_version}\/categories\/Api_test.*/).
|
122
|
+
to_return(@timeout_response).times(3)
|
123
|
+
|
133
124
|
lambda {
|
134
|
-
@c.v3_get("/#{AMEE::Connection.api_version}/categories/
|
125
|
+
@c.v3_get("/#{AMEE::Connection.api_version}/categories/Api_test")
|
135
126
|
}.should raise_error(e)
|
136
127
|
end
|
137
128
|
end
|
@@ -143,25 +134,46 @@ describe AMEE::Connection, "with retry enabled" do
|
|
143
134
|
].each do |e|
|
144
135
|
|
145
136
|
it "should retry after #{e} the correct number of times" do
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
137
|
+
|
138
|
+
@successful_response = {
|
139
|
+
:status => 200,
|
140
|
+
:body => "",
|
141
|
+
:time => 30
|
142
|
+
}
|
143
|
+
|
144
|
+
@error_response = {
|
145
|
+
:status => e.to_i,
|
146
|
+
:body => "",
|
147
|
+
}
|
148
|
+
|
149
|
+
VCR.use_cassette("AMEE_Connection/v3/retries/#{e}") do
|
150
|
+
@c.authenticate
|
151
151
|
end
|
152
|
+
|
153
|
+
stub_request(:any, /.*#{AMEE::Connection.api_version}\/categories\/Api_test.*/).
|
154
|
+
to_return(@error_response).times(2).
|
155
|
+
then.to_return(@successful_response)
|
152
156
|
lambda {
|
153
|
-
@c.v3_get("/#{AMEE::Connection.api_version}/categories/
|
157
|
+
@c.v3_get("/#{AMEE::Connection.api_version}/categories/Api_test")
|
154
158
|
}.should_not raise_error
|
155
159
|
end
|
156
160
|
|
157
161
|
it "should retry #{e} the correct number of times and raise error on failure" do
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
+
|
163
|
+
@error_response = {
|
164
|
+
:status => e.to_i,
|
165
|
+
:body => "",
|
166
|
+
}
|
167
|
+
|
168
|
+
VCR.use_cassette("AMEE_Connection/v3/retries/#{e}") do
|
169
|
+
@c.authenticate
|
162
170
|
end
|
171
|
+
|
172
|
+
stub_request(:any, /.*#{AMEE::Connection.api_version}\/categories\/Api_test.*/).
|
173
|
+
to_return(@error_response).times(3)
|
174
|
+
|
163
175
|
lambda {
|
164
|
-
@c.v3_get("/#{AMEE::Connection.api_version}/categories/
|
176
|
+
@c.v3_get("/#{AMEE::Connection.api_version}/categories/Api_test")
|
165
177
|
}.should raise_error(AMEE::ConnectionFailed)
|
166
178
|
end
|
167
179
|
end
|
@@ -20,6 +20,7 @@ describe AMEE::Admin::ItemValueDefinition, "with an authenticated XML connection
|
|
20
20
|
HERE
|
21
21
|
).once
|
22
22
|
@connection.should_receive(:v3_put).with("/#{AMEE::Connection.api_version}/definitions/PQR/values/ABC;wikiDoc;usages",
|
23
|
+
:content_type => :xml,
|
23
24
|
:body => <<EOF
|
24
25
|
#{XMLPreamble}
|
25
26
|
<ItemValueDefinition>
|
@@ -55,7 +55,7 @@ describe AMEE::Admin::ReturnValueDefinition, "with an authenticated XML connecti
|
|
55
55
|
with("/#{AMEE::Connection.api_version}/definitions/#{Testcativduid}/returnvalues",
|
56
56
|
{:type=>"CO2", :valueDefinition=>"45433E48B39F",
|
57
57
|
:returnobj=>true, :unit=>"kg", :perUnit=>"month"}).
|
58
|
-
and_return({'Location'=>"///#{AMEE::Connection.api_version}/definitions/#{Testcativduid}/returnvalues/#{Testrvduid}"}).once
|
58
|
+
and_return(flexmock(:headers_hash => {'Location'=>"///#{AMEE::Connection.api_version}/definitions/#{Testcativduid}/returnvalues/#{Testrvduid}"})).once
|
59
59
|
rvd=AMEE::Admin::ReturnValueDefinition.create(connection,Testcativduid,
|
60
60
|
:type=>'CO2',:unit=>'kg',:perUnit=>'month')
|
61
61
|
|