Module: RHC::Rest::Mock::Helpers
- Included in:
- MockRestAlias, MockRestApi, MockRestApplication, MockRestCartridge, MockRestClient, MockRestDomain, MockRestGearGroup, MockRestKey, MockRestUser
- Defined in:
- lib/rhc/rest/mock.rb
Instance Method Summary collapse
- #challenge(&block) ⇒ Object
- #credentials_for(with_auth) ⇒ Object
- #define_exceptional_test_on_wizard ⇒ Object
- #empty_domains ⇒ Object
- #empty_keys ⇒ Object
- #empty_response_list(type) ⇒ Object
- #example_allows_gear_sizes? ⇒ Boolean
- #example_allows_members? ⇒ Boolean
- #expect_authorization(with_auth) ⇒ Object
- #mock_alias_links(domain_id = 'test_domain', app_id = 'test_app', alias_id = 'test.foo.com') ⇒ Object
- #mock_alias_response(count = 1) ⇒ Object
- #mock_api_with_authorizations ⇒ Object
- #mock_app_links(domain_id = 'test_domain', app_id = 'test_app') ⇒ Object
- #mock_cart_links(domain_id = 'test_domain', app_id = 'test_app', cart_id = 'test_cart') ⇒ Object
- #mock_cartridge_response(cart_count = 1, url = false) ⇒ Object
- #mock_client_links ⇒ Object
- #mock_date_1 ⇒ Object
- #mock_domain_links(domain_id = 'test_domain') ⇒ Object
- #mock_gear_groups_response ⇒ Object
-
#mock_href(relative = "", with_auth = false) ⇒ Object
Creates consistent hrefs for testing.
- #mock_key_links(key_id = 'test_key') ⇒ Object
- #mock_pass ⇒ Object
- #mock_real_client_links ⇒ Object
- #mock_response_links(links) ⇒ Object
- #mock_uri ⇒ Object
- #mock_user ⇒ Object
- #mock_user_auth ⇒ Object
- #mock_user_links ⇒ Object
- #new_authorization(params) ⇒ Object
- #new_domain(name) ⇒ Object
- #simple_carts ⇒ Object
- #simple_user(login) ⇒ Object
- #stub_add_authorization(params) ⇒ Object
- #stub_add_key(name = 'default') ⇒ Object
- #stub_add_key_error(name, message, code = 422) ⇒ Object
- #stub_api(auth = false, authorizations = false) ⇒ Object
- #stub_api_request(method, uri, with_auth = true) ⇒ Object
- #stub_api_v12(auth = false) ⇒ Object
- #stub_application_cartridges(domain_name, app_name, cartridges, status = 200) ⇒ Object
- #stub_authorizations ⇒ Object
- #stub_create_domain(name) ⇒ Object
- #stub_delete_authorization(token) ⇒ Object
- #stub_delete_authorizations ⇒ Object
- #stub_mock_ssh_keys(name = 'test') ⇒ Object
- #stub_no_domains(with_auth = mock_user_auth) ⇒ Object
- #stub_no_keys ⇒ Object
- #stub_one_application(domain_name, name, *args) ⇒ Object
- #stub_one_domain(name, optional_params = nil, with_auth = mock_user_auth) ⇒ Object
- #stub_one_key(name) ⇒ Object
- #stub_relative_application(domain_name, app_name, body = {}, status = 200) ⇒ Object
- #stub_simple_carts(with_auth = mock_user_auth) ⇒ Object
- #stub_update_key(name) ⇒ Object
- #stub_user(auth = mock_user_auth) ⇒ Object
Instance Method Details
#challenge(&block) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/rhc/rest/mock.rb', line 80 def challenge(&block) @challenge = true yield ensure @challenge = false end |
#credentials_for(with_auth) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/rhc/rest/mock.rb', line 47 def credentials_for(with_auth) if with_auth == true [respond_to?(:username) ? self.username : mock_user, respond_to?(:password) ? self.password : mock_pass] elsif with_auth with_auth.values_at(:user, :password) end end |
#define_exceptional_test_on_wizard ⇒ Object
274 275 276 277 278 279 280 281 |
# File 'lib/rhc/rest/mock.rb', line 274 def define_exceptional_test_on_wizard RHC::Wizard.module_eval <<-EOM private def test_and_raise raise end EOM end |
#empty_domains ⇒ Object
286 287 288 |
# File 'lib/rhc/rest/mock.rb', line 286 def empty_domains empty_response_list('domains') end |
#empty_keys ⇒ Object
283 284 285 |
# File 'lib/rhc/rest/mock.rb', line 283 def empty_keys empty_response_list('keys') end |
#empty_response_list(type) ⇒ Object
290 291 292 293 294 295 296 297 |
# File 'lib/rhc/rest/mock.rb', line 290 def empty_response_list(type) { :body => { :type => type, :data => [], }.to_json } end |
#example_allows_gear_sizes? ⇒ Boolean
58 59 60 |
# File 'lib/rhc/rest/mock.rb', line 58 def example_allows_gear_sizes? respond_to?(:supports_allowed_gear_sizes?) && supports_allowed_gear_sizes? end |
#example_allows_members? ⇒ Boolean
55 56 57 |
# File 'lib/rhc/rest/mock.rb', line 55 def example_allows_members? respond_to?(:supports_members?) && supports_members? end |
#expect_authorization(with_auth) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/rhc/rest/mock.rb', line 62 def (with_auth) username, password = credentials_for(with_auth) lambda{ |r| !username || (r.headers['Authorization'] == "Basic #{["#{username}:#{password}"].pack('m').tr("\n", '')}") } end |
#mock_alias_links(domain_id = 'test_domain', app_id = 'test_app', alias_id = 'test.foo.com') ⇒ Object
461 462 463 464 465 |
# File 'lib/rhc/rest/mock.rb', line 461 def mock_alias_links(domain_id='test_domain',app_id='test_app',alias_id='test.foo.com') [['DELETE', "domains/#{domain_id}/apps/#{app_id}/aliases/#{alias_id}/delete", 'post'], ['GET', "domains/#{domain_id}/apps/#{app_id}/aliases/#{alias_id}", 'get' ], ['UPDATE', "domains/#{domain_id}/apps/#{app_id}/aliases/#{alias_id}/update", 'post' ]] end |
#mock_alias_response(count = 1) ⇒ Object
490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/rhc/rest/mock.rb', line 490 def mock_alias_response(count=1) aliases = count.times.inject([]) do |arr, i| arr << {:id => "www.alias#{i}.com"} end return { :body => { :type => count == 1 ? 'alias' : 'aliases', :data => aliases }.to_json, :status => 200 } end |
#mock_api_with_authorizations ⇒ Object
436 437 438 439 440 441 442 |
# File 'lib/rhc/rest/mock.rb', line 436 def mock_real_client_links.concat([ ['LIST_AUTHORIZATIONS', "broker/rest/user/authorizations", 'GET'], ['ADD_AUTHORIZATION', "broker/rest/user/authorizations", 'POST'], ['SHOW_AUTHORIZATION', "broker/rest/user/authorizations/:id", 'GET'], ]) end |
#mock_app_links(domain_id = 'test_domain', app_id = 'test_app') ⇒ Object
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/rhc/rest/mock.rb', line 391 def mock_app_links(domain_id='test_domain',app_id='test_app') [['ADD_CARTRIDGE', "domains/#{domain_id}/apps/#{app_id}/carts/add", 'post', {'optional_params' => [{'name' => 'environment_variables'}]} ], ['LIST_CARTRIDGES', "broker/rest/domains/#{domain_id}/applications/#{app_id}/cartridges", 'get' ], ['GET_GEAR_GROUPS', "domains/#{domain_id}/apps/#{app_id}/gear_groups", 'get' ], ['START', "domains/#{domain_id}/apps/#{app_id}/start", 'post'], ['STOP', "domains/#{domain_id}/apps/#{app_id}/stop", 'post'], ['RESTART', "domains/#{domain_id}/apps/#{app_id}/restart", 'post'], ['THREAD_DUMP', "domains/#{domain_id}/apps/#{app_id}/event", 'post'], ['ADD_ALIAS', "domains/#{domain_id}/apps/#{app_id}/event", 'post'], ['REMOVE_ALIAS', "domains/#{domain_id}/apps/#{app_id}/event", 'post'], ['LIST_ALIASES', "domains/#{domain_id}/apps/#{app_id}/aliases", 'get'], ['LIST_ENVIRONMENT_VARIABLES', "domains/#{domain_id}/apps/#{app_id}/event", 'post'], ['SET_UNSET_ENVIRONMENT_VARIABLES', "domains/#{domain_id}/apps/#{app_id}/event", 'post'], ['DELETE', "broker/rest/domains/#{domain_id}/applications/#{app_id}", 'delete'], (['LIST_MEMBERS', "domains/#{domain_id}/apps/#{app_id}/members", 'get'] if example_allows_members?), ['UPDATE', "broker/rest/domain/#{domain_id}/application/#{app_id}", 'put'], ['LIST_DEPLOYMENTS', "broker/rest/domain/#{domain_id}/application/#{app_id}/deployments", 'get' ], ['UPDATE_DEPLOYMENTS', "broker/rest/domain/#{domain_id}/application/#{app_id}/deployments", 'post' ], ['ACTIVATE', "broker/rest/domain/#{domain_id}/application/#{app_id}/events", 'post'], ['DEPLOY', "broker/rest/domain/#{domain_id}/application/#{app_id}/deployments", 'post'] ].compact end |
#mock_cart_links(domain_id = 'test_domain', app_id = 'test_app', cart_id = 'test_cart') ⇒ Object
414 415 416 417 418 419 |
# File 'lib/rhc/rest/mock.rb', line 414 def mock_cart_links(domain_id='test_domain',app_id='test_app',cart_id='test_cart') [['START', "domains/#{domain_id}/apps/#{app_id}/carts/#{cart_id}/start", 'post'], ['STOP', "domains/#{domain_id}/apps/#{app_id}/carts/#{cart_id}/stop", 'post'], ['RESTART', "domains/#{domain_id}/apps/#{app_id}/carts/#{cart_id}/restart", 'post'], ['DELETE', "broker/rest/domains/#{domain_id}/applications/#{app_id}/cartridges/#{cart_id}", 'DELETE']] end |
#mock_cartridge_response(cart_count = 1, url = false) ⇒ Object
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 |
# File 'lib/rhc/rest/mock.rb', line 467 def mock_cartridge_response(cart_count=1, url=false) carts = [] while carts.length < cart_count carts << { :name => "mock_cart_#{carts.length}", :url => url ? "http://a.url/#{carts.length}" : nil, :type => carts.empty? ? 'standalone' : 'embedded', :links => mock_response_links(mock_cart_links('mock_domain','mock_app',"mock_cart_#{carts.length}")) } end carts = carts[0] if cart_count == 1 type = cart_count == 1 ? 'cartridge' : 'cartridges' return { :body => { :type => type, :data => carts }.to_json, :status => 200 } end |
#mock_client_links ⇒ Object
421 422 423 424 425 426 |
# File 'lib/rhc/rest/mock.rb', line 421 def mock_client_links [['GET_USER', 'user/', 'get' ], ['ADD_DOMAIN', 'domains/add', 'post'], ['LIST_DOMAINS', 'domains/', 'get' ], ['LIST_CARTRIDGES', 'cartridges/', 'get' ]] end |
#mock_date_1 ⇒ Object
35 36 37 |
# File 'lib/rhc/rest/mock.rb', line 35 def mock_date_1 '2013-02-21T01:00:01Z' end |
#mock_domain_links(domain_id = 'test_domain') ⇒ Object
444 445 446 447 448 449 |
# File 'lib/rhc/rest/mock.rb', line 444 def mock_domain_links(domain_id='test_domain') [['ADD_APPLICATION', "domains/#{domain_id}/apps/add", 'post', {'optional_params' => [{'name' => 'environment_variables'}]} ], ['LIST_APPLICATIONS', "domains/#{domain_id}/apps/", 'get' ], ['UPDATE', "domains/#{domain_id}/update", 'put'], ['DELETE', "domains/#{domain_id}/delete", 'post']] end |
#mock_gear_groups_response ⇒ Object
504 505 506 507 508 509 510 511 512 513 514 515 |
# File 'lib/rhc/rest/mock.rb', line 504 def mock_gear_groups_response() groups = [{}] type = 'gear_groups' return { :body => { :type => type, :data => groups }.to_json, :status => 200 } end |
#mock_href(relative = "", with_auth = false) ⇒ Object
Creates consistent hrefs for testing
369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/rhc/rest/mock.rb', line 369 def mock_href(relative="", with_auth=false) server = respond_to?(:server) ? self.server : mock_uri user, pass = credentials_for(with_auth) uri_string = if user "#{user}:#{pass}@#{server}" else server end "https://#{uri_string}/#{relative}" end |
#mock_key_links(key_id = 'test_key') ⇒ Object
451 452 453 454 |
# File 'lib/rhc/rest/mock.rb', line 451 def mock_key_links(key_id='test_key') [['UPDATE', "user/keys/#{key_id}/update", 'post'], ['DELETE', "user/keys/#{key_id}/delete", 'post']] end |
#mock_pass ⇒ Object
360 361 362 |
# File 'lib/rhc/rest/mock.rb', line 360 def mock_pass "test pass" end |
#mock_real_client_links ⇒ Object
428 429 430 431 432 433 434 |
# File 'lib/rhc/rest/mock.rb', line 428 def mock_real_client_links [['GET_USER', "broker/rest/user", 'GET'], ['LIST_DOMAINS', "broker/rest/domains", 'GET'], ['ADD_DOMAIN', "broker/rest/domains", 'POST', ({'optional_params' => [{'name' => 'allowed_gear_sizes'}]} if example_allows_gear_sizes?)].compact, ['LIST_CARTRIDGES', "broker/rest/cartridges", 'GET'], ] end |
#mock_response_links(links) ⇒ Object
382 383 384 385 386 387 388 389 |
# File 'lib/rhc/rest/mock.rb', line 382 def mock_response_links(links) link_set = {} links.each do |link| = link[3] || {} link_set[link[0]] = { 'href' => mock_href(link[1]), 'method' => link[2], 'relative' => link[1]}.merge() end link_set end |
#mock_uri ⇒ Object
364 365 366 |
# File 'lib/rhc/rest/mock.rb', line 364 def mock_uri "test.domain.com" end |
#mock_user ⇒ Object
39 40 41 |
# File 'lib/rhc/rest/mock.rb', line 39 def mock_user "test_user" end |
#mock_user_auth ⇒ Object
43 44 45 |
# File 'lib/rhc/rest/mock.rb', line 43 def mock_user_auth respond_to?(:user_auth) ? self.user_auth : {:user => username, :password => password} end |
#mock_user_links ⇒ Object
456 457 458 459 |
# File 'lib/rhc/rest/mock.rb', line 456 def mock_user_links [['ADD_KEY', 'user/keys/add', 'post'], ['LIST_KEYS', 'user/keys/', 'get' ]] end |
#new_authorization(params) ⇒ Object
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/rhc/rest/mock.rb', line 343 def (params) { :status => 201, :body => { :type => 'authorization', :data => { :note => params[:note], :token => 'a_token_value', :scopes => (params[:scope] || "userinfo").gsub(/,/, ' '), :expires_in => (params[:expires_in] || 60).to_i, :expires_in_seconds => (params[:expires_in] || 60).to_i, :created_at => mock_date_1, }, }.to_json } end |
#new_domain(name) ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/rhc/rest/mock.rb', line 299 def new_domain(name) { :status => 201, :body => { :type => 'domain', :data => { :id => name, :links => mock_response_links([ ]) }, }.to_json } end |
#simple_carts ⇒ Object
312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/rhc/rest/mock.rb', line 312 def simple_carts { :body => { :type => 'cartridges', :data => [ {:name => 'mock_standalone_cart-1', :type => 'standalone', :tags => ['cartridge'], :display_name => 'Mock1 Cart'}, {:name => 'mock_standalone_cart-2', :type => 'standalone', :description => 'Mock2 description'}, {:name => 'mock_embedded_cart-1', :type => 'embedded', :tags => ['scheduled'], :display_name => 'Mock1 Embedded Cart'}, {:name => 'premium_cart-1', :type => 'standalone', :tags => ['premium'], :display_name => 'Premium Cart', :usage_rate_usd => '0.02'}, ], }.to_json } end |
#simple_user(login) ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/rhc/rest/mock.rb', line 325 def simple_user(login) { :body => { :type => 'user', :data => { :login => login, :plan_id => respond_to?(:user_plan_id) ? self.user_plan_id : nil, :consumed_gears => respond_to?(:user_consumed_gears) ? self.user_consumed_gears : 0, :max_gears => respond_to?(:user_max_gears) ? self.user_max_gears : 3, :capabilities => respond_to?(:user_capabilities) ? self.user_capabilities : {:gear_sizes => ['small', 'medium']}, :links => mock_response_links([ ['ADD_KEY', "broker/rest/user/keys", 'POST'], ['LIST_KEYS', "broker/rest/user/keys", 'GET'], ]) }, }.to_json } end |
#stub_add_authorization(params) ⇒ Object
158 159 160 161 162 |
# File 'lib/rhc/rest/mock.rb', line 158 def (params) stub_api_request(:post, 'broker/rest/user/authorizations', mock_user_auth). with(:body => hash_including(params)). to_return((params)) end |
#stub_add_key(name = 'default') ⇒ Object
108 109 110 111 112 |
# File 'lib/rhc/rest/mock.rb', line 108 def stub_add_key(name='default') stub_api_request(:post, 'broker/rest/user/keys', mock_user_auth). with(:body => hash_including({:name => name, :type => 'ssh-rsa'})). to_return({:status => 201, :body => {}.to_json}) end |
#stub_add_key_error(name, message, code = 422) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/rhc/rest/mock.rb', line 118 def stub_add_key_error(name, , code=422) stub_api_request(:post, "broker/rest/user/keys", mock_user_auth). with(:body => hash_including({:name => name, :type => 'ssh-rsa'})). to_return({:status => code, :body => {:messages => [ {:text => , :field => 'name', :severity => 'error'}, {:text => "A warning from the server", :field => nil, :severity => 'warning'}, ] }.to_json}) end |
#stub_api(auth = false, authorizations = false) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/rhc/rest/mock.rb', line 87 def stub_api(auth=false, =false) stub_api_request(:get, 'broker/rest/api', auth). to_return({ :body => { :data => mock_response_links( ? : mock_real_client_links), :supported_api_versions => [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6], }.to_json }) end |
#stub_api_request(method, uri, with_auth = true) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rhc/rest/mock.rb', line 69 def stub_api_request(method, uri, with_auth=true) api = stub_request(method, mock_href(uri, with_auth)) api.with(&lambda{ |r| request.headers['Authorization'] == "Bearer #{with_auth[:token]}" }) if with_auth.respond_to?(:[]) && with_auth[:token] api.with(&(with_auth)) api.with(&user_agent_header) if @challenge stub_request(method, mock_href(uri, false)).to_return(:status => 401, :headers => {'www-authenticate' => 'basic realm="protonbox broker"'}) end api end |
#stub_api_v12(auth = false) ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/rhc/rest/mock.rb', line 96 def stub_api_v12(auth=false) stub_api_request(:get, 'broker/rest/api', auth). to_return({ :body => { :data => mock_response_links(mock_real_client_links), :supported_api_versions => [1.0, 1.1, 1.2], }.to_json }) end |
#stub_application_cartridges(domain_name, app_name, cartridges, status = 200) ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/rhc/rest/mock.rb', line 255 def stub_application_cartridges(domain_name, app_name, cartridges, status = 200) url = client_links['LIST_DOMAINS']['relative'] rescue "broker/rest/domains" stub_api_request(:any, "#{url}/#{domain_name}/applications/#{app_name}/cartridges"). to_return({ :body => { :type => 'cartridges', :data => cartridges.map{ |c| c.is_a?(String) ? {:name => c} : c }.map do |cart| cart[:links] ||= mock_response_links(mock_cart_links(domain_name,app_name, cart[:name])) cart end }.to_json, :status => status }) end |
#stub_authorizations ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/rhc/rest/mock.rb', line 132 def stub_api_request(:get, 'broker/rest/user/authorizations', mock_user_auth). to_return({ :status => 200, :body => { :type => 'authorizations', :data => [ { :note => 'an_authorization', :token => 'a_token_value', :created_at => mock_date_1, :expires_in_seconds => 60, :scopes => 'session read' } ] }.to_json }) end |
#stub_create_domain(name) ⇒ Object
127 128 129 130 131 |
# File 'lib/rhc/rest/mock.rb', line 127 def stub_create_domain(name) stub_api_request(:post, 'broker/rest/domains', mock_user_auth). with(:body => hash_including({:id => name})). to_return(new_domain(name)) end |
#stub_delete_authorization(token) ⇒ Object
154 155 156 157 |
# File 'lib/rhc/rest/mock.rb', line 154 def (token) stub_api_request(:delete, "broker/rest/user/authorizations/#{token}", mock_user_auth). to_return(:status => 204) end |
#stub_delete_authorizations ⇒ Object
150 151 152 153 |
# File 'lib/rhc/rest/mock.rb', line 150 def stub_api_request(:delete, 'broker/rest/user/authorizations', mock_user_auth). to_return(:status => 204) end |
#stub_mock_ssh_keys(name = 'test') ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/rhc/rest/mock.rb', line 166 def stub_mock_ssh_keys(name='test') stub_api_request(:get, 'broker/rest/user/keys', mock_user_auth). to_return({ :body => { :type => 'keys', :data => [ { :name => name, :type => pub_key.split[0], :content => pub_key.split[1], # :links => mock_response_links([ # ['UPDATE', "broker/rest/user/keys/#{name}", 'put'] # ]), } ], }.to_json }) end |
#stub_no_domains(with_auth = mock_user_auth) ⇒ Object
202 203 204 |
# File 'lib/rhc/rest/mock.rb', line 202 def stub_no_domains(with_auth=mock_user_auth) stub_api_request(:get, 'broker/rest/domains', with_auth).to_return(empty_domains) end |
#stub_no_keys ⇒ Object
163 164 165 |
# File 'lib/rhc/rest/mock.rb', line 163 def stub_no_keys stub_api_request(:get, 'broker/rest/user/keys', mock_user_auth).to_return(empty_keys) end |
#stub_one_application(domain_name, name, *args) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/rhc/rest/mock.rb', line 219 def stub_one_application(domain_name, name, *args) stub_api_request(:get, "broker/rest/domains/#{domain_name}/applications", mock_user_auth). to_return({ :body => { :type => 'applications', :data => [{ :domain_id => domain_name, :id => 1, :name => name, :ssh_url => "ssh://12345@#{name}-#{domain_name}.protonbox.me", :app_url => "http://#{name}-#{domain_name}.protonbox.me", :links => mock_response_links([ ]), }], }.to_json }) stub_relative_application(domain_name,name, *args) end |
#stub_one_domain(name, optional_params = nil, with_auth = mock_user_auth) ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/rhc/rest/mock.rb', line 205 def stub_one_domain(name, optional_params=nil, with_auth=mock_user_auth) stub_api_request(:get, 'broker/rest/domains', with_auth). to_return({ :body => { :type => 'domains', :data => [{:id => name, :links => mock_response_links(mock_domain_links(name).concat([ ['LIST_APPLICATIONS', "broker/rest/domains/#{name}/applications", 'get'], ['ADD_APPLICATION', "broker/rest/domains/#{name}/applications", 'post', ({:optional_params => optional_params} if optional_params)], (['LIST_MEMBERS', "broker/rest/domains/#{name}/members", 'get'] if example_allows_members?), (['UPDATE_MEMBERS', "broker/rest/domains/#{name}/members", 'patch'] if example_allows_members?), ].compact))}], }.to_json }) end |
#stub_one_key(name) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/rhc/rest/mock.rb', line 184 def stub_one_key(name) stub_api_request(:get, 'broker/rest/user/keys', mock_user_auth). to_return({ :body => { :type => 'keys', :data => [ { :name => name, :type => 'ssh-rsa', :content => rsa_key_content_public, :links => mock_response_links([ ['UPDATE', "broker/rest/user/keys/#{name}", 'put'] ]), } ], }.to_json }) end |
#stub_relative_application(domain_name, app_name, body = {}, status = 200) ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/rhc/rest/mock.rb', line 238 def stub_relative_application(domain_name, app_name, body = {}, status = 200) url = client_links['LIST_DOMAINS']['relative'] rescue "broker/rest/domains" stub_api_request(:any, "#{url}/#{domain_name}/applications/#{app_name}"). to_return({ :body => { :type => 'application', :data => { :domain_id => domain_name, :name => app_name, :id => 1, :links => mock_response_links(mock_app_links(domain_name,app_name)), } }.merge(body).to_json, :status => status }) end |
#stub_simple_carts(with_auth = mock_user_auth) ⇒ Object
270 271 272 |
# File 'lib/rhc/rest/mock.rb', line 270 def stub_simple_carts(with_auth=mock_user_auth) stub_api_request(:get, 'broker/rest/cartridges', with_auth).to_return(simple_carts) end |
#stub_update_key(name) ⇒ Object
113 114 115 116 117 |
# File 'lib/rhc/rest/mock.rb', line 113 def stub_update_key(name) stub_api_request(:put, "broker/rest/user/keys/#{name}", mock_user_auth). with(:body => hash_including({:type => 'ssh-rsa'})). to_return({:status => 200, :body => {}.to_json}) end |
#stub_user(auth = mock_user_auth) ⇒ Object
105 106 107 |
# File 'lib/rhc/rest/mock.rb', line 105 def stub_user(auth=mock_user_auth) stub_api_request(:get, 'broker/rest/user', auth).to_return(simple_user(username)) end |