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_team_links, #mock_teams_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?, #openshift_online_server?, #openshift_rest_endpoint, #openshift_server, #openshift_url, #pluralize, #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, #display_team, #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, #find_team, #find_team_by_id, #link_show_application_by_domain_name, #link_show_application_by_id, #link_show_domain_by_name, #link_show_team_by_id, #new_session, #owned_applications, #owned_domains, #owned_teams, #precheck_application_id, #precheck_domain_id, #precheck_team_id, #reset, #search_owned_teams, #search_teams, #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.



546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
# File 'lib/rhc/rest/mock.rb', line 546

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

Instance Method Details

#add_domain(id, extra = false) ⇒ Object



612
613
614
615
616
617
618
619
620
621
# File 'lib/rhc/rest/mock.rb', line 612

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



627
628
629
# File 'lib/rhc/rest/mock.rb', line 627

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

#add_team(name, extra = false) ⇒ Object



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

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

#apiObject



565
566
567
# File 'lib/rhc/rest/mock.rb', line 565

def api
  @api
end

#api_version_negotiatedObject



581
582
583
# File 'lib/rhc/rest/mock.rb', line 581

def api_version_negotiated
  @version
end

#cartridgesObject



585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
# File 'lib/rhc/rest/mock.rb', line 585

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



631
632
633
# File 'lib/rhc/rest/mock.rb', line 631

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

#domainsObject



573
574
575
# File 'lib/rhc/rest/mock.rb', line 573

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



636
637
638
639
640
641
642
# File 'lib/rhc/rest/mock.rb', line 636

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



652
653
654
655
# File 'lib/rhc/rest/mock.rb', line 652

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



657
658
659
660
# File 'lib/rhc/rest/mock.rb', line 657

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



644
645
646
647
648
649
650
# File 'lib/rhc/rest/mock.rb', line 644

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



623
624
625
# File 'lib/rhc/rest/mock.rb', line 623

def sshkeys
  @user.keys
end

#teams(opts = {}) ⇒ Object



577
578
579
# File 'lib/rhc/rest/mock.rb', line 577

def teams(opts={})
  @teams
end

#userObject



569
570
571
# File 'lib/rhc/rest/mock.rb', line 569

def user
  @user
end