amee 2.7.0 → 3.0.1
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 → CHANGELOG.txt} +11 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +27 -0
- data/{README → README.txt} +6 -4
- data/Rakefile +84 -17
- data/VERSION +1 -1
- data/amee.gemspec +172 -0
- data/bin/ameesh +3 -0
- data/examples/create_profile.rb +3 -0
- data/examples/create_profile_item.rb +3 -0
- data/examples/list_profiles.rb +3 -0
- data/examples/view_data_category.rb +3 -0
- data/examples/view_data_item.rb +3 -0
- data/examples/view_profile_item.rb +3 -0
- data/init.rb +3 -0
- data/lib/amee/collection.rb +3 -0
- data/lib/amee/connection.rb +3 -0
- data/lib/amee/data_category.rb +3 -0
- data/lib/amee/data_item.rb +3 -0
- data/lib/amee/data_item_value.rb +3 -0
- data/lib/amee/data_item_value_history.rb +3 -0
- data/lib/amee/data_object.rb +3 -0
- data/lib/amee/drill_down.rb +3 -0
- data/lib/amee/exceptions.rb +3 -0
- data/lib/amee/item_definition.rb +3 -0
- data/lib/amee/item_value_definition.rb +3 -0
- data/lib/amee/logger.rb +3 -0
- data/lib/amee/object.rb +3 -0
- data/lib/amee/pager.rb +3 -0
- data/lib/amee/parse_helper.rb +3 -0
- data/lib/amee/profile.rb +3 -0
- data/lib/amee/profile_category.rb +3 -0
- data/lib/amee/profile_item.rb +3 -0
- data/lib/amee/profile_item_value.rb +3 -0
- data/lib/amee/profile_object.rb +3 -0
- data/lib/amee/rails.rb +3 -0
- data/lib/amee/shell.rb +3 -0
- data/lib/amee/user.rb +3 -0
- data/lib/amee/v3/collection.rb +61 -0
- data/lib/amee/v3/connection.rb +99 -0
- data/lib/amee/v3/item_definition.rb +73 -0
- data/lib/amee/v3/item_value_definition.rb +99 -0
- data/lib/amee/v3/item_value_definition_list.rb +53 -0
- data/lib/amee/v3/meta_helper.rb +28 -0
- data/lib/amee/v3/return_value_definition.rb +202 -0
- data/lib/amee/v3.rb +12 -0
- data/lib/amee.rb +4 -0
- data/rails/init.rb +3 -0
- data/spec/amee_spec.rb +3 -0
- data/spec/cache_spec.rb +3 -0
- data/spec/connection_spec.rb +3 -0
- data/spec/data_category_spec.rb +4 -1
- data/spec/data_item_spec.rb +3 -0
- data/spec/data_item_value_history_spec.rb +3 -0
- data/spec/data_item_value_spec.rb +3 -0
- data/spec/data_object_spec.rb +3 -0
- data/spec/drill_down_spec.rb +3 -0
- data/spec/fixtures/BD88D30D1214.xml +1 -0
- data/spec/fixtures/empty_return_value_definition_list.xml +6 -0
- data/spec/fixtures/itemdef.xml +20 -0
- data/spec/fixtures/itemdef_441BF4BEA15B.xml +14 -0
- data/spec/fixtures/itemdef_no_usages.xml +10 -0
- data/spec/fixtures/itemdef_one_usage.xml +14 -0
- data/spec/fixtures/ivdlist.xml +605 -0
- data/spec/fixtures/ivdlist_BD88D30D1214.xml +1 -0
- data/spec/fixtures/return_value_definition.xml +18 -0
- data/spec/fixtures/return_value_definition_list.xml +46 -0
- data/spec/item_definition_spec.rb +12 -9
- data/spec/item_value_definition_spec.rb +29 -19
- data/spec/logger_spec.rb +2 -2
- data/spec/object_spec.rb +3 -0
- data/spec/parse_helper_spec.rb +3 -0
- data/spec/profile_category_spec.rb +3 -0
- data/spec/profile_item_spec.rb +3 -0
- data/spec/profile_item_value_spec.rb +3 -0
- data/spec/profile_object_spec.rb +3 -0
- data/spec/profile_spec.rb +3 -0
- data/spec/rails_spec.rb +3 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/user_spec.rb +3 -0
- data/spec/v3/connection_spec.rb +169 -0
- data/spec/v3/item_definition_spec.rb +328 -0
- data/spec/v3/item_value_definition_spec.rb +116 -0
- data/spec/v3/return_value_definition_spec.rb +90 -0
- metadata +38 -10
- data/COPYING +0 -19
@@ -0,0 +1,328 @@
|
|
1
|
+
# Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
|
2
|
+
# Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
5
|
+
|
6
|
+
describe AMEE::Admin::ItemDefinition do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@item_definition = AMEE::Admin::ItemDefinition.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should provide a usages array" do
|
13
|
+
@item_definition.usages.should == []
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
describe AMEE::Admin::ItemDefinition, "with an authenticated v3 connection" do
|
19
|
+
|
20
|
+
it "should parse XML correctly" do
|
21
|
+
connection = flexmock "connection"
|
22
|
+
connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E;full", {}).and_return(fixture('itemdef.xml'))
|
23
|
+
@data = AMEE::Admin::ItemDefinition.load(connection,"472D78F6584E")
|
24
|
+
@data.uid.should == "472D78F6584E"
|
25
|
+
@data.created.should == DateTime.new(2009,8,31,12,41,18)
|
26
|
+
@data.modified.should == DateTime.new(2010,8,13,14,54,33)
|
27
|
+
@data.name.should == "Power Stations And Stuff"
|
28
|
+
@data.drill_downs.should == %w{state county metroArea city zipCode plantName powWowWow}
|
29
|
+
@data.usages.should == ['usageOne', 'usageThree', 'usageOther']
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should parse XML correctly if there are no usages" do
|
33
|
+
connection = flexmock "connection"
|
34
|
+
connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E;full", {}).and_return(fixture('itemdef_no_usages.xml'))
|
35
|
+
@data = AMEE::Admin::ItemDefinition.load(connection,"472D78F6584E")
|
36
|
+
@data.usages.should == []
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should parse XML correctly if there is just one usage" do
|
40
|
+
connection = flexmock "connection"
|
41
|
+
connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E;full", {}).and_return(fixture('itemdef_one_usage.xml'))
|
42
|
+
@data = AMEE::Admin::ItemDefinition.load(connection,"472D78F6584E")
|
43
|
+
@data.usages.should == ['usageOne']
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should be able to load an item value definition list" do
|
47
|
+
connection = flexmock "connection"
|
48
|
+
connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E;full", {}).and_return(fixture('itemdef.xml')).once
|
49
|
+
connection.should_receive(:retries).and_return(0).once
|
50
|
+
connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E/values;full", {:resultStart => 0, :resultLimit => 10}).and_return(fixture('ivdlist.xml')).once
|
51
|
+
@data = AMEE::Admin::ItemDefinition.load(connection,"472D78F6584E")
|
52
|
+
@data.uid.should == "472D78F6584E"
|
53
|
+
@list=@data.item_value_definition_list
|
54
|
+
@list.length.should==29
|
55
|
+
@list.first.uid.should=='C531CA64DD72'
|
56
|
+
@list.first.name.should eql 'Past carbon intensity'
|
57
|
+
@list.first.path.should eql 'pastIntensity'
|
58
|
+
@list.first.meta.wikidoc.should eql 'wikidoc'
|
59
|
+
@list.first.valuetype.should eql 'DECIMAL'
|
60
|
+
@list.first.compulsory?('usageOne').should be_true
|
61
|
+
@list.first.forbidden?('usageTwo').should be_true
|
62
|
+
@list.first.default.should eql 42.0
|
63
|
+
@list.first.choices.should eql ['foo','bar']
|
64
|
+
@list.first.unit.should == 'kg'
|
65
|
+
@list.first.perunit.should == 'MWh'
|
66
|
+
@list.first.profile?.should be_false
|
67
|
+
@list.first.drill?.should be_false
|
68
|
+
@list.first.data?.should be_true
|
69
|
+
@list.first.versions.should == ['1.0', '2.0']
|
70
|
+
@list.second.versions.should == ['2.0']
|
71
|
+
@list.second.optional?('usageOne').should be_true
|
72
|
+
@list.second.ignored?('usageTwo').should be_true
|
73
|
+
@list.second.default.should be_nil
|
74
|
+
@list.last.uid.should=='2B0A0E540D4C'
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should fail gracefully with incorrect data" do
|
78
|
+
connection = flexmock "connection"
|
79
|
+
xml = '<?xml version="1.0" encoding="UTF-8"?><Resources>'
|
80
|
+
connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E;full", {}).and_return(xml)
|
81
|
+
lambda{AMEE::Admin::ItemDefinition.load(connection, "472D78F6584E")}.should raise_error(AMEE::BadData)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should fail gracefully on other errors" do
|
85
|
+
connection = flexmock "connection"
|
86
|
+
connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E;full", {}).and_raise("unidentified error")
|
87
|
+
lambda{AMEE::Admin::ItemDefinition.load(connection, "472D78F6584E")}.should raise_error(AMEE::BadData)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should support updating" do
|
91
|
+
connection = flexmock "connection"
|
92
|
+
connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E;full", {}).and_return('<?xml version="1.0" encoding="UTF-8" standalone="no"?><Representation><ItemDefinition created="2009-08-31T12:41:18Z" modified="2010-08-13T14:54:33Z" status="ACTIVE" uid="472D78F6584E"><Name>Power Stations And Stuff</Name><DrillDown>state,county,metroArea,city,zipCode,plantName,powWowWow</DrillDown><Usages><Usage present="true"><Name>usageOne</Name></Usage><Usage present="true"><Name>usageThree</Name></Usage><Usage present="false"><Name>usageOther</Name></Usage></Usages></ItemDefinition><Status>OK</Status><Version>#{AMEE_API_VERSION}.0</Version></Representation>').once
|
93
|
+
connection.should_receive(:v3_put).with("/#{AMEE_API_VERSION}/definitions/472D78F6584E", :usages => 'usageOther,usageThree,usageOne', :name => 'Power Stations And Stuff').once
|
94
|
+
@data = AMEE::Admin::ItemDefinition.load(connection,"472D78F6584E")
|
95
|
+
@data.usages.should == ['usageOne', 'usageThree', 'usageOther']
|
96
|
+
@data.usages.reverse!
|
97
|
+
@data.save!
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
# Following is copied here to make sure that v2 list fetch still work when v3 stuff is added.
|
103
|
+
# Copied wholesale from v2 version
|
104
|
+
|
105
|
+
DefinitionsListResponse=<<HERE
|
106
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
107
|
+
<Resources>
|
108
|
+
<ItemDefinitionsResource>
|
109
|
+
<ItemDefinitions>
|
110
|
+
<ItemDefinition uid="2169991DE821">
|
111
|
+
<Name>AAA Car Generic</Name>
|
112
|
+
<DrillDown>fuel,size</DrillDown>
|
113
|
+
</ItemDefinition>
|
114
|
+
<ItemDefinition uid="18CB59F9EC2D">
|
115
|
+
<Name>AAA Units test</Name>
|
116
|
+
<DrillDown>type</DrillDown>
|
117
|
+
</ItemDefinition>
|
118
|
+
<ItemDefinition uid="76C56F7DF49A">
|
119
|
+
<Name>AAAA1234Test</Name>
|
120
|
+
<DrillDown/>
|
121
|
+
</ItemDefinition>
|
122
|
+
<ItemDefinition uid="CF344E20E9AC">
|
123
|
+
<Name>AAATipTest</Name>
|
124
|
+
<DrillDown>question</DrillDown>
|
125
|
+
</ItemDefinition>
|
126
|
+
<ItemDefinition uid="70BCD634D0A4">
|
127
|
+
<Name>ActOnCO2 Action</Name>
|
128
|
+
<DrillDown>type</DrillDown></ItemDefinition>
|
129
|
+
<ItemDefinition uid="62058B6FD778">
|
130
|
+
<Name>ActOnCO2 Metadata</Name>
|
131
|
+
<DrillDown>type</DrillDown>
|
132
|
+
</ItemDefinition>
|
133
|
+
<ItemDefinition uid="D3351CDC11C8">
|
134
|
+
<Name>ADigTest</Name>
|
135
|
+
<DrillDown/></ItemDefinition>
|
136
|
+
<ItemDefinition uid="A02807E44CA3">
|
137
|
+
<Name>Adipic Acid N2O emissions</Name>
|
138
|
+
<DrillDown>abatementTechnology</DrillDown>
|
139
|
+
</ItemDefinition>
|
140
|
+
<ItemDefinition uid="B910141B00DB">
|
141
|
+
<Name>AJC ID TEST</Name>
|
142
|
+
<DrillDown>type</DrillDown>
|
143
|
+
</ItemDefinition>
|
144
|
+
<ItemDefinition uid="4660BD4FCF97">
|
145
|
+
<Name>Aluminium Production: Alternative (no anode data)</Name>
|
146
|
+
<DrillDown>type</DrillDown>
|
147
|
+
</ItemDefinition></ItemDefinitions>
|
148
|
+
<Pager>
|
149
|
+
<Start>0</Start>
|
150
|
+
<From>1</From>
|
151
|
+
<To>10</To>
|
152
|
+
<Items>10</Items>
|
153
|
+
<CurrentPage>1</CurrentPage>
|
154
|
+
<RequestedPage>1</RequestedPage>
|
155
|
+
<NextPage>-1</NextPage>
|
156
|
+
<PreviousPage>-1</PreviousPage>
|
157
|
+
<LastPage>1</LastPage>
|
158
|
+
<ItemsPerPage>10</ItemsPerPage>
|
159
|
+
<ItemsFound>10</ItemsFound>
|
160
|
+
</Pager>
|
161
|
+
</ItemDefinitionsResource>
|
162
|
+
</Resources>
|
163
|
+
HERE
|
164
|
+
|
165
|
+
DefinitionsListResponsePage1=<<HERE
|
166
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
167
|
+
<Resources>
|
168
|
+
<ItemDefinitionsResource>
|
169
|
+
<ItemDefinitions>
|
170
|
+
<ItemDefinition uid="2169991DE821">
|
171
|
+
<Name>AAA Car Generic</Name>
|
172
|
+
<DrillDown>fuel,size</DrillDown>
|
173
|
+
</ItemDefinition>
|
174
|
+
<ItemDefinition uid="18CB59F9EC2D">
|
175
|
+
<Name>AAA Units test</Name>
|
176
|
+
<DrillDown>type</DrillDown>
|
177
|
+
</ItemDefinition>
|
178
|
+
<ItemDefinition uid="76C56F7DF49A">
|
179
|
+
<Name>AAAA1234Test</Name>
|
180
|
+
<DrillDown/>
|
181
|
+
</ItemDefinition>
|
182
|
+
<ItemDefinition uid="CF344E20E9AC">
|
183
|
+
<Name>AAATipTest</Name>
|
184
|
+
<DrillDown>question</DrillDown>
|
185
|
+
</ItemDefinition></ItemDefinitions>
|
186
|
+
<Pager>
|
187
|
+
<Start>0</Start>
|
188
|
+
<From>1</From>
|
189
|
+
<To>4</To>
|
190
|
+
<Items>10</Items>
|
191
|
+
<CurrentPage>1</CurrentPage>
|
192
|
+
<RequestedPage>1</RequestedPage>
|
193
|
+
<NextPage>2</NextPage>
|
194
|
+
<PreviousPage>-1</PreviousPage>
|
195
|
+
<LastPage>3</LastPage>
|
196
|
+
<ItemsPerPage>4</ItemsPerPage>
|
197
|
+
<ItemsFound>4</ItemsFound>
|
198
|
+
</Pager>
|
199
|
+
</ItemDefinitionsResource>
|
200
|
+
</Resources>
|
201
|
+
HERE
|
202
|
+
DefinitionsListResponsePage2=<<HERE
|
203
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
204
|
+
<Resources>
|
205
|
+
<ItemDefinitionsResource>
|
206
|
+
<ItemDefinitions>
|
207
|
+
<ItemDefinition uid="70BCD634D0A4">
|
208
|
+
<Name>ActOnCO2 Action</Name>
|
209
|
+
<DrillDown>type</DrillDown></ItemDefinition>
|
210
|
+
<ItemDefinition uid="62058B6FD778">
|
211
|
+
<Name>ActOnCO2 Metadata</Name>
|
212
|
+
<DrillDown>type</DrillDown>
|
213
|
+
</ItemDefinition>
|
214
|
+
<ItemDefinition uid="D3351CDC11C8">
|
215
|
+
<Name>ADigTest</Name>
|
216
|
+
<DrillDown/></ItemDefinition>
|
217
|
+
<ItemDefinition uid="A02807E44CA3">
|
218
|
+
<Name>Adipic Acid N2O emissions</Name>
|
219
|
+
<DrillDown>abatementTechnology</DrillDown>
|
220
|
+
</ItemDefinition></ItemDefinitions>
|
221
|
+
<Pager>
|
222
|
+
<Start>4</Start>
|
223
|
+
<From>5</From>
|
224
|
+
<To>8</To>
|
225
|
+
<Items>10</Items>
|
226
|
+
<CurrentPage>2</CurrentPage>
|
227
|
+
<RequestedPage>2</RequestedPage>
|
228
|
+
<NextPage>3</NextPage>
|
229
|
+
<PreviousPage>1</PreviousPage>
|
230
|
+
<LastPage>3</LastPage>
|
231
|
+
<ItemsPerPage>4</ItemsPerPage>
|
232
|
+
<ItemsFound>4</ItemsFound>
|
233
|
+
</Pager>
|
234
|
+
</ItemDefinitionsResource>
|
235
|
+
</Resources>
|
236
|
+
HERE
|
237
|
+
DefinitionsListResponsePage3=<<HERE
|
238
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
239
|
+
<Resources>
|
240
|
+
<ItemDefinitionsResource>
|
241
|
+
<ItemDefinitions>
|
242
|
+
<ItemDefinition uid="B910141B00DB">
|
243
|
+
<Name>AJC ID TEST</Name>
|
244
|
+
<DrillDown>type</DrillDown>
|
245
|
+
</ItemDefinition>
|
246
|
+
<ItemDefinition uid="4660BD4FCF97">
|
247
|
+
<Name>Aluminium Production: Alternative (no anode data)</Name>
|
248
|
+
<DrillDown>type</DrillDown>
|
249
|
+
</ItemDefinition>
|
250
|
+
</ItemDefinitions>
|
251
|
+
<Pager>
|
252
|
+
<Start>8</Start>
|
253
|
+
<From>9</From>
|
254
|
+
<To>10</To>
|
255
|
+
<Items>10</Items>
|
256
|
+
<CurrentPage>3</CurrentPage>
|
257
|
+
<RequestedPage>3</RequestedPage>
|
258
|
+
<NextPage>-1</NextPage>
|
259
|
+
<PreviousPage>2</PreviousPage>
|
260
|
+
<LastPage>3</LastPage>
|
261
|
+
<ItemsPerPage>4</ItemsPerPage>
|
262
|
+
<ItemsFound>2</ItemsFound>
|
263
|
+
</Pager>
|
264
|
+
</ItemDefinitionsResource>
|
265
|
+
</Resources>
|
266
|
+
HERE
|
267
|
+
|
268
|
+
describe AMEE::Admin::ItemDefinitionList do
|
269
|
+
it "Should parse a single page" do
|
270
|
+
connection = flexmock "connection"
|
271
|
+
connection.should_receive(:retries).and_return(0).once
|
272
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions",{}).once.
|
273
|
+
and_return flexmock(:body =>DefinitionsListResponse)
|
274
|
+
@list=AMEE::Admin::ItemDefinitionList.new(connection)
|
275
|
+
@list.first.should be_a AMEE::Admin::ItemDefinition
|
276
|
+
@list.first.uid.should == "2169991DE821"
|
277
|
+
@list.first.name.should == "AAA Car Generic"
|
278
|
+
@list.size.should==10
|
279
|
+
end
|
280
|
+
|
281
|
+
it "Should retry on parse failures" do
|
282
|
+
connection = flexmock "connection"
|
283
|
+
connection.should_receive(:retries).and_return(2).once
|
284
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions",{}).twice.
|
285
|
+
and_return flexmock(:body =>DefinitionsListResponse.first(12))
|
286
|
+
connection.should_receive(:expire).with("/definitions/itemDefinitions").twice
|
287
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions",{}).once.
|
288
|
+
and_return flexmock(:body =>DefinitionsListResponse)
|
289
|
+
@list=AMEE::Admin::ItemDefinitionList.new(connection)
|
290
|
+
@list.first.should be_a AMEE::Admin::ItemDefinition
|
291
|
+
@list.first.uid.should == "2169991DE821"
|
292
|
+
@list.first.name.should == "AAA Car Generic"
|
293
|
+
@list.size.should==10
|
294
|
+
end
|
295
|
+
|
296
|
+
it "Should retry on parse failures and bubble up failure if never successful" do
|
297
|
+
connection = flexmock "connection"
|
298
|
+
connection.should_receive(:retries).and_return(2).once
|
299
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions",{}).times(3).
|
300
|
+
and_return flexmock(:body =>DefinitionsListResponse.first(12))
|
301
|
+
connection.should_receive(:expire).with("/definitions/itemDefinitions").times(3)
|
302
|
+
lambda {
|
303
|
+
AMEE::Admin::ItemDefinitionList.new(connection)
|
304
|
+
}.should raise_error(Nokogiri::XML::SyntaxError)
|
305
|
+
end
|
306
|
+
|
307
|
+
it "Should parse multiple pages" do
|
308
|
+
connection = flexmock "connection"
|
309
|
+
connection.should_receive(:retries).and_return(0).times(3)
|
310
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions",{}).
|
311
|
+
once.
|
312
|
+
and_return flexmock(:body =>DefinitionsListResponsePage1)
|
313
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions",
|
314
|
+
{:page=>2}).once.
|
315
|
+
and_return flexmock(:body =>DefinitionsListResponsePage2)
|
316
|
+
connection.should_receive(:get).with("/definitions/itemDefinitions",
|
317
|
+
{:page=>3}).once.
|
318
|
+
and_return flexmock(:body =>DefinitionsListResponsePage3)
|
319
|
+
@list=AMEE::Admin::ItemDefinitionList.new(connection)
|
320
|
+
@list.first.should be_a AMEE::Admin::ItemDefinition
|
321
|
+
@list.first.uid.should == "2169991DE821"
|
322
|
+
@list.first.name.should == "AAA Car Generic"
|
323
|
+
@list[4].should be_a AMEE::Admin::ItemDefinition
|
324
|
+
@list[4].uid.should == "70BCD634D0A4"
|
325
|
+
@list[4].name.should == "ActOnCO2 Action"
|
326
|
+
@list.size.should==10
|
327
|
+
end
|
328
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
|
2
|
+
# Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
5
|
+
|
6
|
+
describe AMEE::Admin::ItemValueDefinition, "with an authenticated XML connection" do
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
@connection = flexmock "connection"
|
10
|
+
@ivd=AMEE::Admin::ItemValueDefinition.new(:connection=> @connection,
|
11
|
+
:uid=>'ABC',:itemdefuid=>'PQR')
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should set metadata" do
|
15
|
+
@connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/PQR/values/ABC;wikiDoc;usages").
|
16
|
+
and_return(<<HERE
|
17
|
+
#{XMLPreamble}
|
18
|
+
<Representation>
|
19
|
+
</Representation>
|
20
|
+
HERE
|
21
|
+
).once
|
22
|
+
@connection.should_receive(:v3_put).with("/#{AMEE_API_VERSION}/definitions/PQR/values/ABC;wikiDoc;usages",
|
23
|
+
:body => <<EOF
|
24
|
+
#{XMLPreamble}
|
25
|
+
<ItemValueDefinition>
|
26
|
+
<WikiDoc>Mass of carbon per distance</WikiDoc>
|
27
|
+
<Usages>
|
28
|
+
<Usage>
|
29
|
+
<Name>usageTwo</Name>
|
30
|
+
<Type>IGNORED</Type>
|
31
|
+
</Usage>
|
32
|
+
<Usage>
|
33
|
+
<Name>usageOne</Name>
|
34
|
+
<Type>FORBIDDEN</Type>
|
35
|
+
</Usage>
|
36
|
+
</Usages>
|
37
|
+
</ItemValueDefinition>
|
38
|
+
EOF
|
39
|
+
).once
|
40
|
+
@connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/PQR/values/ABC;wikiDoc;usages").
|
41
|
+
and_return(<<HERE
|
42
|
+
#{XMLPreamble}
|
43
|
+
<Representation>
|
44
|
+
</Representation>
|
45
|
+
HERE
|
46
|
+
).once
|
47
|
+
@ivd.meta.wikidoc = "Mass of carbon per distance"
|
48
|
+
@ivd.set_usage_type('usageOne', :forbidden)
|
49
|
+
@ivd.set_usage_type('usageTwo', :ignored)
|
50
|
+
@ivd.putmeta
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should get metadata" do
|
54
|
+
@connection.should_receive(:v3_get).with("/#{AMEE_API_VERSION}/definitions/PQR/values/ABC;wikiDoc;usages").
|
55
|
+
and_return(<<HERE
|
56
|
+
#{XMLPreamble}
|
57
|
+
<Representation>
|
58
|
+
<ItemValueDefinition>
|
59
|
+
<Name>Test</Name>
|
60
|
+
<Path>test</Path>
|
61
|
+
<Value>42</Value>
|
62
|
+
<WikiDoc>Mass of carbon per distance</WikiDoc>
|
63
|
+
<ItemDefinition uid="PQR">
|
64
|
+
<Name>Itemdef</Name>
|
65
|
+
</ItemDefinition>
|
66
|
+
<Usages>
|
67
|
+
<Usage>
|
68
|
+
<Name>usageTwo</Name>
|
69
|
+
<Type>FORBIDDEN</Type>
|
70
|
+
</Usage>
|
71
|
+
<Usage>
|
72
|
+
<Name>usageThree</Name>
|
73
|
+
<Type>IGNORED</Type>
|
74
|
+
</Usage>
|
75
|
+
<Usage>
|
76
|
+
<Name>usageFour</Name>
|
77
|
+
<Type>OPTIONAL</Type>
|
78
|
+
</Usage>
|
79
|
+
<Usage>
|
80
|
+
<Name>usageOne</Name>
|
81
|
+
<Type>COMPULSORY</Type>
|
82
|
+
</Usage>
|
83
|
+
</Usages>
|
84
|
+
<Choices>true=true,false=false</Choices>
|
85
|
+
<DrillDown>false</DrillDown>
|
86
|
+
<FromData>true</FromData>
|
87
|
+
<FromProfile>false</FromProfile>
|
88
|
+
</ItemValueDefinition>
|
89
|
+
<Status>OK</Status>
|
90
|
+
<Version>#{AMEE_API_VERSION}.0</Version>
|
91
|
+
</Representation>
|
92
|
+
HERE
|
93
|
+
).once
|
94
|
+
# @ivd.name.should eql "Test"
|
95
|
+
# @ivd.path.should eql "test"
|
96
|
+
# @ivd.default.should eql 42
|
97
|
+
@ivd.meta.wikidoc.should eql "Mass of carbon per distance"
|
98
|
+
result_map = {
|
99
|
+
'usageOne' => :compulsory,
|
100
|
+
'usageTwo' => :forbidden,
|
101
|
+
'usageThree' => :ignored,
|
102
|
+
'usageFour' => :optional,
|
103
|
+
}
|
104
|
+
types = [:optional, :compulsory, :forbidden, :ignored]
|
105
|
+
result_map.each_pair do |usage, type|
|
106
|
+
@ivd.usage_type(usage).should eql type
|
107
|
+
types.each do |test_type|
|
108
|
+
@ivd.send("#{test_type.to_s}?", usage).should eql(test_type == type)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
@ivd.usage_type('unknownUsage').should == :optional
|
112
|
+
# @ivd.choices.should == ['true', 'false']
|
113
|
+
# @ivd.type.should == 'data'
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
|
2
|
+
# Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
5
|
+
Testcativduid="5648C049F599"
|
6
|
+
Testrvduid="C21026DD57C5"
|
7
|
+
describe AMEE::Admin::ReturnValueDefinition, "with an authenticated XML connection" do
|
8
|
+
|
9
|
+
# # find UID for test/jh/ameem/preexistent
|
10
|
+
# it "should work" do
|
11
|
+
# connection=AMEE::Connection.new('platform-science.amee.com','admin','r41n80w')
|
12
|
+
# testcativduid="#{Testcativduid}"
|
13
|
+
# # get the current list of RVDs
|
14
|
+
# list=AMEE::Admin::ReturnValueDefinitionList.new(connection,testcativduid)
|
15
|
+
# pp list
|
16
|
+
# # add an RVD
|
17
|
+
# AMEE::Admin::ReturnValueDefinition.create(connection,testcativduid,
|
18
|
+
# :type=>'CO2',:unit=>'kg',:perUnit=>'month',:valueDefinition=>'45433E48B39F')
|
19
|
+
# # re-get the list of RVDs
|
20
|
+
# list=AMEE::Admin::ReturnValueDefinitionList.new(connection,testcativduid)
|
21
|
+
# pp list
|
22
|
+
# # delete the RVDs
|
23
|
+
# list.each do |rvd|
|
24
|
+
# AMEE::Admin::ReturnValueDefinition.delete(connection,testcativduid,rvd)
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
it "should index a list of return value definitions" do
|
31
|
+
connection = flexmock "connection"
|
32
|
+
connection.should_receive(:retries).and_return(0).once
|
33
|
+
connection.should_receive(:v3_get).
|
34
|
+
with("/#{AMEE_API_VERSION}/definitions/#{Testcativduid}/returnvalues;full", {:resultLimit=>10, :resultStart=>0}).
|
35
|
+
and_return(fixture('return_value_definition_list.xml')).once
|
36
|
+
list=AMEE::Admin::ReturnValueDefinitionList.new(connection,Testcativduid)
|
37
|
+
list.should have(3).items
|
38
|
+
end
|
39
|
+
it "should return an empty list when there are no return value definitions" do
|
40
|
+
connection = flexmock "connection"
|
41
|
+
connection.should_receive(:retries).and_return(0).once
|
42
|
+
connection.should_receive(:v3_get).
|
43
|
+
with("/#{AMEE_API_VERSION}/definitions/#{Testcativduid}/returnvalues;full", {:resultLimit=>10, :resultStart=>0}).
|
44
|
+
and_return(fixture('empty_return_value_definition_list.xml')).once
|
45
|
+
list=AMEE::Admin::ReturnValueDefinitionList.new(connection,Testcativduid)
|
46
|
+
list.should have(0).items
|
47
|
+
end
|
48
|
+
it "should create a return value definition" do
|
49
|
+
connection = flexmock "connection"
|
50
|
+
connection.should_receive(:v3_get).
|
51
|
+
with("/#{AMEE_API_VERSION}/definitions/#{Testcativduid}/returnvalues/#{Testrvduid};full", {}).
|
52
|
+
and_return(fixture('return_value_definition.xml')).once
|
53
|
+
connection.should_receive(:v3_post).
|
54
|
+
with("/#{AMEE_API_VERSION}/definitions/#{Testcativduid}/returnvalues",
|
55
|
+
{:type=>"CO2", :valueDefinition=>"45433E48B39F",
|
56
|
+
:returnobj=>true, :unit=>"kg", :perUnit=>"month"}).
|
57
|
+
and_return({'Location'=>"///#{AMEE_API_VERSION}/definitions/#{Testcativduid}/returnvalues/#{Testrvduid}"}).once
|
58
|
+
rvd=AMEE::Admin::ReturnValueDefinition.create(connection,Testcativduid,
|
59
|
+
:type=>'CO2',:unit=>'kg',:perUnit=>'month')
|
60
|
+
|
61
|
+
rvd.uid.should eql Testrvduid
|
62
|
+
rvd.unit.should eql 'kg'
|
63
|
+
rvd.perunit.should eql 'month'
|
64
|
+
rvd.type.should eql 'CO2'
|
65
|
+
end
|
66
|
+
it "should read a return value definition" do
|
67
|
+
connection = flexmock "connection"
|
68
|
+
connection.should_receive(:v3_get).
|
69
|
+
with("/#{AMEE_API_VERSION}/definitions/#{Testcativduid}/returnvalues/#{Testrvduid};full", {}).
|
70
|
+
and_return(fixture('return_value_definition.xml')).once
|
71
|
+
rvd=AMEE::Admin::ReturnValueDefinition.load(connection,Testcativduid,Testrvduid)
|
72
|
+
|
73
|
+
rvd.uid.should eql Testrvduid
|
74
|
+
rvd.unit.should eql 'kg'
|
75
|
+
rvd.perunit.should eql 'month'
|
76
|
+
rvd.type.should eql 'CO2'
|
77
|
+
end
|
78
|
+
it "should delete a return value definition" do
|
79
|
+
connection = flexmock "connection"
|
80
|
+
connection.should_receive(:v3_get).
|
81
|
+
with("/#{AMEE_API_VERSION}/definitions/#{Testcativduid}/returnvalues/#{Testrvduid};full", {}).
|
82
|
+
and_return(fixture('return_value_definition.xml')).once
|
83
|
+
connection.should_receive(:v3_delete).
|
84
|
+
with("/#{AMEE_API_VERSION}/definitions/#{Testcativduid}/returnvalues/#{Testrvduid}").once
|
85
|
+
connection.should_receive(:timeout=)
|
86
|
+
connection.should_receive(:timeout)
|
87
|
+
rvd=AMEE::Admin::ReturnValueDefinition.load(connection,Testcativduid,Testrvduid)
|
88
|
+
AMEE::Admin::ReturnValueDefinition.delete(connection,Testcativduid,rvd)
|
89
|
+
end
|
90
|
+
end
|
metadata
CHANGED
@@ -1,21 +1,24 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
|
-
-
|
8
|
-
- 7
|
7
|
+
- 3
|
9
8
|
- 0
|
10
|
-
|
9
|
+
- 1
|
10
|
+
version: 3.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- James Smith
|
14
|
+
- James Hetherington
|
15
|
+
- Andrew Hill
|
16
|
+
- Andrew Berkeley
|
14
17
|
autorequire:
|
15
18
|
bindir: bin
|
16
19
|
cert_chain: []
|
17
20
|
|
18
|
-
date: 2011-08-
|
21
|
+
date: 2011-08-11 00:00:00 +01:00
|
19
22
|
default_executable: ameesh
|
20
23
|
dependencies:
|
21
24
|
- !ruby/object:Gem::Dependency
|
@@ -194,16 +197,19 @@ executables:
|
|
194
197
|
extensions: []
|
195
198
|
|
196
199
|
extra_rdoc_files:
|
197
|
-
-
|
200
|
+
- LICENSE.txt
|
201
|
+
- README.txt
|
198
202
|
files:
|
199
|
-
- CHANGELOG
|
200
|
-
- COPYING
|
203
|
+
- CHANGELOG.txt
|
201
204
|
- Gemfile
|
202
|
-
-
|
205
|
+
- Gemfile.lock
|
206
|
+
- LICENSE.txt
|
207
|
+
- README.txt
|
203
208
|
- Rakefile
|
204
209
|
- VERSION
|
205
210
|
- amee-ruby.gemspec
|
206
211
|
- amee.example.yml
|
212
|
+
- amee.gemspec
|
207
213
|
- bin/ameesh
|
208
214
|
- cacert.pem
|
209
215
|
- examples/create_profile.rb
|
@@ -237,6 +243,14 @@ files:
|
|
237
243
|
- lib/amee/rails.rb
|
238
244
|
- lib/amee/shell.rb
|
239
245
|
- lib/amee/user.rb
|
246
|
+
- lib/amee/v3.rb
|
247
|
+
- lib/amee/v3/collection.rb
|
248
|
+
- lib/amee/v3/connection.rb
|
249
|
+
- lib/amee/v3/item_definition.rb
|
250
|
+
- lib/amee/v3/item_value_definition.rb
|
251
|
+
- lib/amee/v3/item_value_definition_list.rb
|
252
|
+
- lib/amee/v3/meta_helper.rb
|
253
|
+
- lib/amee/v3/return_value_definition.rb
|
240
254
|
- rails/init.rb
|
241
255
|
- spec/amee_spec.rb
|
242
256
|
- spec/cache_spec.rb
|
@@ -249,6 +263,7 @@ files:
|
|
249
263
|
- spec/drill_down_spec.rb
|
250
264
|
- spec/fixtures/AD63A83B4D41.json
|
251
265
|
- spec/fixtures/AD63A83B4D41.xml
|
266
|
+
- spec/fixtures/BD88D30D1214.xml
|
252
267
|
- spec/fixtures/create_item.json
|
253
268
|
- spec/fixtures/create_item.xml
|
254
269
|
- spec/fixtures/data.json
|
@@ -258,7 +273,16 @@ files:
|
|
258
273
|
- spec/fixtures/data_transport_car_generic_drill_fuel_diesel.xml
|
259
274
|
- spec/fixtures/empty.json
|
260
275
|
- spec/fixtures/empty.xml
|
276
|
+
- spec/fixtures/empty_return_value_definition_list.xml
|
277
|
+
- spec/fixtures/itemdef.xml
|
278
|
+
- spec/fixtures/itemdef_441BF4BEA15B.xml
|
279
|
+
- spec/fixtures/itemdef_no_usages.xml
|
280
|
+
- spec/fixtures/itemdef_one_usage.xml
|
281
|
+
- spec/fixtures/ivdlist.xml
|
282
|
+
- spec/fixtures/ivdlist_BD88D30D1214.xml
|
261
283
|
- spec/fixtures/parse_test.xml
|
284
|
+
- spec/fixtures/return_value_definition.xml
|
285
|
+
- spec/fixtures/return_value_definition_list.xml
|
262
286
|
- spec/fixtures/v0_data_transport_transport_drill_transportType_Car1.xml
|
263
287
|
- spec/item_definition_spec.rb
|
264
288
|
- spec/item_value_definition_spec.rb
|
@@ -274,10 +298,14 @@ files:
|
|
274
298
|
- spec/spec.opts
|
275
299
|
- spec/spec_helper.rb
|
276
300
|
- spec/user_spec.rb
|
301
|
+
- spec/v3/connection_spec.rb
|
302
|
+
- spec/v3/item_definition_spec.rb
|
303
|
+
- spec/v3/item_value_definition_spec.rb
|
304
|
+
- spec/v3/return_value_definition_spec.rb
|
277
305
|
has_rdoc: true
|
278
306
|
homepage: http://github.com/AMEE/amee-ruby
|
279
307
|
licenses:
|
280
|
-
-
|
308
|
+
- BSD 3-Clause
|
281
309
|
post_install_message:
|
282
310
|
rdoc_options: []
|
283
311
|
|
data/COPYING
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
Copyright (c) 2008 James Smith (james@floppy.org.uk)
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
5
|
-
in the Software without restriction, including without limitation the rights
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
8
|
-
furnished to do so, subject to the following conditions:
|
9
|
-
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
11
|
-
all copies or substantial portions of the Software.
|
12
|
-
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
THE SOFTWARE.
|