<commit_before>require 'test_helper'

class Aviator::Test
  describe 'aviator/openstack/volume/v1/public/get_volume_type' do

    def create_request(session_data = get_session_data, &block)
      klass.new(session_data, &block)
    end

    def session
      unless @session
        @session = Aviator::Session.new(
                     config_file: Environment.path,
                     environment: 'openstack_member'
                   )
        @session.authenticate
      end

      @session
    end


    def get_session_data
      session.send :auth_info
    end

    def helper
      Aviator::Test::RequestHelper
    end

    def klass
      @klass ||= helper.load_request('openstack', 'volume', 'v1', 'public', 'get_volume_type.rb')
    end

    validate_attr :anonymous? do
      klass.anonymous?.must_equal false
    end


    validate_attr :api_version do
      klass.api_version.must_equal :v1
    end

    validate_attr :endpoint_type do
      klass.endpoint_type.must_equal :public
    end


    validate_attr :headers do
      headers = { 'X-Auth-Token' => get_session_data[:access][:token][:id] }

      request = create_request do |params|
                  params[:id] = 'doesntmatter'
                end

      request.headers.must_equal headers
    end

    validate_attr :http_method do
      request = create_request do |params|
                  params[:id] = 'doesntmatter'
                end

      request.http_method.must_equal :get
    end

    validate_attr :optional_params do
      klass.optional_params.must_equal []
    end

    validate_attr :required_params do
      klass.required_params.must_equal [:id]
    end

    validate_attr :url do
      service_spec    = get_session_data[:access][:serviceCatalog].find{|s| s[:type] == 'volume' }
      volume_type_id  = '555'
      url             = "#{ service_spec[:endpoints][0][:publicURL] }/types/#{ volume_type_id }"

      request = create_request do |p|
        p[:id] = volume_type_id
      end

      request.url.must_equal url
    end

    #No Volume Types are existing for mc.1-2
    #validate_response 'a valid server id is provided' do
      #volume_id = session.volume_service.request(:list_volume_types).body[:volume_types].first[:id]

      #response = session.volume_service.request :get_volume_types do |params|
        #params[:id] = volume_id
      #end

      #response.status.must_equal 200
      #response.body.wont_be_nil
      #response.body[:volume].wont_be_nil
      #response.body[:volume][:id].must_equal volume_id
      #response.headers.wont_be_nil
    #end

    validate_response 'an invalid volume id is provided' do
      volume_id = 'bogusserveridthatdoesntexist'

      response = session.volume_service.request :get_volume_type do |params|
        params[:id] = volume_id
      end

      response.status.must_equal 404
      response.body.wont_be_nil
      response.headers.wont_be_nil
    end

  end
end
<commit_msg>Refactors create_request for get_volume_type_test.<commit_after>require 'test_helper'

class Aviator::Test
  describe 'aviator/openstack/volume/v1/public/get_volume_type' do

    def create_request(session_data = get_session_data, &block)
      block ||= lambda do |params|
        params[:id] = 0
      end

      klass.new(session_data, &block)
    end

    def session
      unless @session
        @session = Aviator::Session.new(
                     config_file: Environment.path,
                     environment: 'openstack_member'
                   )
        @session.authenticate
      end

      @session
    end


    def get_session_data
      session.send :auth_info
    end

    def helper
      Aviator::Test::RequestHelper
    end

    def klass
      @klass ||= helper.load_request('openstack', 'volume', 'v1', 'public', 'get_volume_type.rb')
    end

    validate_attr :anonymous? do
      klass.anonymous?.must_equal false
    end


    validate_attr :api_version do
      klass.api_version.must_equal :v1
    end

    validate_attr :endpoint_type do
      klass.endpoint_type.must_equal :public
    end


    validate_attr :headers do
      headers = { 'X-Auth-Token' => get_session_data[:access][:token][:id] }

      request = create_request
      request.headers.must_equal headers
    end

    validate_attr :http_method do
      request = create_request
      request.http_method.must_equal :get
    end

    validate_attr :optional_params do
      klass.optional_params.must_equal []
    end

    validate_attr :required_params do
      klass.required_params.must_equal [:id]
    end

    validate_attr :url do
      service_spec    = get_session_data[:access][:serviceCatalog].find{|s| s[:type] == 'volume' }
      volume_type_id  = '555'
      url             = "#{ service_spec[:endpoints][0][:publicURL] }/types/#{ volume_type_id }"

      request = create_request do |p|
        p[:id] = volume_type_id
      end

      request.url.must_equal url
    end

    #No Volume Types are existing for mc.1-2
    #validate_response 'a valid server id is provided' do
      #volume_id = session.volume_service.request(:list_volume_types).body[:volume_types].first[:id]

      #response = session.volume_service.request :get_volume_types do |params|
        #params[:id] = volume_id
      #end

      #response.status.must_equal 200
      #response.body.wont_be_nil
      #response.body[:volume].wont_be_nil
      #response.body[:volume][:id].must_equal volume_id
      #response.headers.wont_be_nil
    #end

    validate_response 'an invalid volume id is provided' do
      volume_id = 'bogusserveridthatdoesntexist'

      response = session.volume_service.request :get_volume_type do |params|
        params[:id] = volume_id
      end

      response.status.must_equal 404
      response.body.wont_be_nil
      response.headers.wont_be_nil
    end

  end
end

{'fraction_non_alphanumeric': 0.09064377682403434, 'fraction_numerical': 0.005321888412017167, 'mean_word_length': 2.580823601720959, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5562829', 'n_tokens_mistral': 1853, 'n_tokens_neox': 1777, 'n_words': 370}