<commit_before>require 'test_helper'

class Aviator::Test

  describe 'aviator/openstack/volume/v1/public/get_volume' 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.rb')
    end

    def create_volume
      session.volume_service.request :create_volume do |params|
        params[:display_name]         = 'Aviator Volume Test Name'
        params[:display_description]  = 'Aviator Volume Test Description'
        params[:size]                 = '1'
      end
    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 :body do
      klass.body?.must_equal false

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

      request.body?.must_equal false
    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_id    = '52415800-8b69-11e0-9b19-734f000004d2'
      url          = "#{ service_spec[:endpoints][0][:publicURL] }/volumes/#{ volume_id }"

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

      request.url.must_equal url
    end


    validate_response 'a valid volume id is provided' do

      create_volume
<commit_msg>Refactors create_request for get_volume_test.<commit_after>require 'test_helper'

class Aviator::Test

  describe 'aviator/openstack/volume/v1/public/get_volume' 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.rb')
    end

    def create_volume
      session.volume_service.request :create_volume do |params|
        params[:display_name]         = 'Aviator Volume Test Name'
        params[:display_description]  = 'Aviator Volume Test Description'
        params[:size]                 = '1'
      end
    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 :body do
      klass.body?.must_equal false

      request = create_request
      request.body?.must_equal false
    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_id    = '52415800-8b69-11e0-9b19-734f000004d2'
      url          = "#{ service_spec[:endpoints][0][:publicURL] }/volumes/#{ volume_id }"

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

      request.url.must_equal url
    end


    validate_response 'a valid volume id is provided' do

      create_volume

{'fraction_non_alphanumeric': 0.08726003490401396, 'fraction_numerical': 0.012604227263913128, 'mean_word_length': 2.2832590706556335, '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': '6269729', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1528, 'n_words': 337}