amee 2.7.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,46 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
2
|
+
<Representation>
|
3
|
+
<ReturnValueDefinitions>
|
4
|
+
<ReturnValueDefinition uid="308BD9B0E78E">
|
5
|
+
<ItemDefinition uid="5648C049F599">
|
6
|
+
<Name>AMEEM Prexistent Test Itemdef</Name>
|
7
|
+
</ItemDefinition>
|
8
|
+
<ValueDefinition uid="45433E48B39F">
|
9
|
+
<Name>amount</Name>
|
10
|
+
<ValueType>DECIMAL</ValueType>
|
11
|
+
</ValueDefinition>
|
12
|
+
<Unit>kg</Unit>
|
13
|
+
<PerUnit>month</PerUnit>
|
14
|
+
<Type>CO2</Type>
|
15
|
+
<Default>false</Default>
|
16
|
+
</ReturnValueDefinition>
|
17
|
+
<ReturnValueDefinition uid="9D094FF46FD2">
|
18
|
+
<ItemDefinition uid="5648C049F599">
|
19
|
+
<Name>AMEEM Prexistent Test Itemdef</Name>
|
20
|
+
</ItemDefinition>
|
21
|
+
<ValueDefinition uid="45433E48B39F">
|
22
|
+
<Name>amount</Name>
|
23
|
+
<ValueType>DECIMAL</ValueType>
|
24
|
+
</ValueDefinition>
|
25
|
+
<Unit>kg</Unit>
|
26
|
+
<PerUnit>month</PerUnit>
|
27
|
+
<Type>CO2e</Type>
|
28
|
+
<Default>false</Default>
|
29
|
+
</ReturnValueDefinition>
|
30
|
+
<ReturnValueDefinition uid="C21026DD57C5">
|
31
|
+
<ItemDefinition uid="5648C049F599">
|
32
|
+
<Name>AMEEM Prexistent Test Itemdef</Name>
|
33
|
+
</ItemDefinition>
|
34
|
+
<ValueDefinition uid="45433E48B39F">
|
35
|
+
<Name>amount</Name>
|
36
|
+
<ValueType>DECIMAL</ValueType>
|
37
|
+
</ValueDefinition>
|
38
|
+
<Unit>kg</Unit>
|
39
|
+
<PerUnit>month</PerUnit>
|
40
|
+
<Type>CH4</Type>
|
41
|
+
<Default>false</Default>
|
42
|
+
</ReturnValueDefinition>
|
43
|
+
</ReturnValueDefinitions>
|
44
|
+
<Status>OK</Status>
|
45
|
+
<Version>3.1.0</Version>
|
46
|
+
</Representation>
|
@@ -1,3 +1,6 @@
|
|
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
|
+
|
1
4
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
5
|
|
3
6
|
describe AMEE::Admin::ItemDefinition do
|
@@ -32,11 +35,11 @@ describe AMEE::Admin::ItemDefinition, "with an authenticated connection" do
|
|
32
35
|
|
33
36
|
it "should parse XML correctly" do
|
34
37
|
connection = flexmock "connection"
|
35
|
-
connection.should_receive(:
|
38
|
+
connection.should_receive(:v3_get).with("/3.3/definitions/BD88D30D1214;full", {}).and_return(fixture('BD88D30D1214.xml'))
|
36
39
|
@data = AMEE::Admin::ItemDefinition.load(connection,"BD88D30D1214")
|
37
40
|
@data.uid.should == "BD88D30D1214"
|
38
|
-
@data.created.should == DateTime.new(2007,7,27,
|
39
|
-
@data.modified.should == DateTime.new(
|
41
|
+
@data.created.should == DateTime.new(2007,7,27,7,30,44)
|
42
|
+
@data.modified.should == DateTime.new(2011,2,16,8,40,06)
|
40
43
|
@data.name.should == "Bus Generic"
|
41
44
|
@data.drill_downs.should == ["type"]
|
42
45
|
@data.full_path.should == '/definitions/itemDefinitions/BD88D30D1214'
|
@@ -44,11 +47,11 @@ describe AMEE::Admin::ItemDefinition, "with an authenticated connection" do
|
|
44
47
|
|
45
48
|
it "should parse JSON correctly" do
|
46
49
|
connection = flexmock "connection"
|
47
|
-
connection.should_receive(:
|
50
|
+
connection.should_receive(:v3_get).with("/3.3/definitions/BD88D30D1214;full", {}).and_return(fixture('BD88D30D1214.xml'))
|
48
51
|
@data = AMEE::Admin::ItemDefinition.load(connection,"BD88D30D1214")
|
49
52
|
@data.uid.should == "BD88D30D1214"
|
50
|
-
@data.created.should == DateTime.new(2007,7,27,
|
51
|
-
@data.modified.should == DateTime.new(
|
53
|
+
@data.created.should == DateTime.new(2007,7,27,7,30,44)
|
54
|
+
@data.modified.should == DateTime.new(2011,2,16,8,40,06)
|
52
55
|
@data.name.should == "Bus Generic"
|
53
56
|
@data.drill_downs.should == ["type"]
|
54
57
|
@data.full_path.should == '/definitions/itemDefinitions/BD88D30D1214'
|
@@ -56,14 +59,14 @@ describe AMEE::Admin::ItemDefinition, "with an authenticated connection" do
|
|
56
59
|
|
57
60
|
it "should be able to load an item value definition list" do
|
58
61
|
connection = flexmock "connection"
|
59
|
-
connection.should_receive(:
|
62
|
+
connection.should_receive(:v3_get).with("/3.3/definitions/BD88D30D1214;full", {}).and_return(fixture('BD88D30D1214.xml'))
|
60
63
|
connection.should_receive(:retries).and_return(0).once
|
61
|
-
connection.should_receive(:
|
64
|
+
connection.should_receive(:v3_get).with("/3.3/definitions/BD88D30D1214/values;full", {:resultStart=>0, :resultLimit=>10}).and_return(fixture('ivdlist_BD88D30D1214.xml')).once
|
62
65
|
@data = AMEE::Admin::ItemDefinition.load(connection,"BD88D30D1214")
|
63
66
|
@data.uid.should == "BD88D30D1214"
|
64
67
|
@list=@data.item_value_definition_list
|
65
68
|
@list.length.should==15
|
66
|
-
@list.first.uid.should=='
|
69
|
+
@list.first.uid.should=='9813267B616E'
|
67
70
|
end
|
68
71
|
|
69
72
|
it "should fail gracefully with incorrect data" do
|
@@ -1,3 +1,6 @@
|
|
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
|
+
|
1
4
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
5
|
|
3
6
|
describe AMEE::Admin::ItemValueDefinition do
|
@@ -32,13 +35,13 @@ describe AMEE::Admin::ItemValueDefinitionList, "with an authenticated connection
|
|
32
35
|
it "should parse XML correctly" do
|
33
36
|
connection = flexmock "connection"
|
34
37
|
connection.should_receive(:retries).and_return(0).once
|
35
|
-
connection.should_receive(:
|
38
|
+
connection.should_receive(:v3_get).with("/3.3/definitions/BD88D30D1214/values;full", {:resultStart=>0, :resultLimit=>10}).and_return(fixture('ivdlist_BD88D30D1214.xml')).once
|
36
39
|
@data = AMEE::Admin::ItemValueDefinitionList.new(connection,"BD88D30D1214")
|
37
40
|
@data.length.should==15
|
38
|
-
@data.first.uid.should=='
|
39
|
-
@data.first.name.should == "
|
40
|
-
@data.first.path.should == "
|
41
|
-
@data.first.unit.should ==
|
41
|
+
@data.first.uid.should=='9813267B616E'
|
42
|
+
@data.first.name.should == "Country"
|
43
|
+
@data.first.path.should == "country"
|
44
|
+
@data.first.unit.should == nil
|
42
45
|
@data.first.perunit.should == nil
|
43
46
|
@data.first.profile?.should == true
|
44
47
|
@data.first.drill?.should == false
|
@@ -48,24 +51,31 @@ describe AMEE::Admin::ItemValueDefinitionList, "with an authenticated connection
|
|
48
51
|
it "should apply block filter correctly" do
|
49
52
|
connection = flexmock "connection"
|
50
53
|
connection.should_receive(:retries).and_return(0).once
|
51
|
-
connection.should_receive(:
|
54
|
+
connection.should_receive(:v3_get).with("/3.3/definitions/BD88D30D1214/values;full", {:resultStart=>0, :resultLimit=>10}).and_return(fixture('ivdlist_BD88D30D1214.xml')).once
|
52
55
|
@data = AMEE::Admin::ItemValueDefinitionList.new(connection,"BD88D30D1214") do |x|
|
53
|
-
x.uid == 'A8A212610A57' ? x
|
56
|
+
x.uid == 'A8A212610A57' ? x : nil
|
54
57
|
end
|
55
|
-
|
56
|
-
@data.first.should=='A8A212610A57'
|
58
|
+
#@data.length.should==1
|
59
|
+
@data.first.uid.should=='A8A212610A57'
|
60
|
+
@data.first.name.should == "Distance per journey"
|
61
|
+
@data.first.path.should == "distancePerJourney"
|
62
|
+
@data.first.unit.should == "km"
|
63
|
+
@data.first.perunit.should == nil
|
64
|
+
@data.first.profile?.should == true
|
65
|
+
@data.first.drill?.should == false
|
66
|
+
@data.first.data?.should == false
|
57
67
|
end
|
58
68
|
|
59
69
|
it "should parse JSON correctly" do
|
60
70
|
connection = flexmock "connection"
|
61
71
|
connection.should_receive(:retries).and_return(0).once
|
62
|
-
connection.should_receive(:
|
72
|
+
connection.should_receive(:v3_get).with("/3.3/definitions/BD88D30D1214/values;full", {:resultStart=>0, :resultLimit=>10}).and_return(fixture('ivdlist_BD88D30D1214.xml')).once
|
63
73
|
@data = AMEE::Admin::ItemValueDefinitionList.new(connection,"BD88D30D1214")
|
64
74
|
@data.length.should==15
|
65
|
-
@data.first.uid.should=='
|
66
|
-
@data.first.name.should == "
|
67
|
-
@data.first.path.should == "
|
68
|
-
@data.first.unit.should ==
|
75
|
+
@data.first.uid.should=='9813267B616E'
|
76
|
+
@data.first.name.should == "Country"
|
77
|
+
@data.first.path.should == "country"
|
78
|
+
@data.first.unit.should == nil
|
69
79
|
@data.first.perunit.should == nil
|
70
80
|
@data.first.profile?.should == true
|
71
81
|
@data.first.drill?.should == false
|
@@ -76,8 +86,8 @@ describe AMEE::Admin::ItemValueDefinitionList, "with an authenticated connection
|
|
76
86
|
connection = flexmock "connection"
|
77
87
|
connection.should_receive(:retries).and_return(0).once
|
78
88
|
xml = '<?xml version="1.0" encoding="UTF-8"?><Resources></Resources>'
|
79
|
-
connection.should_receive(:
|
80
|
-
connection.should_receive(:expire).with("/definitions/
|
89
|
+
connection.should_receive(:v3_get).with("/3.3/definitions/BD88D30D1214/values;full", {:resultStart=>0, :resultLimit=>10}).and_return(xml)
|
90
|
+
connection.should_receive(:expire).with("/3.3/definitions/BD88D30D1214/values;full").once
|
81
91
|
lambda{AMEE::Admin::ItemValueDefinitionList.new(connection, "BD88D30D1214")}.should raise_error(AMEE::BadData)
|
82
92
|
end
|
83
93
|
|
@@ -85,15 +95,15 @@ describe AMEE::Admin::ItemValueDefinitionList, "with an authenticated connection
|
|
85
95
|
connection = flexmock "connection"
|
86
96
|
connection.should_receive(:retries).and_return(0).once
|
87
97
|
json = '{}'
|
88
|
-
connection.should_receive(:
|
89
|
-
connection.should_receive(:expire).with("/definitions/
|
98
|
+
connection.should_receive(:v3_get).with("/3.3/definitions/BD88D30D1214/values;full", {:resultStart=>0, :resultLimit=>10}).and_return(json)
|
99
|
+
connection.should_receive(:expire).with("/3.3/definitions/BD88D30D1214/values;full").once
|
90
100
|
lambda{AMEE::Admin::ItemValueDefinitionList.new(connection, "BD88D30D1214")}.should raise_error(AMEE::BadData)
|
91
101
|
end
|
92
102
|
|
93
103
|
it "should fail gracefully on other errors" do
|
94
104
|
connection = flexmock "connection"
|
95
105
|
connection.should_receive(:retries).and_return(0).once
|
96
|
-
connection.should_receive(:
|
106
|
+
connection.should_receive(:v3_get).with("/3.3/definitions/BD88D30D1214/values;full", {:resultStart=>0, :resultLimit=>10}).and_raise(Timeout::Error)
|
97
107
|
lambda{AMEE::Admin::ItemValueDefinitionList.new(connection, "BD88D30D1214")}.should raise_error(Timeout::Error)
|
98
108
|
end
|
99
109
|
end
|
data/spec/logger_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#
|
2
|
-
#
|
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
3
|
|
4
4
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
5
5
|
|
data/spec/object_spec.rb
CHANGED
data/spec/parse_helper_spec.rb
CHANGED
data/spec/profile_item_spec.rb
CHANGED
data/spec/profile_object_spec.rb
CHANGED
data/spec/profile_spec.rb
CHANGED
data/spec/rails_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
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
|
+
|
1
4
|
require 'rubygems'
|
2
5
|
require 'spec'
|
3
6
|
require 'rspec_spinner'
|
7
|
+
require 'activesupport'
|
4
8
|
|
5
9
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
6
10
|
require 'amee'
|
@@ -54,3 +58,6 @@ end
|
|
54
58
|
def fixture(filename)
|
55
59
|
File.read File.dirname(__FILE__)+'/fixtures/'+filename
|
56
60
|
end
|
61
|
+
|
62
|
+
XMLPreamble='<?xml version="1.0" encoding="UTF-8"?>'
|
63
|
+
|
data/spec/user_spec.rb
CHANGED
@@ -0,0 +1,169 @@
|
|
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::Connection do
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
@c = AMEE::Connection.new('server.example.com', 'username', 'password', :ssl => false)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have a connection to meta server" do
|
13
|
+
flexmock(Net::HTTP).new_instances.should_receive(:start => nil)
|
14
|
+
@c.v3_connection.should_not be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should login and know the path to the server" do
|
18
|
+
flexmock(Net::HTTP::Get).new_instances do |mock|
|
19
|
+
mock.should_receive(:basic_auth).with('username','password').once
|
20
|
+
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_API_VERSION}/categories/SomeCategory").should == "OK"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should be able to get from meta server" do
|
33
|
+
flexmock(Net::HTTP).new_instances do |mock|
|
34
|
+
mock.should_receive(:start => nil)
|
35
|
+
mock.should_receive(:request).and_return(flexmock(:code => '200', :body => "OK"))
|
36
|
+
mock.should_receive(:finish => nil)
|
37
|
+
end
|
38
|
+
@c.v3_get("/#{AMEE_API_VERSION}/categories/SomeCategory").should == "OK"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be able to handle failed gets from meta server" do
|
42
|
+
flexmock(Net::HTTP).new_instances do |mock|
|
43
|
+
mock.should_receive(:start => nil)
|
44
|
+
mock.should_receive(:request).and_return(flexmock(:code => '404'))
|
45
|
+
mock.should_receive(:finish => nil)
|
46
|
+
end
|
47
|
+
lambda {
|
48
|
+
@c.v3_get("/#{AMEE_API_VERSION}/categories/SomeCategory").should == nil
|
49
|
+
}.should raise_error(AMEE::NotFound, "The URL was not found on the server.\nRequest: GET /#{AMEE_API_VERSION}/categories/SomeCategory")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should be able to post to meta server" do
|
53
|
+
flexmock(Net::HTTP).new_instances do |mock|
|
54
|
+
mock.should_receive(:start => nil)
|
55
|
+
mock.should_receive(:request).and_return(flexmock(:code => '200', :body => "OK"))
|
56
|
+
mock.should_receive(:finish => nil)
|
57
|
+
end
|
58
|
+
@c.v3_put("/#{AMEE_API_VERSION}/categories/SomeCategory", {:arg => "test"}).should == "OK"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should be able to handle failed gets from meta server" do
|
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
|
67
|
+
lambda {
|
68
|
+
@c.v3_put("/#{AMEE_API_VERSION}/categories/SomeCategory", {:arg => "test"}).should == "OK"
|
69
|
+
}.should raise_error
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should generate correct hostname for platform-dev.amee.com" do
|
73
|
+
c = AMEE::Connection.new('platform-dev.amee.com', 'username', 'password')
|
74
|
+
c.send(:v3_hostname).should eql 'platform-api-dev.amee.com'
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should generate correct hostname for platform-science.amee.com" do
|
78
|
+
c = AMEE::Connection.new('platform-science.amee.com', 'username', 'password')
|
79
|
+
c.send(:v3_hostname).should eql 'platform-api-science.amee.com'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should generate correct hostname for stage.amee.com" do
|
83
|
+
c = AMEE::Connection.new('stage.amee.com', 'username', 'password')
|
84
|
+
c.send(:v3_hostname).should eql 'platform-api-stage.amee.com'
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should generate correct hostname for live.amee.com" do
|
88
|
+
c = AMEE::Connection.new('live.amee.com', 'username', 'password')
|
89
|
+
c.send(:v3_hostname).should eql 'platform-api-live.amee.com'
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should not change modern hostnames" do
|
93
|
+
c = AMEE::Connection.new('platform-api-test.amee.com', 'username', 'password')
|
94
|
+
c.send(:v3_hostname).should eql 'platform-api-test.amee.com'
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
describe AMEE::Connection, "with retry enabled" do
|
100
|
+
|
101
|
+
before :each do
|
102
|
+
@c = AMEE::Connection.new('server.example.com', 'username', 'password', :ssl => false, :retries => 2)
|
103
|
+
end
|
104
|
+
|
105
|
+
[
|
106
|
+
Timeout::Error,
|
107
|
+
Errno::EINVAL,
|
108
|
+
Errno::ECONNRESET,
|
109
|
+
EOFError,
|
110
|
+
Net::HTTPBadResponse,
|
111
|
+
Net::HTTPHeaderSyntaxError,
|
112
|
+
Net::ProtocolError
|
113
|
+
].each do |e|
|
114
|
+
|
115
|
+
it "should retry after #{e.name} the correct number of times" do
|
116
|
+
flexmock(Net::HTTP).new_instances do |mock|
|
117
|
+
mock.should_receive(:start => nil)
|
118
|
+
mock.should_receive(:request).and_raise(e.new).twice
|
119
|
+
mock.should_receive(:request).and_return(flexmock(:code => '200', :body => '{}')).once
|
120
|
+
mock.should_receive(:finish => nil)
|
121
|
+
end
|
122
|
+
lambda {
|
123
|
+
@c.v3_get("/#{AMEE_API_VERSION}/categories/SomeCategory")
|
124
|
+
}.should_not raise_error
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should retry #{e.name} the correct number of times and raise error on failure" do
|
128
|
+
flexmock(Net::HTTP).new_instances do |mock|
|
129
|
+
mock.should_receive(:start => nil)
|
130
|
+
mock.should_receive(:request).and_raise(e.new).times(3)
|
131
|
+
mock.should_receive(:finish => nil)
|
132
|
+
end
|
133
|
+
lambda {
|
134
|
+
@c.v3_get("/#{AMEE_API_VERSION}/categories/SomeCategory")
|
135
|
+
}.should raise_error(e)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
[
|
140
|
+
'502',
|
141
|
+
'503',
|
142
|
+
'504'
|
143
|
+
].each do |e|
|
144
|
+
|
145
|
+
it "should retry after #{e} the correct number of times" do
|
146
|
+
flexmock(Net::HTTP).new_instances do |mock|
|
147
|
+
mock.should_receive(:start => nil)
|
148
|
+
mock.should_receive(:request).and_return(flexmock(:code => e, :body => '{}')).twice
|
149
|
+
mock.should_receive(:request).and_return(flexmock(:code => '200', :body => '{}')).once
|
150
|
+
mock.should_receive(:finish => nil)
|
151
|
+
end
|
152
|
+
lambda {
|
153
|
+
@c.v3_get("/#{AMEE_API_VERSION}/categories/SomeCategory")
|
154
|
+
}.should_not raise_error
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should retry #{e} the correct number of times and raise error on failure" do
|
158
|
+
flexmock(Net::HTTP).new_instances do |mock|
|
159
|
+
mock.should_receive(:start => nil)
|
160
|
+
mock.should_receive(:request).and_return(flexmock(:code => e, :body => '{}')).times(3)
|
161
|
+
mock.should_receive(:finish => nil)
|
162
|
+
end
|
163
|
+
lambda {
|
164
|
+
@c.v3_get("/#{AMEE_API_VERSION}/categories/SomeCategory")
|
165
|
+
}.should raise_error(AMEE::ConnectionFailed)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|