Class: GramAccountMocker

Inherits:
Object
  • Object
show all
Defined in:
lib/gram_v2_client/rspec/gram_account_mocker.rb

Constant Summary collapse

DEFAULT_GRAM_ACCOUNT =
{
    "uuid"=>"12345678-1234-1234-1234-123456789012",
    "hruid"=>"francois.dupont.2011",
    "firstname"=>"Francois",
    "lastname"=>"Dupont",
    "id_soce"=>"84189",
    "enable"=>"TRUE",
    "id"=>98765,
    "uid_number"=>99765,
    "gid_number"=>99765,
    "home_directory"=>"/nonexistant",
    "alias"=>["francois.dupont.2011", "98765", "98765J"],
    "password"=>"Not Display",
    "email"=>"francois.dupont",
    "email_forge"=>"[email protected]",
    "birthdate"=>"1987-09-17 00:00:00",
    "login_validation_check"=>"CGU=2015-06-04;",
    "description"=>"Agoram inscription - via module register - creation 2015-06-04 11:32:48",
    "entities"=>["comptes", "gram"],
    "is_gadz"=>"true",
    "gapps_id" => nil
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr = {}, auth = nil) ⇒ GramAccountMocker

Returns a new instance of GramAccountMocker.



30
31
32
33
# File 'lib/gram_v2_client/rspec/gram_account_mocker.rb', line 30

def initialize(attr={},auth=nil)
  @auth=auth
  @attributes=attr
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



28
29
30
# File 'lib/gram_v2_client/rspec/gram_account_mocker.rb', line 28

def attributes
  @attributes
end

Class Method Details

.for(attr: {}, auth: nil) ⇒ Object



39
40
41
42
# File 'lib/gram_v2_client/rspec/gram_account_mocker.rb', line 39

def self.for(attr:{},auth: nil)
  string_hash=attr.inject({}){|memo,(k,v)| memo[k.to_s] = v; memo}
  self.new(DEFAULT_GRAM_ACCOUNT.merge(string_hash),auth)
end

.http_basic_auth_header(user, password) ⇒ Object



77
78
79
# File 'lib/gram_v2_client/rspec/gram_account_mocker.rb', line 77

def self.http_basic_auth_header(user,password)
  "Basic "+Base64.encode64("#{user}:#{password}").chomp
end

.reset!Object



73
74
75
# File 'lib/gram_v2_client/rspec/gram_account_mocker.rb', line 73

def self.reset!
  ActiveResource::HttpMock.reset!
end

Instance Method Details

#mock_get_request(with_password: false) ⇒ Object



50
51
52
53
54
55
# File 'lib/gram_v2_client/rspec/gram_account_mocker.rb', line 50

def mock_get_request(with_password: false)
  uri=uri_for_get_request(with_password: with_password)
  ActiveResource::HttpMock.respond_to({},false) do |mock|
    mock.get uri, {"Authorization"=>authorization_header,'Accept' => 'application/json'}, attributes.to_json, 200
  end
end

#mock_put_requestObject



66
67
68
69
70
71
# File 'lib/gram_v2_client/rspec/gram_account_mocker.rb', line 66

def mock_put_request()
  uri= "/api/v2/accounts/#{uuid}.json"
  ActiveResource::HttpMock.respond_to({},false) do |mock|
    mock.put uri, {"Authorization"=>authorization_header,'Content-Type' => 'application/json'}, attributes.to_json, 200
  end
end

#mock_search_request_for(param, value = nil, response = [attributes]) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/gram_v2_client/rspec/gram_account_mocker.rb', line 57

def mock_search_request_for(param,value=nil,response=[attributes])
  value||=attributes[param.to_s]
  value=URI.escape(URI.escape(value.to_s),"@")
  response=response.to_json unless response.is_a? String
  ActiveResource::HttpMock.respond_to({},false) do |mock|
    mock.get "/api/v2/accounts.json?#{param.to_s}=#{value}", {"Authorization"=>authorization_header,'Accept' => 'application/json'}, response, 200
  end
end

#uri_for_get_request(with_password: false) ⇒ Object



44
45
46
47
48
# File 'lib/gram_v2_client/rspec/gram_account_mocker.rb', line 44

def uri_for_get_request(with_password: false)
  uri= "/api/v2/accounts/#{uuid}.json"
  uri+= "?show_password_hash=true" if with_password
  uri
end

#uuidObject



35
36
37
# File 'lib/gram_v2_client/rspec/gram_account_mocker.rb', line 35

def uuid
  @attributes["uuid"]
end