aviator 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f56372f2f4fea06121bebdef1c2bccfef12c1f56
4
- data.tar.gz: a17fe8facfb17ba357ceb772d9087e89d53a59ca
3
+ metadata.gz: c8e26c692d08f4a3414f7b3ff14b120cee73bad5
4
+ data.tar.gz: 9d60456a3afe9eed57d27acd626a08c3a987b3be
5
5
  SHA512:
6
- metadata.gz: 00aa0e3555582535cfac8d3699259d31140cc88f920f2d162c064d64e2b483ccc8bb484aa29f59f99be99cda355d57a450de29c08714d14e07d23978a9c3a116
7
- data.tar.gz: 7a0155396260c67ab9c7f1c0d03504f7a1e81f8e36463b347303198375c0486d415acd5e97d265036a0ac7a7be9878c9d304ee2743d98dd40b6733f594611cef
6
+ metadata.gz: ffae1b956dc180c585cfa847889a9e0e8267843600e9bac5471a25e8781797ebf6eccb3cedeb05501375372aeedc15348d7b963790bd18682eddce2387cc5a95
7
+ data.tar.gz: f9ebba7e141c1f886d17573b04b0dd60b1708e7c814b3cbbaf6493096be8d78dd4bbc76a52a83c308df63d0fe9e0e8eaacbffc76f907d617b1e9ea7d68cefceb
@@ -0,0 +1,11 @@
1
+ Adrian Peterson Co <adrianpco@gmail.com>
2
+ Alfonso Juan Dillera <aj.dillera@gmail.com>
3
+ Alvin Garcia <agarcia1337@gmail.com>
4
+ Colleen Murphy <colleen@puppetlabs.com>
5
+ Lewis Marshall <lewis@technoplusit.co.uk>
6
+ Mark Maglana <mmaglana@gmail.com>
7
+ Nate West <natescott.west@gmail.com>
8
+ Ricardo Rocha <rocha.porto@gmail.com>
9
+ Stephen Paul Suarez <ssuarez@exist.com>
10
+ Weto Olaguer <wenceslaoolaguer@gmail.com>
11
+ Behrooz Shabani <everplays@gmail.com>
data/README.md CHANGED
@@ -6,5 +6,6 @@
6
6
  [![Code Climate](https://codeclimate.com/github/aviator/aviator.png)](https://codeclimate.com/github/aviator/aviator)
7
7
  [![Gem Version](https://badge.fury.io/rb/aviator.png)](http://badge.fury.io/rb/aviator)
8
8
 
9
+ Aviator complies with <a href="http://semver.org/">Semantic Versioning</a>.
9
10
 
10
11
  <a href="http://aviator.github.io/www/">Usage and Installation</a>
@@ -36,7 +36,7 @@ module Aviator
36
36
  request_class = "Aviator::#{ provider_name.camelize }::#{ service_name.camelize }::Requests::"\
37
37
  "#{ api_version.camelize }::#{ endpoint_type.camelize }::#{ request_name.camelize }".constantize
38
38
 
39
- display = ":Request => #{ request_name }\n"
39
+ display = "Request: #{ request_name }\n"
40
40
 
41
41
 
42
42
  # Build the parameters
@@ -83,7 +83,7 @@ module Aviator
83
83
  # Build the sample code
84
84
  display << "\nSample Code:\n"
85
85
 
86
- display << " session.#{ service_name }_service.request(:#{ request_name })"
86
+ display << " session.request(:#{ service_name }_service, :#{ request_name })"
87
87
 
88
88
  if params && params.length > 0
89
89
  display << " do |params|\n"
@@ -14,7 +14,7 @@ module Aviator
14
14
 
15
15
 
16
16
  def body
17
- if raw_body.length > 0
17
+ @body ||= if raw_body.length > 0
18
18
  if Aviator::Compatibility::RUBY_1_8_MODE
19
19
  clean_body = raw_body.gsub(/\\ /, ' ')
20
20
  else
@@ -29,14 +29,22 @@ module Aviator
29
29
 
30
30
 
31
31
  def headers
32
- Hashish.new(@response.headers)
32
+ @headers ||= Hashish.new(@response.headers)
33
33
  end
34
34
 
35
35
 
36
+ def to_hash
37
+ Hashish.new({
38
+ :status => status,
39
+ :headers => headers,
40
+ :body => body
41
+ })
42
+ end
43
+
36
44
  private
37
45
 
38
46
  def raw_body
39
- @response.body
47
+ @raw_body ||= @response.body
40
48
  end
41
49
 
42
50
  end
@@ -1,5 +1,8 @@
1
1
  module Aviator
2
2
 
3
+ #
4
+ # Manages a service
5
+ #
3
6
  class Service
4
7
 
5
8
  class AccessDetailsNotDefinedError < StandardError
@@ -35,7 +38,6 @@ module Aviator
35
38
  end
36
39
  end
37
40
 
38
-
39
41
  class UnknownRequestError < StandardError
40
42
  def initialize(request_name, options)
41
43
  super "Unknown request #{ request_name } #{ options }."
@@ -75,7 +77,9 @@ module Aviator
75
77
  load_requests
76
78
  end
77
79
 
78
-
80
+ #
81
+ # No longer recommended for public use. Use Aviator::Session#request instead
82
+ #
79
83
  def request(request_name, options={}, &params)
80
84
  if options[:api_version].nil? && @default_options[:api_version]
81
85
  options[:api_version] = @default_options[:api_version]
@@ -93,6 +97,19 @@ module Aviator
93
97
 
94
98
  raise UnknownRequestError.new(request_name, options) unless request_class
95
99
 
100
+ # Always use :params over &params if provided
101
+ if options[:params]
102
+ params = lambda do |params|
103
+ options[:params].each do |key, value|
104
+ begin
105
+ params[key] = value
106
+ rescue NameError => e
107
+ raise NameError.new("Unknown param name '#{key}'")
108
+ end
109
+ end
110
+ end
111
+ end
112
+
96
113
  request = request_class.new(session_data, &params)
97
114
 
98
115
  response = http_connection.send(request.http_method) do |r|
@@ -1,12 +1,14 @@
1
+ #
2
+ # Author:: Mark Maglana (mmaglana@gmail.com)
3
+ # Copyright:: Copyright (c) 2014 Mark Maglana
4
+ # License:: Distributed under the MIT license
5
+ # Homepage:: http://aviator.github.io/www/
6
+ #
1
7
  module Aviator
2
8
 
3
9
  #
4
- # Manages a provider (e.g. OpenStack) session.
5
- #
6
- # Author:: Mark Maglana (mmaglana@gmail.com)
7
- # Copyright:: Copyright (c) 2014 Mark Maglana
8
- # License:: Distributed under the MIT license
9
- # Homepage:: http://aviator.github.io/www/
10
+ # Manages a provider (e.g. OpenStack) session and serves as the entry point
11
+ # for a consumer class/object. See Session::new for notes on usage.
10
12
  #
11
13
  class Session
12
14
 
@@ -51,8 +53,7 @@ module Aviator
51
53
  end
52
54
 
53
55
  #
54
- # Create a new Session instance with options provided in <tt>opts</tt> which can
55
- # have many forms discussed below.
56
+ # Create a new Session instance.
56
57
  #
57
58
  # <b>Initialize with a config file</b>
58
59
  #
@@ -73,17 +74,20 @@ module Aviator
73
74
  # password: mypassword
74
75
  # tenant_name: myproject
75
76
  #
77
+ # <b>SIDENOTE:</b> For more information about the <tt>validator</tt> member, see Session#validate.
78
+ #
76
79
  # Once the session has been instantiated, you may authenticate against the
77
80
  # provider as follows:
78
81
  #
79
82
  # session.authenticate
80
83
  #
81
- # Note that the required items under <tt>auth_credentials</tt> in the config
82
- # file depends on the required parameters of the request class declared under
83
- # <tt>auth_service</tt>. If writing the <tt>auth_credentials</tt> in the config
84
- # file is not acceptable, you may omit it and just supply the credentials at
85
- # runtime. For instance, assume that the <tt>auth_credentials</tt> section in the
86
- # config file above is missing. You would then authenticate as follows:
84
+ # The members you put under <tt>auth_credentials</tt> will depend on the request
85
+ # class you declare under <tt>auth_service:request</tt> and what parameters it
86
+ # accepts. To know more about a request class and its parameters, you can use
87
+ # the CLI tool <tt>aviator describe</tt> or view the request definition file directly.
88
+ #
89
+ # If writing the <tt>auth_credentials</tt> in the config file is not acceptable,
90
+ # you may omit it and just supply the credentials at runtime. For example:
87
91
  #
88
92
  # session.authenticate do |params|
89
93
  # params.username = ARGV[0]
@@ -91,7 +95,7 @@ module Aviator
91
95
  # params.tenant_name = ARGV[2]
92
96
  # end
93
97
  #
94
- # Please see Session#authenticate for more info.
98
+ # See Session#authenticate for more info.
95
99
  #
96
100
  # Note that while the example config file above only has one environment (production),
97
101
  # you can declare an arbitrary number of environments in your config file. Shifting
@@ -100,8 +104,8 @@ module Aviator
100
104
  #
101
105
  # <b>Initialize with an in-memory hash</b>
102
106
  #
103
- # You can create an in-memory hash which is similar in structure to the config file except
104
- # that you don't need to specify an environment name. For example:
107
+ # You can create an in-memory hash with a structure similar to the config file but without
108
+ # the environment name. For example:
105
109
  #
106
110
  # configuration = {
107
111
  # :provider => 'openstack',
@@ -150,12 +154,14 @@ module Aviator
150
154
  end
151
155
 
152
156
  #
153
- # Authenticates against the auth_service request class declared in the session's
154
- # configuration during initialization. Please see Session.new for more information
157
+ # Authenticates against the backend provider using the auth_service request class
158
+ # declared in the session's configuration. Please see Session.new for more information
155
159
  # on declaring the request class to use for authentication.
156
160
  #
157
- # If the auth_service request class accepts a parameter block, you may also supply that
158
- # when calling this method and it will be directly passed to the request. For example:
161
+ # <b>Request params block</b>
162
+ #
163
+ # If the auth_service request class accepts parameters, you may supply that
164
+ # as a block and it will be directly passed to the request. For example:
159
165
  #
160
166
  # session = Aviator::Session.new(:config => config)
161
167
  # session.authenticate do |params|
@@ -164,9 +170,12 @@ module Aviator
164
170
  # params.tenant_name = project
165
171
  # end
166
172
  #
167
- # Expects an HTTP status 200 or 201. Any other status is treated as a failure.
173
+ # If your configuration happens to have an <tt>auth_credentials</tt> in it, those
174
+ # will be overridden by this block.
168
175
  #
169
- # Note that you can also treat the block's argument like a hash with the attribute
176
+ # <b>Treat parameters as a hash</b>
177
+ #
178
+ # You can also treat the params struct like a hash with the attribute
170
179
  # names as the keys. For example, we can rewrite the above as:
171
180
  #
172
181
  # session = Aviator::Session.new(:config => config)
@@ -178,7 +187,29 @@ module Aviator
178
187
  #
179
188
  # Keys can be symbols or strings.
180
189
  #
181
- def authenticate(&block)
190
+ # <b>Use a hash argument instead of a block</b>
191
+ #
192
+ # You may also provide request params as an argument instead of a block. This is
193
+ # especially useful if you want to mock Aviator as it's easier to specify ordinary
194
+ # argument expectations over blocks. Further rewriting the example above,
195
+ # we end up with:
196
+ #
197
+ # session = Aviator::Session.new(:config => config)
198
+ # session.authenticate :params => {
199
+ # :username => username,
200
+ # :password => password,
201
+ # :tenant_name => project
202
+ # }
203
+ #
204
+ # If both <tt>:params</tt> and a block are provided, the <tt>:params</tt>
205
+ # values will be used and the block ignored.
206
+ #
207
+ # <b>Success requirements</b>
208
+ #
209
+ # Expects an HTTP status 200 or 201 response from the backend. Any other
210
+ # status is treated as a failure.
211
+ #
212
+ def authenticate(opts={}, &block)
182
213
  block ||= lambda do |params|
183
214
  config[:auth_credentials].each do |key, value|
184
215
  begin
@@ -189,7 +220,7 @@ module Aviator
189
220
  end
190
221
  end
191
222
 
192
- response = auth_service.request config[:auth_service][:request].to_sym, &block
223
+ response = auth_service.request(config[:auth_service][:request].to_sym, opts, &block)
193
224
 
194
225
  if [200, 201].include? response.status
195
226
  @auth_response = Hashish.new({
@@ -204,7 +235,10 @@ module Aviator
204
235
  end
205
236
 
206
237
  #
207
- # Returns true if the session has been authenticated.
238
+ # Returns true if the session has been authenticated. Note that this relies on
239
+ # cached response from a previous run of Session#authenticate if one was made.
240
+ # If you want to check against the backend provider if the session is still valid,
241
+ # use Session#validate instead.
208
242
  #
209
243
  def authenticated?
210
244
  !auth_response.nil?
@@ -247,7 +281,7 @@ module Aviator
247
281
  end
248
282
 
249
283
 
250
- def method_missing(name, *args, &block)
284
+ def method_missing(name, *args, &block) # :nodoc:
251
285
  service_name_parts = name.to_s.match(/^(\w+)_service$/)
252
286
 
253
287
  if service_name_parts
@@ -262,7 +296,8 @@ module Aviator
262
296
  # Creates a new Session object from a previous session's dump. See Session#dump for
263
297
  # more information.
264
298
  #
265
- # If you want the newly deserialized session to log its output, make sure to indicate it on load
299
+ # If you want the newly deserialized session to log its output, add a <tt>:log_file</tt>
300
+ # option.
266
301
  #
267
302
  # Aviator::Session.load(session_dump_str, :log_file => 'path/to/aviator.log')
268
303
  #
@@ -301,37 +336,77 @@ module Aviator
301
336
  #
302
337
  # Keys can be symbols or strings.
303
338
  #
339
+ # You may also provide parameters as an argument instead of a block. This is
340
+ # especially useful when mocking Aviator as it's easier to specify ordinary
341
+ # argument expectations over blocks. Further rewriting the example above,
342
+ # we end up with:
343
+ #
344
+ # session.request :compute_service, :create_server, :params => {
345
+ # :name => "My Server",
346
+ # :image_ref => "7cae8c8e-fb01-4a88-bba3-ae0fcb1dbe29",
347
+ # :flavor_ref => "fa283da1-59a5-4245-8569-b6eadf69f10b"
348
+ # }
349
+ #
350
+ # If both <tt>:params</tt> and a block are provided, the values in <tt>:params</tt>
351
+ # will be used and the block ignored.
352
+ #
353
+ # <b>Return Value</b>
354
+ #
355
+ # The return value will be an instance of Hashish, a lightweight replacement for
356
+ # activesupport's HashWithIndifferentAccess, with the following structure:
357
+ #
358
+ # {
359
+ # :status => 200,
360
+ # :headers => {
361
+ # 'X-Auth-Token' => 'd9186f45ce5446eaa0adc9def1c46f5f',
362
+ # 'Content-Type' => 'application/json'
363
+ # },
364
+ # :body => {
365
+ # :some_key => :some_value
366
+ # }
367
+ # }
368
+ #
369
+ # Note that the members in <tt>:headers</tt> and <tt>:body</tt> will vary depending
370
+ # on the provider and the request that was made.
371
+ #
304
372
  # ---
305
373
  #
306
374
  # <b>Request Options</b>
307
375
  #
308
- # You can further customize how the request is fulfilled by providing one or more
309
- # options to the method call. For example, the following ensures that the request
310
- # will call the :create_server request for the v1 API.
376
+ # You can further customize how the method behaves by providing one or more
377
+ # options to the call. For example, assuming you are using the <tt>openstack</tt>
378
+ # provider, the following will call the <tt>:create_server</tt> request of the
379
+ # v1 API of <tt>:compute_service</tt>.
311
380
  #
312
- # session.request :compute_service, :create_server, :api_version => v1
381
+ # session.request :compute_service, :create_server, :api_version => v1, :params => params
313
382
  #
314
383
  # The available options vary depending on the provider. See the documentation
315
- # on the provider's Provider class for more information (e.g. Aviator::OpenStack::Provider)
384
+ # on the provider's Provider class for more information (e.g. Aviator::Openstack::Provider)
316
385
  #
317
- def request(service_name, request_name, opts={}, &params)
386
+ def request(service_name, request_name, opts={}, &block)
318
387
  service = send("#{service_name.to_s}_service")
319
- service.request(request_name, opts, &params)
388
+ response = service.request(request_name, opts, &block)
389
+ response.to_hash
320
390
  end
321
391
 
322
392
 
323
393
  #
324
- # Returns true if the session is still valid in the underlying provider. This method does this
325
- # by calling the validator request class declared declared under <tt>auth_service</tt> in the
394
+ # Returns true if the session is still valid in the underlying provider. This method calls
395
+ # the <tt>validator</tt> request class declared under <tt>auth_service</tt> in the
326
396
  # configuration. The validator can be any request class as long as:
327
397
  #
328
398
  # * The request class exists!
399
+ # * Is not an anonymous request. Otherwise it will always return true.
329
400
  # * Does not require any parameters
330
401
  # * It returns an HTTP status 200 or 203 to indicate auth info validity.
331
402
  # * It returns any other HTTP status to indicate that the auth info is invalid.
332
403
  #
333
404
  # See Session::new for an example on how to specify the request class to use for session validation.
334
405
  #
406
+ # Note that this method requires the session to be previously authenticated otherwise a
407
+ # NotAuthenticatedError will be raised. If you just want to check if the session was previously
408
+ # authenticated, use Session#authenticated? instead.
409
+ #
335
410
  def validate
336
411
  raise NotAuthenticatedError.new unless authenticated?
337
412
  raise ValidatorNotDefinedError.new unless config[:auth_service][:validator]
@@ -1,7 +1,6 @@
1
- # Original work by Stephen Paul Suarez
2
- # https://github.com/musashi-dev/aviator/blob/develop/lib/aviator/openstack/identity/v3/public/create_token.rb
3
-
4
1
  module Aviator
2
+ # Original work by Stephen Paul Suarez
3
+ # https://github.com/musashi-dev/aviator/blob/develop/lib/aviator/openstack/identity/v3/public/create_token.rb
5
4
 
6
5
  define_request :create_token, :inherit => [:openstack, :common, :v3, :public, :base] do
7
6
 
@@ -1,13 +1,6 @@
1
1
  module Aviator
2
2
  module Openstack
3
3
 
4
- #
5
- # Manages a provider (e.g. OpenStack) session.
6
- #
7
- # Author:: Mark Maglana (mmaglana@gmail.com)
8
- # Copyright:: Copyright (c) 2014 Mark Maglana
9
- # License:: Distributed under the MIT license
10
- # Homepage:: http://aviator.github.io/www/
11
4
  #
12
5
  # <b>Request Options</b>
13
6
  #
@@ -16,10 +9,10 @@ module Openstack
16
9
  #
17
10
  # :api_version => :v2::
18
11
  # Forces Aviator to use the request class for the v2 API. For any other
19
- # version, replace Note that this may throw an error if no such request
20
- # class exists. If you want to globally specify the API version to use for
21
- # a specific service, declare it in your config file under the correct
22
- # environment. For example:
12
+ # version, replace :v2 with the desired one. Note that this may throw an
13
+ # error if no such request class for the given api version exists. If you
14
+ # want to globally specify the API version to use for a specific service,
15
+ # declare it in your config file under the correct environment. For example:
23
16
  #
24
17
  # production:
25
18
  # provider: openstack
@@ -1,3 +1,3 @@
1
1
  module Aviator
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -110,10 +110,10 @@ class Aviator::Test
110
110
  request_class = build_request(provider, service, request_name)
111
111
 
112
112
  expected = <<-EOF
113
- :Request => #{ request_name }
113
+ Request: #{ request_name }
114
114
 
115
115
  Sample Code:
116
- session.#{ service }_service.request(:#{ request_name })
116
+ session.request(:#{ service }_service, :#{ request_name })
117
117
  EOF
118
118
 
119
119
  output = klass.describe_request(
@@ -139,7 +139,7 @@ EOF
139
139
  end
140
140
 
141
141
  expected = <<-EOF
142
- :Request => #{ request_name }
142
+ Request: #{ request_name }
143
143
 
144
144
  Parameters:
145
145
  +----------+-----------+
@@ -150,7 +150,7 @@ Parameters:
150
150
  +----------+-----------+
151
151
 
152
152
  Sample Code:
153
- session.#{ service }_service.request(:#{ request_name }) do |params|
153
+ session.request(:#{ service }_service, :#{ request_name }) do |params|
154
154
  params.another = value
155
155
  params.theParam = value
156
156
  end
@@ -179,7 +179,7 @@ EOF
179
179
  end
180
180
 
181
181
  expected = <<-EOF
182
- :Request => #{ request_name }
182
+ Request: #{ request_name }
183
183
 
184
184
  Parameters:
185
185
  +--------------+-----------+---------------+
@@ -190,7 +190,7 @@ Parameters:
190
190
  +--------------+-----------+---------------+
191
191
 
192
192
  Sample Code:
193
- session.#{ service }_service.request(:#{ request_name }) do |params|
193
+ session.request(:#{ service }_service, :#{ request_name }) do |params|
194
194
  params.another_param = value
195
195
  params.the_param = value
196
196
  end
@@ -221,7 +221,7 @@ EOF
221
221
  end
222
222
 
223
223
  expected = <<-EOF
224
- :Request => #{ request_name }
224
+ Request: #{ request_name }
225
225
 
226
226
  Parameters:
227
227
  +--------------+-----------+---------------+
@@ -232,7 +232,7 @@ Parameters:
232
232
  +--------------+-----------+---------------+
233
233
 
234
234
  Sample Code:
235
- session.#{ service }_service.request(:#{ request_name }) do |params|
235
+ session.request(:#{ service }_service, :#{ request_name }) do |params|
236
236
  params.another_param = value
237
237
  params.the_param = value
238
238
  end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+ require 'mocha/setup'
3
+
4
+
5
+ class Aviator::Test
6
+
7
+ describe 'aviator/core/response' do
8
+
9
+ describe '#to_hash' do
10
+
11
+ it 'returns a Hashish instance representing the response' do
12
+ mock_http_response = mock('Faraday::Response')
13
+ mock_request = mock('Aviator::Request')
14
+
15
+ hashed_response = {
16
+ :status => 200,
17
+ :headers => {
18
+ :header1 => 'value1',
19
+ :header2 => 'value2'
20
+ },
21
+ :body => {
22
+ :body1 => 'bodyvalue1',
23
+ :body2 => 'bodyvalue2'
24
+ }
25
+ }
26
+
27
+ mock_http_response.expects(:status).returns(hashed_response[:status])
28
+ mock_http_response.expects(:headers).returns(hashed_response[:headers])
29
+ mock_http_response.expects(:body).returns(hashed_response[:body].to_json)
30
+
31
+ response = Aviator::Response.new(mock_http_response, mock_request)
32
+
33
+ response.to_hash.must_equal Hashish.new(hashed_response)
34
+ end
35
+
36
+ end
37
+
38
+
39
+ end
40
+
41
+ end
@@ -112,6 +112,33 @@ describe 'Aviator::Session' do
112
112
  end
113
113
 
114
114
 
115
+ it 'authenticates against the auth service using the credentials in a params arg' do
116
+ # Keys below are dependent on whatever is declared in
117
+ # the request classes referenced by auth_service:request
118
+ # in the config file
119
+ params = {
120
+ 'username' => 'someuser',
121
+ 'password' => 'password'
122
+ }
123
+
124
+ mock_conn = mock('Faraday::Connection')
125
+ mock_http_req = mock('Faraday::Request')
126
+ mock_response = mock('Faraday::Response')
127
+ Faraday.expects(:new).returns(mock_conn)
128
+ mock_conn.expects(:post).yields(mock_http_req).returns(mock_response)
129
+ mock_http_req.expects(:url)
130
+ mock_http_req.expects(:body=).with(){|json| JSON.load(json) == params }
131
+ mock_response.expects(:status).returns(200)
132
+ mock_response.expects(:headers).returns({})
133
+ mock_response.expects(:body).returns({})
134
+
135
+ session = Aviator::Session.new(:config => valid_config[valid_env])
136
+ session.authenticate :params => params
137
+
138
+ session.authenticated?.must_equal true
139
+ end
140
+
141
+
115
142
  it 'raises an AuthenticationError when authentication fails' do
116
143
  Faraday.expects(:new).returns(mock_conn = mock('Faraday::Connection'))
117
144
  mock_conn.expects(:post).returns(mock_response = mock('Faraday::Response'))
@@ -353,14 +380,48 @@ describe 'Aviator::Session' do
353
380
  mock_response.stubs(:status).returns(200)
354
381
  mock_response.stubs(:headers).returns({})
355
382
  mock_response.stubs(:body).returns('{}')
383
+ hashed_response = {:response1 => :value1}
384
+ mock_response.stubs(:to_hash).returns(hashed_response)
356
385
  mock_auth.expects(:request).returns(mock_response)
357
386
  mock_compute.expects(:request).with(request_name, request_opts).yields(yielded_params).returns(mock_response)
358
387
 
359
388
  session = Aviator::Session.new(:config => valid_config[valid_env])
360
389
  session.authenticate
361
390
 
362
- session.request :compute, request_name, request_opts, &request_params
391
+ response = session.request :compute, request_name, request_opts, &request_params
363
392
  yielded_params.wont_be_empty
393
+ response.must_equal hashed_response
394
+ end
395
+
396
+
397
+ it 'passes the params arg to Service#request' do
398
+ request_name = :create_server
399
+ request_opts = {
400
+ :params => {
401
+ :key1 => :value1,
402
+ :key2 => :value2
403
+ }
404
+ }
405
+
406
+ mock_auth = mock('Aviator::Service')
407
+ mock_compute = mock('Aviator::Service')
408
+ mock_response = mock('Aviator::Response')
409
+
410
+ Aviator::Service.expects(:new).twice.returns(mock_auth, mock_compute)
411
+ mock_response.stubs(:status).returns(200)
412
+ mock_response.stubs(:headers).returns({:header1 => :headervalue1})
413
+ mock_response.stubs(:body).returns('{":bodykey1": "bodyvalue1"}')
414
+ hashed_response = {:responsekey1 => :responsevalue1}
415
+ mock_response.stubs(:to_hash).returns(hashed_response)
416
+ mock_auth.expects(:request).returns(mock_response)
417
+ mock_compute.expects(:request).with(request_name, request_opts).returns(mock_response)
418
+
419
+ session = Aviator::Session.new(:config => valid_config[valid_env])
420
+ session.authenticate
421
+
422
+ response = session.request :compute, request_name, request_opts
423
+
424
+ response.must_equal hashed_response
364
425
  end
365
426
 
366
427
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aviator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Maglana
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-08 00:00:00.000000000 Z
11
+ date: 2014-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -255,6 +255,7 @@ files:
255
255
  - ".coveralls.yml"
256
256
  - ".gitignore"
257
257
  - ".travis.yml"
258
+ - CONTRIBUTORS.txt
258
259
  - Gemfile
259
260
  - Guardfile
260
261
  - LICENSE.txt
@@ -358,6 +359,7 @@ files:
358
359
  - test/aviator/core/cli/describer_test.rb
359
360
  - test/aviator/core/request_builder_test.rb
360
361
  - test/aviator/core/request_test.rb
362
+ - test/aviator/core/response_test.rb
361
363
  - test/aviator/core/service_test.rb
362
364
  - test/aviator/core/session_test.rb
363
365
  - test/aviator/openstack/common/requests/v0/public/base_test.rb
@@ -940,6 +942,7 @@ test_files:
940
942
  - test/aviator/core/cli/describer_test.rb
941
943
  - test/aviator/core/request_builder_test.rb
942
944
  - test/aviator/core/request_test.rb
945
+ - test/aviator/core/response_test.rb
943
946
  - test/aviator/core/service_test.rb
944
947
  - test/aviator/core/session_test.rb
945
948
  - test/aviator/openstack/common/requests/v0/public/base_test.rb