-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
281 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'netbox_client_ruby/entity' | ||
require 'netbox_client_ruby/api/dcim/manufacturer' | ||
require 'netbox_client_ruby/api/tenancy/tenant' | ||
|
||
module NetboxClientRuby | ||
class DeviceType | ||
include NetboxClientRuby::Entity | ||
|
||
id id: :id | ||
deletable true | ||
path 'dcim/device-types/:id.json' | ||
creation_path 'dcim/device-types/' | ||
object_fields( | ||
manufacturer: proc { |raw_data| NetboxClientRuby::Manufacturer.new raw_data['id'] }, | ||
interface_ordering: NetboxClientRuby::DeviceTypeInterfaceOrdering | ||
) | ||
readonly_fields :display_name | ||
|
||
end | ||
|
||
class IpAddressStatus | ||
attr_reader :value, :label | ||
|
||
def initialize(raw_data) | ||
@value = raw_data['value'] | ||
@label = raw_data['label'] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'netbox_client_ruby/entities' | ||
require 'netbox_client_ruby/api/dcim/device_type' | ||
|
||
module NetboxClientRuby | ||
class DeviceTypes | ||
include NetboxClientRuby::Entities | ||
|
||
path 'ipam/ip-addresses.json' | ||
data_key 'results' | ||
count_key 'count' | ||
entity_creator :entity_creator | ||
|
||
private | ||
|
||
def entity_creator(raw_entity) | ||
NetboxClientRuby::DeviceType.new raw_entity['id'] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'netbox_client_ruby/entity' | ||
|
||
module NetboxClientRuby | ||
class Manufacturer | ||
include NetboxClientRuby::Entity | ||
|
||
id id: :id | ||
deletable true | ||
path 'dcim/manufacturers/:id.json' | ||
creation_path 'dcim/manufacturers/' | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'netbox_client_ruby/entities' | ||
require 'netbox_client_ruby/api/dcim/manufacturer' | ||
|
||
module NetboxClientRuby | ||
class Manufacturers | ||
include NetboxClientRuby::Entities | ||
|
||
path 'dcim/manufacturers.json' | ||
data_key 'results' | ||
count_key 'count' | ||
entity_creator :entity_creator | ||
|
||
private | ||
|
||
def entity_creator(raw_entity) | ||
NetboxClientRuby::Manufacturer.new raw_entity['id'] | ||
end | ||
end | ||
end |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
require 'spec_helper' | ||
|
||
describe NetboxClientRuby::Manufacturer, faraday_stub: true do | ||
let(:entity_id) { 1 } | ||
let(:expected_name) { 'manu1' } | ||
let(:sut) { NetboxClientRuby::Manufacturer } | ||
let(:base_url) { '/api/dcim/manufacturers/' } | ||
let(:request_url) { "#{base_url}#{entity_id}.json" } | ||
let(:response) { File.read("spec/fixtures/dcim/manufacturer_#{entity_id}.json") } | ||
|
||
subject { sut.new entity_id } | ||
|
||
describe '#id' do | ||
it 'shall be the expected id' do | ||
expect(subject.id).to eq(entity_id) | ||
end | ||
end | ||
|
||
describe '#name' do | ||
it 'should fetch the data' do | ||
expect(faraday).to receive(:get).and_call_original | ||
|
||
subject.name | ||
end | ||
|
||
it 'shall be the expected name' do | ||
expect(subject.name).to eq(expected_name) | ||
end | ||
end | ||
|
||
describe '.delete' do | ||
let(:request_method) { :delete } | ||
let(:response_status) { 204 } | ||
let(:response) { nil } | ||
|
||
it 'should delete the object' do | ||
expect(faraday).to receive(request_method).and_call_original | ||
subject.delete | ||
end | ||
end | ||
|
||
describe '.update' do | ||
let(:request_method) { :patch } | ||
let(:request_params) { { 'name' => 'noob' } } | ||
|
||
it 'should update the object' do | ||
expect(faraday).to receive(request_method).and_call_original | ||
expect(subject.update(name: 'noob').name).to eq(expected_name) | ||
end | ||
end | ||
|
||
describe '.reload' do | ||
it 'should reload the object' do | ||
expect(faraday).to receive(request_method).twice.and_call_original | ||
|
||
subject.reload | ||
subject.reload | ||
end | ||
end | ||
|
||
describe '.save' do | ||
let(:name) { 'foobar' } | ||
let(:slug) { name } | ||
let(:request_params) { { 'name' => name, 'slug' => slug } } | ||
|
||
context 'update' do | ||
let(:request_method) { :patch } | ||
|
||
subject do | ||
region = sut.new entity_id | ||
region.name = name | ||
region.slug = slug | ||
region | ||
end | ||
|
||
it 'does not call PATCH until save is called' do | ||
expect(faraday).to_not receive(request_method) | ||
expect(faraday).to_not receive(:get) | ||
|
||
expect(subject.name).to eq(name) | ||
expect(subject.slug).to eq(slug) | ||
end | ||
|
||
it 'calls PATCH when save is called' do | ||
expect(faraday).to receive(request_method).and_call_original | ||
|
||
expect(subject.save).to be(subject) | ||
end | ||
|
||
it 'Reads the anwer from the PATCH answer' do | ||
expect(faraday).to receive(request_method).and_call_original | ||
|
||
subject.save | ||
expect(subject.name).to eq(expected_name) | ||
expect(subject.slug).to eq(expected_name) | ||
end | ||
end | ||
|
||
context 'create' do | ||
let(:request_method) { :post } | ||
let(:request_url) { base_url } | ||
|
||
subject do | ||
region = sut.new | ||
region.name = name | ||
region.slug = slug | ||
region | ||
end | ||
|
||
it 'does not POST until save is called' do | ||
expect(faraday).to_not receive(request_method) | ||
expect(faraday).to_not receive(:get) | ||
|
||
expect(subject.name).to eq(name) | ||
expect(subject.slug).to eq(slug) | ||
end | ||
|
||
it 'POSTs the data upon a call of save' do | ||
expect(faraday).to receive(request_method).and_call_original | ||
|
||
expect(subject.save).to be(subject) | ||
end | ||
|
||
it 'Reads the answer from the POST' do | ||
expect(faraday).to receive(request_method).and_call_original | ||
|
||
subject.save | ||
|
||
expect(subject.id).to be(1) | ||
expect(subject.name).to eq(expected_name) | ||
expect(subject.slug).to eq(expected_name) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'spec_helper' | ||
|
||
describe NetboxClientRuby::Regions, faraday_stub: true do | ||
let(:response) { File.read('spec/fixtures/dcim/regions.json') } | ||
let(:request_url) { '/api/dcim/regions.json' } | ||
let(:request_url_params) do | ||
{ limit: NetboxClientRuby.config.netbox.pagination.default_limit } | ||
end | ||
|
||
context 'unpaged fetch' do | ||
describe '#length' do | ||
it 'shall be the expected length' do | ||
expect(subject.length).to be 2 | ||
end | ||
end | ||
|
||
describe '#total' do | ||
it 'shall be the expected total' do | ||
expect(subject.total).to be 2 | ||
end | ||
end | ||
end | ||
|
||
describe '#reload' do | ||
it 'fetches the correct data' do | ||
expect(faraday).to receive(:get).and_call_original | ||
subject.reload | ||
end | ||
|
||
it 'caches the data' do | ||
expect(faraday).to receive(:get).and_call_original | ||
subject.total | ||
subject.total | ||
end | ||
|
||
it 'reloads the data' do | ||
expect(faraday).to receive(:get).twice.and_call_original | ||
subject.reload | ||
subject.reload | ||
end | ||
end | ||
|
||
describe '#as_array' do | ||
it 'return the correct amount' do | ||
expect(subject.as_array.length).to be 2 | ||
end | ||
|
||
it 'returns Site instances' do | ||
subject.as_array.each do |element| | ||
expect(element).to be_a NetboxClientRuby::Region | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters