mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[hp|dns] Add DNS model tests and updated models and mocks.
This commit is contained in:
parent
749685be8a
commit
000ab244d6
17 changed files with 279 additions and 40 deletions
|
@ -0,0 +1,55 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module HP
|
||||
class DNS
|
||||
|
||||
class Domain < Fog::Model
|
||||
identity :id
|
||||
|
||||
attribute :name
|
||||
attribute :description
|
||||
attribute :email
|
||||
attribute :ttl
|
||||
attribute :serial
|
||||
attribute :created_at
|
||||
attribute :updated_at
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
service.delete_domain(id)
|
||||
true
|
||||
end
|
||||
|
||||
def records
|
||||
@records ||= begin
|
||||
Fog::HP::DNS::Records.new({
|
||||
:service => service,
|
||||
:domain => self
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
def save
|
||||
identity ? update : create
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create
|
||||
### Inconsistent API behavior - does not return 'domain'
|
||||
merge_attributes(service.create_domain(self.name, self.email, attributes).body)
|
||||
true
|
||||
end
|
||||
|
||||
def update
|
||||
requires :id
|
||||
### Inconsistent API behavior - does not return 'domain'
|
||||
merge_attributes(service.update_domain(id, attributes).body)
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/hp/models/dns/domains'
|
||||
require 'fog/hp/models/dns/domain'
|
||||
|
||||
module Fog
|
||||
module HP
|
||||
|
@ -7,23 +7,15 @@ module Fog
|
|||
|
||||
class Domains < Fog::Collection
|
||||
|
||||
attribute :filters
|
||||
model Fog::HP::DNS::Domain
|
||||
|
||||
model Fog::HP::DNS::Domains
|
||||
|
||||
def initialize(attributes)
|
||||
self.filters ||= {}
|
||||
super
|
||||
end
|
||||
|
||||
def all(filters = filters)
|
||||
self.filters = filters
|
||||
non_aliased_filters = Fog::HP.convert_aliased_attributes_to_original(self.model, filters)
|
||||
load(service.list_domains(non_aliased_filters).body['domains'])
|
||||
def all
|
||||
load(service.list_domains.body['domains'])
|
||||
end
|
||||
|
||||
def get(domain_id)
|
||||
if domain = service.get_domain(domain_id).body['domain']
|
||||
### Inconsistent API - does not return a 'domain'
|
||||
if domain = service.get_domain(domain_id).body
|
||||
new(domain)
|
||||
end
|
||||
rescue Fog::HP::DNS::NotFound
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module HP
|
||||
class DNS
|
||||
|
||||
class Record < Fog::Model
|
||||
identity :id
|
||||
|
||||
attribute :name
|
||||
attribute :description
|
||||
attribute :domain_id
|
||||
attribute :type
|
||||
attribute :ttl
|
||||
attribute :data
|
||||
attribute :priority
|
||||
attribute :created_at
|
||||
attribute :updated_at
|
||||
|
||||
def initialize(new_attributes = {})
|
||||
super(new_attributes)
|
||||
self.domain_id = domain.id if domain
|
||||
self
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id, :domain_id
|
||||
service.delete_record(self.domain_id, id)
|
||||
true
|
||||
end
|
||||
|
||||
def save
|
||||
identity ? update : create
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def domain
|
||||
collection.domain
|
||||
end
|
||||
|
||||
def create
|
||||
requires :domain_id
|
||||
### Inconsistent API behavior - does not return 'record'
|
||||
merge_attributes(service.create_record(self.domain_id, self.name, self.type, self.data, attributes).body)
|
||||
true
|
||||
end
|
||||
|
||||
def update
|
||||
requires :id, :domain_id
|
||||
### Inconsistent API behavior - does not return 'domain'
|
||||
merge_attributes(service.update_record(self.domain_id, id, attributes).body)
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,32 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/hp/models/dns/record'
|
||||
|
||||
module Fog
|
||||
module HP
|
||||
class DNS
|
||||
|
||||
class Records < Fog::Collection
|
||||
|
||||
model Fog::HP::DNS::Record
|
||||
|
||||
attr_accessor :domain
|
||||
|
||||
def all
|
||||
requires :domain
|
||||
load(service.list_records_in_a_domain(domain.id).body['records'])
|
||||
end
|
||||
|
||||
def get(record_id)
|
||||
requires :domain
|
||||
### Inconsistent API - does not return a 'record'
|
||||
if record = service.get_record(domain.id, record_id).body
|
||||
new(record)
|
||||
end
|
||||
rescue Fog::HP::DNS::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -5,9 +5,10 @@ module Fog
|
|||
# Create a new DNS domain
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 'name'<~String> - Name of domain
|
||||
# * 'email'<~String> - email for the domain
|
||||
# * 'name'<~String> - Name of the domain
|
||||
# * 'email'<~String> - Email for the domain
|
||||
# * options<~Hash>:
|
||||
# * 'description'<~String> - Description for the domain
|
||||
# * 'ttl'<~String> - TTL for the domain
|
||||
#
|
||||
# ==== Returns
|
||||
|
@ -15,6 +16,7 @@ module Fog
|
|||
# * body<~Hash>:
|
||||
# * 'id'<~String> - UUID of the domain
|
||||
# * 'name'<~String> - Name of the domain
|
||||
# * 'description'<~String> - Description for the domain
|
||||
# * 'ttl'<~Integer> - TTL for the domain
|
||||
# * 'email'<~String> - Email for the domain
|
||||
# * 'serial'<~Integer> - Serial number for the domain
|
||||
|
@ -26,7 +28,7 @@ module Fog
|
|||
:email => email
|
||||
}
|
||||
|
||||
l_options = [:ttl]
|
||||
l_options = [:description, :ttl]
|
||||
l_options.select{|o| options[o]}.each do |key|
|
||||
data[key] = options[key]
|
||||
end
|
||||
|
@ -48,9 +50,10 @@ module Fog
|
|||
data = {
|
||||
'id' => Fog::HP::Mock.uuid.to_s,
|
||||
'name' => name || 'domain1.com.',
|
||||
'ttl' => options[:ttl] || 3600,
|
||||
'email' => email || 'nsadmin@example.org',
|
||||
'serial' => 1351800588,
|
||||
'description' => options[:description] || 'desc domain1.com.',
|
||||
'ttl' => options[:ttl] || 3600,
|
||||
'serial' => Fog::Mock.random_numbers(10).to_i,
|
||||
'created_at' => '2012-01-01T13:32:20Z'
|
||||
}
|
||||
self.data[:domains][data['id']] = data
|
||||
|
|
|
@ -6,30 +6,38 @@ module Fog
|
|||
# Create a new DNS record
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 'domain_id'<~String> - UUId of the domain
|
||||
# * 'name'<~String> - Name of record
|
||||
# * 'type'<~String> - Type of the record i.e. 'A'
|
||||
# * 'data'<~String> - Data required by the record
|
||||
# * 'priority'<~String> - Priority
|
||||
# * options<~Hash>:
|
||||
# * 'description'<~String> - Description for the record
|
||||
# * 'priority'<~Integer> - Priority
|
||||
# * 'ttl'<~Integer> - TTL of the record
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'id'<~String> - UUID of the record
|
||||
# * 'name'<~String> - Name of the record
|
||||
# * 'description'<~String> - Description for the record
|
||||
# * 'type'<~String> - Type of the record
|
||||
# * 'domain_id'<~String> - UUID of the domain
|
||||
# * 'ttl'<~Integer> - TTL of the record
|
||||
# * 'data'<~String> - Data required by the record
|
||||
# * 'priority'<~String> - Priority for the record
|
||||
# * 'priority'<~Integer> - Priority for the record
|
||||
# * 'created_at'<~String> - created date time stamp
|
||||
# * 'updated_at'<~String> - updated date time stamp
|
||||
def create_record(domain_id, name, type, data, priority=nil)
|
||||
def create_record(domain_id, name, type, data, options={})
|
||||
data = {
|
||||
:name => name,
|
||||
:type => type,
|
||||
:data => data
|
||||
}
|
||||
data[:priority] = priority.to_i unless priority.nil?
|
||||
l_options = [:description, :priority, :ttl]
|
||||
l_options.select{|o| options[o]}.each do |key|
|
||||
data[key] = options[key]
|
||||
end
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
|
@ -41,8 +49,7 @@ module Fog
|
|||
end
|
||||
end
|
||||
class Mock
|
||||
def create_record(domain_id, name, type, data, priority)
|
||||
priority = priority.to_i unless priority.nil?
|
||||
def create_record(domain_id, name, type, data, options={})
|
||||
response = Excon::Response.new
|
||||
if list_domains.body['domains'].detect {|_| _['id'] == domain_id}
|
||||
response.status = 200
|
||||
|
@ -52,8 +59,9 @@ module Fog
|
|||
'name' => name || 'www.example.com.',
|
||||
'type' => type || 'A',
|
||||
'data' => data || '15.185.172.152',
|
||||
'ttl' => 3600,
|
||||
'priority' => priority || nil,
|
||||
'ttl' => options['ttl'] || 3600,
|
||||
'description' => options['description'] || 'desc for www.example.com.',
|
||||
'priority' => options['priority'] || nil,
|
||||
'created_at' => '2012-11-02T19:56:26.366792',
|
||||
'updated_at' => '2012-11-02T19:56:26.366792'
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ module Fog
|
|||
# Delete a DNS Record
|
||||
#
|
||||
# ==== Parameters
|
||||
# * domain_id<~Integer> - Id of domain for record
|
||||
# * record_id<~Integer> - Id of record to delete
|
||||
# * 'domain_id'<~String> - UUId of domain for record
|
||||
# * 'record_id'<~String> - UUId of record to delete
|
||||
#
|
||||
def delete_record(domain_id, record_id)
|
||||
request(
|
||||
|
|
|
@ -6,14 +6,15 @@ module Fog
|
|||
# Get details of an existing DNS record
|
||||
#
|
||||
# ==== Parameters
|
||||
# * domain_id<~String> - UUId of domain for record
|
||||
# * record_id<~String> - UUId of record to get
|
||||
# * 'domain_id'<~String> - UUId of domain for record
|
||||
# * 'record_id'<~String> - UUId of record to get
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'id'<~String> - UUID of the record
|
||||
# * 'name'<~String> - Name of the record
|
||||
# * 'description'<~String> - Description for the record
|
||||
# * 'type'<~String> - Type of the record
|
||||
# * 'domain_id'<~String> - UUId of the domain
|
||||
# * 'ttl'<~Integer> - TTL of the record
|
||||
|
|
|
@ -4,12 +4,16 @@ module Fog
|
|||
class Real
|
||||
# List DNS records for a given domain
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 'domain_id'<~String> - UUId of domain for record
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'records'<~Array>:
|
||||
# * 'id'<~String> - UUID of the record
|
||||
# * 'name'<~String> - Name of the record
|
||||
# * 'description'<~String> - Description for the record
|
||||
# * 'type'<~String> - Type of the record
|
||||
# * 'domain_id'<~String> - UUID of the domain
|
||||
# * 'ttl'<~Integer> - TTL of the record
|
||||
|
|
|
@ -9,6 +9,7 @@ module Fog
|
|||
# * domain_id<~String> - UUId of domain to delete
|
||||
# * options<~Hash>:
|
||||
# * 'name'<~String> - Name of domain
|
||||
# * 'description'<~String> - Description for the domain
|
||||
# * 'ttl'<~String> - TTL for the domain
|
||||
# * 'email'<~String> - email for the domain
|
||||
#
|
||||
|
@ -17,12 +18,14 @@ module Fog
|
|||
# * body<~Hash>:
|
||||
# * 'id'<~String> - UUID of the domain
|
||||
# * 'name'<~String> - Name of the domain
|
||||
# * 'description'<~String> - Description for the domain
|
||||
# * 'ttl'<~Integer> - TTL for the domain
|
||||
# * 'email'<~String> - Email for the domain
|
||||
# * 'serial'<~Integer> - Serial number for the domain
|
||||
# * 'created_at'<~String> - created date time stamp
|
||||
def update_domain(domain_id, options={})
|
||||
l_options = [:name, :ttl, :email]
|
||||
data = {}
|
||||
l_options = [:name, :description, :ttl, :email]
|
||||
l_options.select{|o| options[o]}.each do |key|
|
||||
data[key] = options[key]
|
||||
end
|
||||
|
@ -41,9 +44,10 @@ module Fog
|
|||
response = Excon::Response.new
|
||||
if domain = list_domains.body['domains'].detect { |_| _['id'] == domain_id }
|
||||
|
||||
domain['name'] = options[:name] if options[:name]
|
||||
domain['ttl'] = options[:ttl] if options[:ttl]
|
||||
domain['email'] = options[:email] if options[:email]
|
||||
domain['name'] = options[:name] if options[:name]
|
||||
domain['description'] = options[:description] if options[:description]
|
||||
domain['ttl'] = options[:ttl] if options[:ttl]
|
||||
domain['email'] = options[:email] if options[:email]
|
||||
|
||||
response.status = 200
|
||||
response.body = domain
|
||||
|
|
|
@ -6,19 +6,22 @@ module Fog
|
|||
# Update an existing DNS record
|
||||
#
|
||||
# ==== Parameters
|
||||
# * domain_id<~String> - UUId of domain to delete
|
||||
# * record_id<~String> - UUId of record to get
|
||||
# * 'domain_id'<~String> - UUId of domain of record
|
||||
# * 'record_id'<~String> - UUId of record to update
|
||||
# * options<~Hash>:
|
||||
# * 'name'<~String> - Name of record
|
||||
# * 'description'<~String> - Description for the record
|
||||
# * 'type'<~String> - Type of the record i.e. 'A'
|
||||
# * 'data'<~String> - Data required by the record
|
||||
# * 'priority'<~Integer> - Priority
|
||||
# * 'ttl'<~Integer> - TTL of the record
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'id'<~String> - UUID of the record
|
||||
# * 'name'<~String> - Name of the record
|
||||
# * 'description'<~String> - Description for the record
|
||||
# * 'type'<~String> - Type of the record
|
||||
# * 'domain_id'<~String> - UUID of the domain
|
||||
# * 'ttl'<~Integer> - TTL of the record
|
||||
|
|
25
tests/hp/models/dns/domain_tests.rb
Normal file
25
tests/hp/models/dns/domain_tests.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
Shindo.tests('HP::DNS | domain model', ['hp', 'dns', 'domain']) do
|
||||
|
||||
attributes = {:name => 'www.fogtest.com.', :email => 'test@fogtest.com'}
|
||||
model_tests(HP[:dns].domains, attributes, true)
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests('#create').succeeds do
|
||||
attributes = {:name => 'www.fogtest.com.', :email => 'test@fogtest.com', :ttl => 3600}
|
||||
@domain = HP[:dns].domains.create(attributes)
|
||||
!@domain.id.nil?
|
||||
end
|
||||
|
||||
tests('Update via #save').succeeds do
|
||||
@domain.email = 'update@fogtest.com'
|
||||
@domain.save
|
||||
end
|
||||
|
||||
tests('#destroy').succeeds do
|
||||
@domain.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
14
tests/hp/models/dns/domains_tests.rb
Normal file
14
tests/hp/models/dns/domains_tests.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
Shindo.tests('HP::DNS | domains collection', ['hp', 'dns', 'domains']) do
|
||||
|
||||
attributes = {:name => 'www.fogtest.com.', :email => 'test@fogtest.com', :ttl => 3600}
|
||||
collection_tests(HP[:dns].domains, attributes, true)
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests('#all').succeeds do
|
||||
HP[:dns].domains.all
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
28
tests/hp/models/dns/record_tests.rb
Normal file
28
tests/hp/models/dns/record_tests.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
Shindo.tests('HP::DNS | record model', ['hp', 'dns', 'record']) do
|
||||
|
||||
@domain = HP[:dns].domains.create({:name => 'www.fogtest.com.', :email => 'test@fogtest.com'})
|
||||
|
||||
attributes = {:domain_id => @domain.id, :name => 'www.fogtest.com.', :type => 'A', :data => '15.185.100.152'}
|
||||
model_tests(@domain.records, attributes, true)
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests('#create').succeeds do
|
||||
attributes = {:domain_id => @domain.id, :name => 'www.fogtest.com.', :type => 'A', :data => '15.185.200.152', :description => 'test record'}
|
||||
@record = HP[:dns].records.create(attributes)
|
||||
!@record.id.nil?
|
||||
end
|
||||
|
||||
tests('Update via #save').succeeds do
|
||||
@record.name = 'www.fogupdate.com.'
|
||||
@record.save
|
||||
end
|
||||
|
||||
tests('#destroy').succeeds do
|
||||
@record.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@domain.destroy
|
||||
end
|
9
tests/hp/models/dns/records_tests.rb
Normal file
9
tests/hp/models/dns/records_tests.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
Shindo.tests('HP::DNS | records collection', ['hp', 'dns', 'records']) do
|
||||
|
||||
@domain = HP[:dns].domains.create({:name => 'www.fogtest.com.', :email => 'test@fogtest.com'})
|
||||
|
||||
attributes = {:domain_id => @domain.id, :name => 'www.fogtest.com.', :type => 'A', :data => '15.185.172.152'}
|
||||
collection_tests(@domain.records, attributes, true)
|
||||
|
||||
@domain.destroy
|
||||
end
|
|
@ -2,6 +2,7 @@ Shindo.tests("HP::DNS | domain requests", ['hp', 'dns', 'domain']) do
|
|||
@domain_format = {
|
||||
'id' => String,
|
||||
'name' => String,
|
||||
'description' => String,
|
||||
'ttl' => Integer,
|
||||
'serial' => Integer,
|
||||
'email' => String,
|
||||
|
|
|
@ -2,11 +2,12 @@ Shindo.tests("HP::DNS | record requests", ['hp', 'dns', 'record']) do
|
|||
@record_format = {
|
||||
'id' => String,
|
||||
'name' => String,
|
||||
'description' => String,
|
||||
'type' => String,
|
||||
'domain_id' => String,
|
||||
'ttl' => Integer,
|
||||
'data' => String,
|
||||
'priority' => Integer,
|
||||
'priority' => Fog::Nullable::Integer,
|
||||
'created_at' => String,
|
||||
'updated_at' => String
|
||||
}
|
||||
|
@ -19,8 +20,8 @@ Shindo.tests("HP::DNS | record requests", ['hp', 'dns', 'record']) do
|
|||
@record_name = 'www.fogtest.com.'
|
||||
@record_data = '15.185.172.152'
|
||||
|
||||
tests("#create_record(#{@domain_id}, #{@record_name}, 'A', #{@record_data}, 1)").formats(@record_format) do
|
||||
data = HP[:dns].create_record(@domain_id, @record_name, 'A', @record_data, 1).body
|
||||
tests("#create_record(#{@domain_id}, #{@record_name}, 'A', #{@record_data})").formats(@record_format) do
|
||||
data = HP[:dns].create_record(@domain_id, @record_name, 'A', @record_data).body
|
||||
@record_id = data['id']
|
||||
data
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue