[PATCH conductor 1/1] pools api - index endpoint

Richard Su rwsu at redhat.com
Wed Aug 15 20:02:11 UTC 2012


On 08/15/2012 08:47 AM, Crag Wolfe wrote:
> Add the pools index REST endpoint.  The cucumber test verifies the
> names in the index are as expected and that the id's are unique.
> ---
>   src/app/controllers/pools_controller.rb         |    3 ++
>   src/app/views/api/entrypoint/index.xml.haml     |    1 +
>   src/app/views/pools/_list.xml.haml              |    4 +++
>   src/features/pool_api.feature                   |   16 +++++++++++++
>   src/features/step_definitions/pool_api_steps.rb |   27 +++++++++++++++++++++++
>   5 files changed, 51 insertions(+), 0 deletions(-)
>   create mode 100644 src/app/views/pools/_list.xml.haml
>   create mode 100644 src/features/pool_api.feature
>   create mode 100644 src/features/step_definitions/pool_api_steps.rb
>
> diff --git a/src/app/controllers/pools_controller.rb b/src/app/controllers/pools_controller.rb
> index 931d25d..16ad93b 100644
> --- a/src/app/controllers/pools_controller.rb
> +++ b/src/app/controllers/pools_controller.rb
> @@ -109,6 +109,9 @@ class PoolsController < ApplicationController
>             :user_info => view_context.user_info_for_mustache
>           }
>         end
> +      format.xml do
> +        render :partial => 'list.xml'
> +      end
>       end
>     end
>
> diff --git a/src/app/views/api/entrypoint/index.xml.haml b/src/app/views/api/entrypoint/index.xml.haml
> index f3a1d92..597edbc 100644
> --- a/src/app/views/api/entrypoint/index.xml.haml
> +++ b/src/app/views/api/entrypoint/index.xml.haml
> @@ -2,5 +2,6 @@
>   %api{:href => api_url}
>     %images{:href => api_images_url}
>     %builds{:href => api_builds_url}
> +  %pools{:href => api_pools_url}
>     %provider_images{:href => api_provider_images_url}
>     %target_images{:href => api_target_images_url}
> diff --git a/src/app/views/pools/_list.xml.haml b/src/app/views/pools/_list.xml.haml
> new file mode 100644
> index 0000000..57cb421
> --- /dev/null
> +++ b/src/app/views/pools/_list.xml.haml
> @@ -0,0 +1,4 @@
> +!!! XML
> +%pools
> +  - @pools.each do |pool|
> +    %pool{:id => pool.id, :name => pool.name, :href => api_pool_url(pool)}
> diff --git a/src/features/pool_api.feature b/src/features/pool_api.feature
> new file mode 100644
> index 0000000..6800f41
> --- /dev/null
> +++ b/src/features/pool_api.feature
> @@ -0,0 +1,16 @@
> + at api
> +Feature: Manage Pools via API
> +  As a client of conductor,
> +  In order to manage the full life cycle of pools in the system
> +  I want to be able to Create, Update and Delete pools via a RESTful API
> +
> +  Background:
> +    Given I am an authorised user
> +    And I use my authentication credentials in each request
> +
> +  Scenario: Get list of pools as XML
> +    Given a pool "foo" exists
> +    And a pool "bar" exists
> +    When I request a list of pools as XML
> +    # The third pool besides foo and bar is the Default pool
> +    Then I should receive list of 3 pools as XML
> diff --git a/src/features/step_definitions/pool_api_steps.rb b/src/features/step_definitions/pool_api_steps.rb
> new file mode 100644
> index 0000000..2ffab0e
> --- /dev/null
> +++ b/src/features/step_definitions/pool_api_steps.rb
> @@ -0,0 +1,27 @@
> +When /^I request a list of pools as XML$/ do
> +  header 'Accept', 'application/xml'
> +  get api_pools_path
> +end
> +
> +Then /^I should receive list of (\d+) pools as XML$/ do |number|
> +  response = last_response
> +  response.headers['Content-Type'].should include('application/xml')
> +  response.status.should be_eql(200)
> +  xml_body = Nokogiri::XML(response.body)
> +  pool_node_set = xml_body.xpath('//pools/pool')
> +  pool_node_set.size.should be_eql(number.to_i)
> +  ids = []
> +  names = []
> +  pool_node_set.each() do |ns|
> +    ids << ns.get_attribute('id')
> +    names << ns.get_attribute('name')
> +  end
> +  ids.uniq!
> +  names.sort!
> +  # verify unique id's
> +  ids.size.should be_eql(number.to_i)
> +  if number == 3
> +    # verify pool names match those given in the scenario
> +    names.should be_eql(["Default", "bar", "foo"])
> +  end
> +end
Ack and pushed.



More information about the aeolus-devel mailing list