Module: RHC::Rest::Mock::Helpers

Instance Method Summary collapse

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_wizardObject



279
280
281
282
283
284
285
286
# File 'lib/rhc/rest/mock.rb', line 279

def define_exceptional_test_on_wizard
  RHC::Wizard.module_eval <<-EOM
  private
  def test_and_raise
    raise
  end
  EOM
end

#empty_domainsObject



291
292
293
# File 'lib/rhc/rest/mock.rb', line 291

def empty_domains
  empty_response_list('domains')
end

#empty_keysObject



288
289
290
# File 'lib/rhc/rest/mock.rb', line 288

def empty_keys
  empty_response_list('keys')
end

#empty_response_list(type) ⇒ Object



295
296
297
298
299
300
301
302
# File 'lib/rhc/rest/mock.rb', line 295

def empty_response_list(type)
  {
    :body => {
      :type => type,
      :data => [],
    }.to_json
  }
end

#example_allows_gear_sizes?Boolean

Returns:

  • (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

Returns:

  • (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 expect_authorization(with_auth)
  username, password = credentials_for(with_auth)
  lambda{ |r|
    !username || (r.headers['Authorization'] == "Basic #{["#{username}:#{password}"].pack('m').tr("\n", '')}")
  }
end


486
487
488
489
490
# File 'lib/rhc/rest/mock.rb', line 486

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



515
516
517
518
519
520
521
522
523
524
525
526
527
# File 'lib/rhc/rest/mock.rb', line 515

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_authorizationsObject



452
453
454
455
456
457
458
# File 'lib/rhc/rest/mock.rb', line 452

def mock_api_with_authorizations
  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


396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'lib/rhc/rest/mock.rb', line 396

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'],
   ['SCALE_UP',                        "broker/rest/application/#{app_id}/events",                           'scale-up'],
   ['SCALE_DOWN',                      "broker/rest/application/#{app_id}/events",                           'scale-down'],
   ['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


421
422
423
424
425
426
# File 'lib/rhc/rest/mock.rb', line 421

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



492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/rhc/rest/mock.rb', line 492

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


428
429
430
431
432
433
434
435
# File 'lib/rhc/rest/mock.rb', line 428

def mock_client_links
  mock_teams_links.concat([
   ['GET_USER',        'user/',       'get' ],
   ['ADD_DOMAIN',      'domains/add', 'post'],
   ['LIST_DOMAINS',    'domains/',    'get' ],
   ['LIST_CARTRIDGES', 'cartridges/', 'get' ]
  ])
end

#mock_date_1Object



35
36
37
# File 'lib/rhc/rest/mock.rb', line 35

def mock_date_1
  '2013-02-21T01:00:01Z'
end


469
470
471
472
473
474
# File 'lib/rhc/rest/mock.rb', line 469

def mock_domain_links(domain_id='test_domain')
  [['ADD_APPLICATION',   "domains/#{domain_id}/apps/add", 'post', {'optional_params' => [{'name' => 'environment_variables'}, {'name' => 'cartridges[][name]'}, {'name' => 'cartridges[][url]'}]} ],
   ['LIST_APPLICATIONS', "domains/#{domain_id}/apps/",    'get' ],
   ['UPDATE',            "domains/#{domain_id}/update",   'put'],
   ['DELETE',            "domains/#{domain_id}/delete",   'post']]
end

#mock_gear_groups_responseObject



529
530
531
532
533
534
535
536
537
538
539
540
# File 'lib/rhc/rest/mock.rb', line 529

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



374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/rhc/rest/mock.rb', line 374

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


476
477
478
479
# File 'lib/rhc/rest/mock.rb', line 476

def mock_key_links(key_id='test_key')
  [['UPDATE', "user/keys/#{key_id}/update", 'post'],
   ['DELETE', "user/keys/#{key_id}/delete", 'post']]
end

#mock_passObject



365
366
367
# File 'lib/rhc/rest/mock.rb', line 365

def mock_pass
  "test pass"
end


437
438
439
440
441
442
443
444
# File 'lib/rhc/rest/mock.rb', line 437

def mock_real_client_links
  mock_teams_links.concat([
   ['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


387
388
389
390
391
392
393
394
# File 'lib/rhc/rest/mock.rb', line 387

def mock_response_links(links)
  link_set = {}
  links.each do |link|
    options   = link[3] || {}
    link_set[link[0]] = { 'href' => mock_href(link[1]), 'method' => link[2], 'relative' => link[1]}.merge(options)
  end
  link_set
end


460
461
462
463
464
465
466
467
# File 'lib/rhc/rest/mock.rb', line 460

def mock_team_links(team_id='test_team')
  [['GET',            "team/#{team_id}",          'get'    ],
   ['ADD_MEMBER',     "team/#{team_id}/members/", 'post', {'optional_params' => [{'name' => 'id'}, {'name' => 'login'}], 'required_params' => [{'name' => 'role'}]} ],
   ['LIST_MEMBERS',   "team/#{team_id}/update",   'get'    ],
   ['UPDATE_MEMBERS', "team/#{team_id}/delete",   'patch', {'optional_params' => [{'name' => 'id'}, {'name' => 'login'}, {'name' => 'members'}] } ],
   ['LEAVE',          "team/#{team_id}/delete",   'delete' ],
   ['DELETE',         "team/#{team_id}/delete",   'delete' ]]
end


446
447
448
449
450
# File 'lib/rhc/rest/mock.rb', line 446

def mock_teams_links
  [['SEARCH_TEAMS',           "broker/rest/teams",      'GET'],
   ['LIST_TEAMS',             "broker/rest/teams",      'GET'],
   ['LIST_TEAMS_BY_OWNER',    "broker/rest/teams",      'GET']]
end

#mock_uriObject



369
370
371
# File 'lib/rhc/rest/mock.rb', line 369

def mock_uri
  "test.domain.com"
end

#mock_userObject



39
40
41
# File 'lib/rhc/rest/mock.rb', line 39

def mock_user
  "test_user"
end

#mock_user_authObject



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


481
482
483
484
# File 'lib/rhc/rest/mock.rb', line 481

def mock_user_links
  [['ADD_KEY',   'user/keys/add', 'post'],
   ['LIST_KEYS', 'user/keys/',    'get' ]]
end

#new_authorization(params) ⇒ Object



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/rhc/rest/mock.rb', line 348

def new_authorization(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



304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/rhc/rest/mock.rb', line 304

def new_domain(name)
  {
    :status => 201,
    :body => {
      :type => 'domain',
      :data => {
        :id => name,
        :links => mock_response_links([
        ])
      },
    }.to_json
  }
end

#simple_cartsObject



317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/rhc/rest/mock.rb', line 317

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



330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/rhc/rest/mock.rb', line 330

def simple_user()
  {
    :body => {
      :type => 'user',
      :data => {
        :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
163
164
165
166
167
# File 'lib/rhc/rest/mock.rb', line 158

def stub_add_authorization(params)

  stub_request(:get, "https://api.startappcloud.com/broker/rest/api").
    with(:headers => {'Accept'=>'application/json', 'Authorization'=>'Bearer 05bad717f5c73d38d0e9cd9839c3445132b1a9df61dcbc4992e72e2cc6faf06f'}).
    to_return(:status => 200, :body => "", :headers => {})

  stub_api_request(:post, 'broker/rest/user/authorizations', mock_user_auth).
    with(:body => hash_including(params)).
    to_return(new_authorization(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, message, 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 => message, :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, authorizations=false)
  stub_api_request(:get, 'broker/rest/api', auth).
    to_return({
      :body => {
        :data => mock_response_links(authorizations ? mock_api_with_authorizations : 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(&expect_authorization(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="openshift 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



260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/rhc/rest/mock.rb', line 260

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_authorizationsObject



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_authorizations
  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 stub_delete_authorization(token)
  stub_api_request(:delete, "broker/rest/user/authorizations/#{token}", mock_user_auth).
    to_return(:status => 204)
end

#stub_delete_authorizationsObject



150
151
152
153
# File 'lib/rhc/rest/mock.rb', line 150

def stub_delete_authorizations
  stub_api_request(:delete, 'broker/rest/user/authorizations', mock_user_auth).
    to_return(:status => 204)
end

#stub_mock_ssh_keys(name = 'test') ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/rhc/rest/mock.rb', line 171

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



207
208
209
# File 'lib/rhc/rest/mock.rb', line 207

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_keysObject



168
169
170
# File 'lib/rhc/rest/mock.rb', line 168

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



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/rhc/rest/mock.rb', line 224

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}.rhcloud.com",
          :app_url => "http://#{name}-#{domain_name}.rhcloud.com",
          :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



210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/rhc/rest/mock.rb', line 210

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



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/rhc/rest/mock.rb', line 189

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



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/rhc/rest/mock.rb', line 243

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



275
276
277
# File 'lib/rhc/rest/mock.rb', line 275

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