class Fog::Account::Softlayer::Mock

The Mock Service allows you to run a fake instance of the Service which makes no real connections.

Public Class Methods

new(options={}) click to toggle source
Calls superclass method Fog::Softlayer::Compute::Shared.new
# File lib/fog/softlayer/account.rb, line 33
def initialize(options={})
  @brands = []
  @accounts = [{'id' => 1}]
  super(options)
end

Public Instance Methods

create_brand(attributes) click to toggle source

Create a Brand @param [Hash] attributes @return [Excon::Response]

# File lib/fog/softlayer/requests/account/create_brand.rb, line 15
def create_brand(attributes)
  raise ArgumentError, "Fog::Account::Softlayer#create_brand expects argument of type Hash" unless attributes.kind_of?(Hash)
  response = Excon::Response.new
  required = %w{keyName longName name account}
  if Fog::Softlayer.valid_request?(required, attributes)
    response.status = 201
    response.body = { :id => Fog::Softlayer.mock_vm_id.to_i, :catalogId => 14 }.merge(attributes)
    @brands << response.body
  else
    response.status = 500
    response.body = {
      "code" => "SoftLayer_Exception_MissingCreationProperty",
      "error" => "Properties #{required.join(', ')} ALL must be set to create an instance of 'SoftLayer_Brand'."
    }
  end
  response
end
credentials() click to toggle source
# File lib/fog/softlayer/account.rb, line 39
def credentials
  { :provider           => 'softlayer',
    :softlayer_username => @softlayer_username,
    :softlayer_api_key  => @softlayer_api_key
  }
end
get_account_owned_brands(identifier) click to toggle source

Get all brands who are owned by account. @param [Integer] identifier @return [Excon::Response]

# File lib/fog/softlayer/requests/account/get_account_owned_brands.rb, line 15
def get_account_owned_brands(identifier)
  response = Excon::Response.new
  response.status = 200
  response.body = mocked_brands
  if @accounts.select {|account| account['id'] == identifier.to_i }.empty?
    response.status = 404
    response.body = {
      "error" => "Unable to find object with id of '#{identifier}'.",
      "code"=>"SoftLayer_Exception_ObjectNotFound"
    }
  end
  response
end
get_brand(identifier) click to toggle source

Get a Brand @param [Integer] identifier @return [Excon::Response]

# File lib/fog/softlayer/requests/account/get_brand.rb, line 15
def get_brand(identifier)
  response = Excon::Response.new
  response.body = @brands.select {|brand| brand[:id] == identifier.to_i }.first || {}
  response.status = response.body.empty? ? 404 : 200
  if response.status == 404
    response.body = {
      "error" => "Unable to find object with id of '#{identifier}'.",
      "code"=>"SoftLayer_Exception_ObjectNotFound"
    }
  end
  response
end
get_brand_owned_accounts(identifier) click to toggle source

Get all accounts who are owned by brand. @param [Integer] identifier @return [Excon::Response]

# File lib/fog/softlayer/requests/account/get_brand_owned_accounts.rb, line 15
def get_brand_owned_accounts(identifier)
  response = Excon::Response.new
  if @brands.select {|brand| brand[:id] == identifier.to_i }.empty?
    response.status = 404
    response.body = {
      "error" => "Unable to find object with id of '#{identifier}'.",
      "code"=>"SoftLayer_Exception_ObjectNotFound"
    }
  else
    response.status = 200
    response.body = mocked_accounts
  end
  response
end
mocked_accounts() click to toggle source
# File lib/fog/softlayer/requests/account/get_brand_owned_accounts.rb, line 45
def mocked_accounts
  [
    {
      "accountManagedResourcesFlag"=>false,
      "accountStatusId"=>1001,
      "address1"=>"R 1",
      "allowedPptpVpnQuantity"=>1,
      "brandId"=>23456,
      "city"=>"Itajuba",
      "claimedTaxExemptTxFlag"=>false,
      "companyName"=>"teste",
      "country"=>"BR",
      "createDate"=>"2015-06-10T17:06:27-03:00",
      "email"=>"a@gmail.com",
      "firstName"=>"Matheus2",
      "id"=>23456,
      "isReseller"=>0,
      "lastName"=>"Mina2",
      "lateFeeProtectionFlag"=>nil,
      "modifyDate"=>"2015-06-10T17:06:31-03:00",
      "postalCode"=>"37500-050",
      "state"=>"OT",
      "statusDate"=>nil,
      "brand"=>
        {
          "catalogId"=>14,
          "id"=>12345,
          "keyName"=>"ALS",
          "longName"=>"als",
          "name"=>"als",
          "ownedAccounts"=>
            [
              {
                "accountManagedResourcesFlag"=>false,
                "accountStatusId"=>1001,
                "address1"=>"Av, 1303 Sl 10",
                "address2"=>"Sl 11",
                "allowedPptpVpnQuantity"=>2,
                "brandId"=>44443,
                "city"=>"Itajuba",
                "claimedTaxExemptTxFlag"=>false,
                "companyName"=>"Tecnologias LTDA",
                "country"=>"BR",
                "createDate"=>"2010-10-06T11:32:30-03:00",
                "email"=>"sysadmin@example.com.br",
                "firstName"=>"Xe",
                "id"=>12345,
                "isReseller"=>1,
                "lastName"=>"Silva",
                "lateFeeProtectionFlag"=>true,
                "modifyDate"=>"2011-02-14T17:40:23-02:00",
                "officePhone"=>"+55 35 3629-1616",
                "postalCode"=>"37500-903",
                "state"=>"OT",
                "statusDate"=>nil,
                "brand"=>nil
              },
              nil
            ]
        }
    }
  ]
end
mocked_brands() click to toggle source
# File lib/fog/softlayer/requests/account/get_account_owned_brands.rb, line 44
def mocked_brands
  [
    {
      "catalogId"=>14,
      "id"=>11111,
      "keyName"=>"NAME",
      "longName"=>"Name Name",
      "name"=>"Name"
    }
  ]
end