deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michal Fojtik <mfoj...@redhat.com>
Subject Re: [PATCH 1/2] API TESTS: refactoring of common code - avoid duplication
Date Fri, 10 Aug 2012 13:04:13 GMT
On Aug 9, 2012, at 3:02 PM, marios@redhat.com wrote:

ACK. Small nits inline.

> From: marios <marios@redhat.com>
> 
> 
> Signed-off-by: marios <marios@redhat.com>
> ---
> tests/README                       |   15 ++++----
> tests/config.yaml                  |   10 +++---
> tests/deltacloud/instances_test.rb |   63 +++++++++++-------------------------
> tests/deltacloud/test_setup.rb     |   27 +++++++++++----
> 4 files changed, 51 insertions(+), 64 deletions(-)
> 
> diff --git a/tests/deltacloud/test_setup.rb b/tests/deltacloud/test_setup.rb
> index e034493..6beceb1 100644
> --- a/tests/deltacloud/test_setup.rb
> +++ b/tests/deltacloud/test_setup.rb
> @@ -43,6 +43,12 @@ class String
>     return self.gsub(/es$/, '') if self =~ /sses$/
>     self.gsub(/s$/, '')
>   end
> +  def pluralize
> +    return self + 'es' if self =~ /ess$/
> +    return self[0, self.length-1] + "ies" if self =~ /ty$/
> +    return self if self =~ /data$/
> +    self + "s"
> +  end
> end
> 
> class Array

Why we need to have this in test_setup, when we already have core_ext
with pluralize() method ?

> @@ -83,12 +89,8 @@ module Deltacloud
>         @hash[driver]["bucket_locations"]
>       end
> 
> -      def instances_config
> -        @hash[driver]["instances"] || {}
> -      end
> -
> -      def preferred_provider
> -        @hash[driver]["preferred_provider"]
> +      def preferred
> +        @hash[driver]["preferred"] || {}
>       end
> 
>       def driver
> @@ -166,8 +168,8 @@ module Deltacloud::Test::Methods
>     end
> 
>     def post(path, post_body, params={})
> -      if api.preferred_provider and not params[:provider]
> -        params[:provider] = api.preferred_provider
> +      if api.preferred["provider"] and not params[:provider]
> +        params[:provider] = api.preferred["provider"]
>       end
>       url, headers = process_url_params(path, params)
>       RestClient.post url, post_body, headers
> @@ -204,6 +206,15 @@ module Deltacloud::Test::Methods
>       name.insert(0, "apitest")
>     end
> 
> +    def get_a(item)
> +      if api.preferred[item]
> +        item_id = api.preferred[item]
> +      else
> +        item_list = get("/#{item.pluralize}")
> +        item_id = (item_list.xml/"#{item.pluralize}/#{item}").to_a.choice[:id]
> +      end
> +    end
> +
>     private
> 
>     def process_url_params(path, params)
> -- 
> 1.7.6.5
> 


Mime
View raw message