[terremark] Mock for get_organizations

This commit is contained in:
Edward Muller 2010-04-28 11:50:23 +08:00 committed by Wesley Beary
parent bb79de6fc8
commit 14c2da7e3c
4 changed files with 52 additions and 12 deletions

View File

@ -43,6 +43,11 @@ module Fog
class Mock
include Fog::Terremark::Shared::Mock
include Fog::Terremark::Shared::Parser
def initialize(option = {})
super
@data = self.class.data[:terremark_ecloud_username]
end
end
end

View File

@ -30,7 +30,16 @@ module Fog
module Mock
def get_organizations
raise MockNotImplemented.new("Contributions welcome!")
response = Excon::Response.new
org_list = @data[:organizations].map do |organization|
{ "name" => organization[:info][:name],
"href" => "https://services.enterprisecloud.terremark.com/api/v0.8a-ext2.0/org/#{organization[:info][:id]}",
"type" => "application/vnd.vmware.vcloud.org+xml"
}
end
response.body = { "OrgList" => org_list }
response.headers = Fog::Terremark::Shared::Mock.headers(response.body, "application/vnd.vmware.vcloud.orgList+xml")
response
end
end

View File

@ -51,21 +51,42 @@ module Fog
end
module Mock
def self.data
@data ||= Hash.new do |hash, key|
hash[key] = {}
end
end
def self.reset_data(keys=data.keys)
for key in [*keys]
data.delete(key)
end
DATA = {
:organizations =>
[
{
:info => {
:name => "Boom Inc.",
:id => "1"
}
}
]
}
def self.headers(body, content_type)
{"X-Powered-By"=>"ASP.NET",
"Date"=> Time.now.to_s,
"Content-Type"=> content_type,
"Content-Length"=> body.to_s.length,
"Server"=>"Microsoft-IIS/7.0",
"Set-Cookie"=>"vcloud-token=ecb37bfc-56f0-421d-97e5-bf2gdf789457; path=/",
"Cache-Control"=>"private"}
end
def initialize(options={})
@terremark_username = options[:terremark_username]
@data = self.class.data[@terremark_username]
self.class.instance_eval '
def self.data
@data ||= Hash.new do |hash, key|
hash[key] = Fog::Terremark::Shared::Mock::DATA
end
end'
self.class.instance_eval '
def self.reset_data(keys=data.keys)
for key in [*keys]
data.delete(key)
end
end'
end
end

View File

@ -89,6 +89,11 @@ module Fog
class Mock
include Fog::Terremark::Shared::Mock
include Fog::Terremark::Shared::Parser
def initialize(option = {})
super
@data = self.class.data[:terremark_vcloud_username]
end
end
end