Class: RHC::Rest::Mock::MockRestClient

Inherits:
Client show all
Includes:
Helpers
Defined in:
lib/rhc/rest/mock.rb

Constant Summary

Constants inherited from Client

Client::CLIENT_API_VERSIONS, Client::MAX_RETRIES

Constants included from Helpers

Helpers::BOUND_WARNING, Helpers::PREFIX, Helpers::ROLES

Instance Method Summary collapse

Methods included from Helpers

#challenge, #credentials_for, #define_exceptional_test_on_wizard, #empty_domains, #empty_keys, #empty_response_list, #example_allows_gear_sizes?, #example_allows_members?, #expect_authorization, #mock_alias_links, #mock_alias_response, #mock_api_with_authorizations, #mock_app_links, #mock_cart_links, #mock_cartridge_response, #mock_client_links, #mock_date_1, #mock_domain_links, #mock_gear_groups_response, #mock_href, #mock_key_links, #mock_pass, #mock_real_client_links, #mock_response_links, #mock_uri, #mock_user, #mock_user_auth, #mock_user_links, #new_authorization, #new_domain, #simple_carts, #simple_user, #stub_add_authorization, #stub_add_key, #stub_add_key_error, #stub_api, #stub_api_request, #stub_api_v12, #stub_application_cartridges, #stub_authorizations, #stub_create_domain, #stub_delete_authorization, #stub_delete_authorizations, #stub_mock_ssh_keys, #stub_no_domains, #stub_no_keys, #stub_one_application, #stub_one_domain, #stub_one_key, #stub_relative_application, #stub_simple_carts, #stub_update_key, #stub_user

Methods inherited from Client

#attempt, #request, #url

Methods included from Helpers

#agree, #certificate_file, #client_from_options, #collect_env_vars, #color, #confirm_action, #date, #datetime_rfc3339, #debug, #debug?, #debug_error, #decode_json, #deprecated, #deprecated_command, #disable_deprecated?, #distance_of_time_in_words, #env_var_regex_pattern, #error, #exec, #host_exists?, #hosts_file_contains?, #human_size, #info, #interactive?, #jruby?, #mac?, #pluralize, #protonbox_online_server?, #protonbox_rest_endpoint, #protonbox_server, #protonbox_url, #results, #role_name, #run_with_tee, #ssh_string, #ssh_string_parts, #ssl_options, #success, #system_path, #table_heading, #to_host, #to_uri, #token_for_user, #unix?, #user_agent, #warn, #windows?, #with_tolerant_encoding

Methods included from OutputHelpers

#default_display_env_var, #display_app, #display_app_configurations, #display_authorization, #display_cart, #display_cart_storage_info, #display_cart_storage_list, #display_deployment, #display_deployment_list, #display_domain, #display_env_var_list, #display_key, #format_cart_gears, #format_cart_header, #format_gear_info, #format_key_header, #format_scaling_info, #format_usage_message

Methods included from ApiMethods

#add_authorization, #applications, #authorization_scope_list, #authorizations, #delete_authorization, #delete_authorizations, #find_application_aliases, #find_cartridges, #find_domain, #find_key, #link_show_application_by_domain_name, #link_show_application_by_id, #link_show_domain_by_name, #new_session, #owned_domains, #reset, #supports_sessions?

Methods inherited from Base

#add_message, #has_param?, #link_href, #links, #rest_method, #supports?

Methods included from AttributesClass

#define_attr, #model_name

Methods included from Attributes

#attribute, #attributes, #attributes=, #clear_attribute

Constructor Details

#initialize(config = RHC::Config, version = 1.0) ⇒ MockRestClient

Returns a new instance of MockRestClient.



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/rhc/rest/mock.rb', line 521

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 = []
  @user = MockRestUser.new(self, config.username)
  @api = MockRestApi.new(self, config)
  @version = version
end

Instance Method Details

#add_domain(id, extra = false) ⇒ Object



573
574
575
576
577
578
579
580
581
582
# File 'lib/rhc/rest/mock.rb', line 573

def add_domain(id, extra=false)
  d = MockRestDomain.new(self, id)
  if extra
    d.attributes['creation_time'] = '2013-07-21T15:00:44Z'
    d.attributes['members'] = [{'owner' => true, 'name' => 'a_user_name'}]
    d.attributes['allowed_gear_sizes'] = ['small']
  end
  @domains << d
  d
end

#add_key(name, type, content) ⇒ Object



588
589
590
# File 'lib/rhc/rest/mock.rb', line 588

def add_key(name, type, content)
  @user.add_key(name, type, content)
end

#apiObject



539
540
541
# File 'lib/rhc/rest/mock.rb', line 539

def api
  @api
end

#api_version_negotiatedObject



551
552
553
# File 'lib/rhc/rest/mock.rb', line 551

def api_version_negotiated
  @version
end

#cartridgesObject



555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
# File 'lib/rhc/rest/mock.rb', line 555

def cartridges
  premium_embedded = MockRestCartridge.new(self, "premium_cart", "embedded")
  premium_embedded.usage_rate = 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

#delete_key(name) ⇒ Object



592
593
594
# File 'lib/rhc/rest/mock.rb', line 592

def delete_key(name)
  @user.keys.delete_if { |key| key.name == name }
end

#domainsObject



547
548
549
# File 'lib/rhc/rest/mock.rb', line 547

def domains
  @domains
end

#find_application(domain, name, options = {}) ⇒ Object

Need to mock this since we are not registering HTTP requests when adding apps to the mock domain



597
598
599
600
601
602
603
# File 'lib/rhc/rest/mock.rb', line 597

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

#find_application_by_id(id, options = {}) ⇒ Object



613
614
615
616
# File 'lib/rhc/rest/mock.rb', line 613

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

#find_application_by_id_gear_groups(id, options = {}) ⇒ Object



618
619
620
621
# File 'lib/rhc/rest/mock.rb', line 618

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

#find_application_gear_groups(domain, name, options = {}) ⇒ Object



605
606
607
608
609
610
611
# File 'lib/rhc/rest/mock.rb', line 605

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

#sshkeysObject



584
585
586
# File 'lib/rhc/rest/mock.rb', line 584

def sshkeys
  @user.keys
end

#userObject



543
544
545
# File 'lib/rhc/rest/mock.rb', line 543

def user
  @user
end