# File lib/rhc/rest/mock.rb, line 560 def initialize(config=RHC::Config, version=1.0) obj = self if RHC::Rest::Client.respond_to?(:stub) RHC::Rest::Client.stub(:new) { obj } else RHC::Rest::Client.instance_eval do @obj = obj def new(*args) @obj end end end @domains = [] @teams = [] @user = MockRestUser.new(self, config.username) @api = MockRestApi.new(self, config) @version = version end
# File lib/rhc/rest/mock.rb, line 626 def add_domain(id, extra=false) d = MockRestDomain.new(self, id) if extra d.attributes['creation_time'] = '2013-07-21T15:00:44Z' d.attributes['allowed_gear_sizes'] = ['small'] d.add_member(RHC::Rest::Membership::Member.new(:id => '1', :role => 'admin', :explicit_role => 'admin', :owner => true, :login => 'a_user_name', :type => 'user')) end @domains << d d end
# File lib/rhc/rest/mock.rb, line 641 def add_key(name, type, content) @user.add_key(name, type, content) end
# File lib/rhc/rest/mock.rb, line 617 def add_team(name, extra=false) t = MockRestTeam.new(self, name) if extra t.attributes['members'] = [{'owner' => true, 'name' => 'a_user_name'}] end @teams << t t end
# File lib/rhc/rest/mock.rb, line 579 def api @api end
# File lib/rhc/rest/mock.rb, line 595 def api_version_negotiated @version end
# File lib/rhc/rest/mock.rb, line 599 def cartridges premium_embedded = MockRestCartridge.new(self, "premium_cart", "embedded") premium_embedded.usage_rates = {0.05 => []} [MockRestCartridge.new(self, "mock_cart-1", "embedded"), # code should sort this to be after standalone MockRestCartridge.new(self, "mock_standalone_cart-1", "standalone"), MockRestCartridge.new(self, "mock_standalone_cart-2", "standalone"), MockRestCartridge.new(self, "mock_unique_standalone_cart-1", "standalone"), MockRestCartridge.new(self, "jenkins-1", "standalone", nil, ['ci']), MockRestCartridge.new(self, "mock_cart-2", "embedded"), MockRestCartridge.new(self, "unique_mock_cart-1", "embedded"), MockRestCartridge.new(self, "jenkins-client-1", "embedded", nil, ['ci_builder']), MockRestCartridge.new(self, "embcart-1", "embedded"), MockRestCartridge.new(self, "embcart-2", "embedded"), premium_embedded ] end
# File lib/rhc/rest/mock.rb, line 645 def delete_key(name) @user.keys.delete_if { |key| key.name == name } end
# File lib/rhc/rest/mock.rb, line 587 def domains @domains end
Need to mock this since we are not registering HTTP requests when adding apps to the mock domain
# File lib/rhc/rest/mock.rb, line 650 def find_application(domain, name, options = {}) find_domain(domain).applications.each do |app| return app if app.name.downcase == name.downcase end raise RHC::Rest::ApplicationNotFoundException.new("Application #{name} does not exist") end
# File lib/rhc/rest/mock.rb, line 674 def find_application_by_id(id, options={}) @domains.each{ |d| d.applications.each{ |a| return a if a.id == id } } raise RHC::Rest::ApplicationNotFoundException.new("Application with id #{id} does not exist") end
# File lib/rhc/rest/mock.rb, line 679 def find_application_by_id_gear_groups(id, options={}) @domains.each{ |d| d.applications.each{ |a| return a.gear_groups if a.id == id } } raise RHC::Rest::ApplicationNotFoundException.new("Application with id #{id} does not exist") end
# File lib/rhc/rest/mock.rb, line 666 def find_application_gear_groups(domain, name, options = {}) find_domain(domain).applications.each do |app| return app.gear_groups if app.name.downcase == name.downcase end raise RHC::Rest::ApplicationNotFoundException.new("Application #{name} does not exist") end
# File lib/rhc/rest/mock.rb, line 658 def find_application_gear_groups_endpoints(domain, name, options = {}) find_domain(domain).applications.each do |app| return app.gear_groups if app.name.downcase == name.downcase end raise RHC::Rest::ApplicationNotFoundException.new("Application #{name} does not exist") end
# File lib/rhc/rest/mock.rb, line 567 def new(*args) @obj end
# File lib/rhc/rest/mock.rb, line 637 def sshkeys @user.keys end
# File lib/rhc/rest/mock.rb, line 591 def teams(opts={}) @teams end
# File lib/rhc/rest/mock.rb, line 583 def user @user end