salesforcebulk 1.4.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +33 -15
  3. data/lib/salesforce_bulk.rb +1 -5
  4. data/lib/salesforce_bulk/client.rb +56 -59
  5. data/lib/salesforce_bulk/version.rb +1 -1
  6. metadata +46 -76
  7. data/.gitignore +0 -4
  8. data/.travis.yml +0 -10
  9. data/Gemfile +0 -3
  10. data/LICENSE +0 -20
  11. data/Rakefile +0 -22
  12. data/salesforcebulk.gemspec +0 -30
  13. data/test/fixtures/batch_create_request.csv +0 -3
  14. data/test/fixtures/batch_create_response.xml +0 -13
  15. data/test/fixtures/batch_info_list_response.xml +0 -27
  16. data/test/fixtures/batch_info_response.xml +0 -14
  17. data/test/fixtures/batch_result_list_response.csv +0 -3
  18. data/test/fixtures/config.yml +0 -5
  19. data/test/fixtures/invalid_batch_error.xml +0 -5
  20. data/test/fixtures/invalid_error.xml +0 -5
  21. data/test/fixtures/invalid_job_error.xml +0 -5
  22. data/test/fixtures/invalid_session_error.xml +0 -5
  23. data/test/fixtures/job_abort_request.xml +0 -1
  24. data/test/fixtures/job_abort_response.xml +0 -25
  25. data/test/fixtures/job_close_request.xml +0 -1
  26. data/test/fixtures/job_close_response.xml +0 -25
  27. data/test/fixtures/job_create_request.xml +0 -1
  28. data/test/fixtures/job_create_response.xml +0 -25
  29. data/test/fixtures/job_info_response.xml +0 -25
  30. data/test/fixtures/login_error.xml +0 -1
  31. data/test/fixtures/login_request.xml +0 -1
  32. data/test/fixtures/login_response.xml +0 -39
  33. data/test/fixtures/query_result_list_response.xml +0 -1
  34. data/test/fixtures/query_result_response.csv +0 -5
  35. data/test/lib/test_batch.rb +0 -252
  36. data/test/lib/test_batch_result.rb +0 -36
  37. data/test/lib/test_core_extensions.rb +0 -15
  38. data/test/lib/test_initialization.rb +0 -80
  39. data/test/lib/test_job.rb +0 -247
  40. data/test/lib/test_query_result_collection.rb +0 -86
  41. data/test/test_helper.rb +0 -32
@@ -1 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?><jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload"><operation>upsert</operation><object>VideoEvent__c</object><externalIdFieldName>Id__c</externalIdFieldName><contentType>CSV</contentType></jobInfo>
@@ -1,25 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload">
3
- <id>750E00000004MzbIAE</id>
4
- <operation>upsert</operation>
5
- <object>VideoEvent__c</object>
6
- <createdById>005E00000017spfIAA</createdById>
7
- <createdDate>2012-05-29T21:50:47.000Z</createdDate>
8
- <systemModstamp>2012-05-29T21:50:47.000Z</systemModstamp>
9
- <state>Open</state>
10
- <externalIdFieldName>Id__c</externalIdFieldName>
11
- <concurrencyMode>Parallel</concurrencyMode>
12
- <contentType>CSV</contentType>
13
- <numberBatchesQueued>0</numberBatchesQueued>
14
- <numberBatchesInProgress>0</numberBatchesInProgress>
15
- <numberBatchesCompleted>0</numberBatchesCompleted>
16
- <numberBatchesFailed>0</numberBatchesFailed>
17
- <numberBatchesTotal>0</numberBatchesTotal>
18
- <numberRecordsProcessed>0</numberRecordsProcessed>
19
- <numberRetries>0</numberRetries>
20
- <apiVersion>24.0</apiVersion>
21
- <numberRecordsFailed>0</numberRecordsFailed>
22
- <totalProcessingTime>0</totalProcessingTime>
23
- <apiActiveProcessingTime>0</apiActiveProcessingTime>
24
- <apexProcessingTime>0</apexProcessingTime>
25
- </jobInfo>
@@ -1,25 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><jobInfo
2
- xmlns="http://www.force.com/2009/06/asyncapi/dataload">
3
- <id>750E00000004N1mIAE</id>
4
- <operation>upsert</operation>
5
- <object>VideoEvent__c</object>
6
- <createdById>005E00000017spfIAA</createdById>
7
- <createdDate>2012-05-30T04:08:30.000Z</createdDate>
8
- <systemModstamp>2012-05-30T04:08:30.000Z</systemModstamp>
9
- <state>Open</state>
10
- <externalIdFieldName>Id__c</externalIdFieldName>
11
- <concurrencyMode>Parallel</concurrencyMode>
12
- <contentType>CSV</contentType>
13
- <numberBatchesQueued>0</numberBatchesQueued>
14
- <numberBatchesInProgress>0</numberBatchesInProgress>
15
- <numberBatchesCompleted>0</numberBatchesCompleted>
16
- <numberBatchesFailed>0</numberBatchesFailed>
17
- <numberBatchesTotal>0</numberBatchesTotal>
18
- <numberRecordsProcessed>0</numberRecordsProcessed>
19
- <numberRetries>0</numberRetries>
20
- <apiVersion>24.0</apiVersion>
21
- <numberRecordsFailed>0</numberRecordsFailed>
22
- <totalProcessingTime>0</totalProcessingTime>
23
- <apiActiveProcessingTime>0</apiActiveProcessingTime>
24
- <apexProcessingTime>0</apexProcessingTime>
25
- </jobInfo>
@@ -1 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode>sf:INVALID_LOGIN</faultcode><faultstring>INVALID_LOGIN: Invalid username, password, security token; or user locked out.</faultstring><detail><sf:LoginFault xsi:type="sf:LoginFault"><sf:exceptionCode>INVALID_LOGIN</sf:exceptionCode><sf:exceptionMessage>Invalid username, password, security token; or user locked out.</sf:exceptionMessage></sf:LoginFault></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
@@ -1 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><n1:login xmlns:n1="urn:partner.soap.sforce.com"><n1:username>MyUsername</n1:username><n1:password>MyPassword</n1:password></n1:login></env:Body></env:Envelope>
@@ -1,39 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3
- <soapenv:Body>
4
- <loginResponse>
5
- <result>
6
- <metadataServerUrl>https://na9-api.salesforce.com/services/Soap/m/24.0/00DE0000000YSKp</metadataServerUrl>
7
- <passwordExpired>false</passwordExpired>
8
- <sandbox>false</sandbox>
9
- <serverUrl>https://na9-api.salesforce.com/services/Soap/u/24.0/00DE0000000YSKp</serverUrl>
10
- <sessionId>00DE0000000YSKp!AQ4AQNQhDKLMORZx2NwZppuKfure.ChCmdI3S35PPxpNA5MHb3ZVxhYd5STM3euVJTI5.39s.jOBT.3mKdZ3BWFDdIrddS8O</sessionId>
11
- <userId>005E00000017spfIAA</userId>
12
- <userInfo>
13
- <accessibilityMode>false</accessibilityMode>
14
- <currencySymbol>$</currencySymbol>
15
- <orgAttachmentFileSizeLimit>5242880</orgAttachmentFileSizeLimit>
16
- <orgDefaultCurrencyIsoCode>USD</orgDefaultCurrencyIsoCode>
17
- <orgDisallowHtmlAttachments>false</orgDisallowHtmlAttachments>
18
- <orgHasPersonAccounts>false</orgHasPersonAccounts>
19
- <organizationId>00DE0000000YSKpMAO</organizationId>
20
- <organizationMultiCurrency>false</organizationMultiCurrency>
21
- <organizationName>Gmail</organizationName>
22
- <profileId>00eE0000000oANhIAM</profileId>
23
- <roleId xsi:nil="true" />
24
- <sessionSecondsValid>7200</sessionSecondsValid>
25
- <userDefaultCurrencyIsoCode xsi:nil="true" />
26
- <userEmail>jjfutbol@gmail.com</userEmail>
27
- <userFullName>Javier Julio</userFullName>
28
- <userId>005E00000017spfIAA</userId>
29
- <userLanguage>en_US</userLanguage>
30
- <userLocale>en_US</userLocale>
31
- <userName>jjfutbol@gmail.com</userName>
32
- <userTimeZone>America/Panama</userTimeZone>
33
- <userType>Standard</userType>
34
- <userUiSkin>Theme3</userUiSkin>
35
- </userInfo>
36
- </result>
37
- </loginResponse>
38
- </soapenv:Body>
39
- </soapenv:Envelope>
@@ -1 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><result-list xmlns="http://www.force.com/2009/06/asyncapi/dataload"><result>752E0000000TNaq</result></result-list>
@@ -1,5 +0,0 @@
1
- "Id__c","Title__c","IsPreview__c"
2
- "23456.0","A second test!","true"
3
- "12345.0","This is a test video","false"
4
- "3456.0","Some long title","false"
5
- "4567.0","Another test title for testing","true"
@@ -1,252 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestBatch < Test::Unit::TestCase
4
-
5
- def setup
6
- options = {
7
- :username => 'myusername',
8
- :password => 'mypassword'
9
- }
10
-
11
- @client = SalesforceBulk::Client.new(options)
12
- bypass_authentication(@client)
13
- @batch = SalesforceBulk::Batch.new
14
- @headers = {"Content-Type" => "text/csv; charset=UTF-8", 'X-Sfdc-Session' => '123456789'}
15
- @headersWithXml = {'Content-Type' => 'application/xml', 'X-Sfdc-Session' => '123456789'}
16
- end
17
-
18
- test "initialize from XML" do
19
- xml = fixture("batch_info_response.xml")
20
- batch = SalesforceBulk::Batch.new_from_xml(XmlSimple.xml_in(xml, 'ForceArray' => false))
21
-
22
- assert_equal batch.id, '751E00000004ZRbIAM'
23
- assert_equal batch.job_id, '750E00000004N97IAE'
24
- assert_equal batch.state, 'Completed'
25
- assert_equal batch.state_message, 'Success'
26
- assert_equal batch.created_at, DateTime.parse('2012-05-31T01:22:47.000Z')
27
- assert_equal batch.completed_at, DateTime.parse('2012-05-31T01:22:47.000Z')
28
- assert_equal batch.processed_records, 2
29
- assert_equal batch.failed_records, 0
30
- assert_equal batch.total_processing_time, 72
31
- assert_equal batch.api_active_processing_time, 28
32
- assert_equal batch.apex_processing_time, 0
33
- end
34
-
35
- test "state?" do
36
- @batch.state = "Completed"
37
- assert @batch.state?('Completed')
38
-
39
- @batch.state = "COMPLETED"
40
- assert @batch.state?('completed')
41
-
42
- @batch.state = "Failed"
43
- assert !@batch.state?('Queued')
44
- end
45
-
46
- test "state is marked queued" do
47
- @batch.state = "Queued"
48
- assert @batch.queued?
49
-
50
- @batch.state = nil
51
- assert !@batch.queued?
52
- end
53
-
54
- test "state is marked in progress" do
55
- @batch.state = "InProgress"
56
- assert @batch.in_progress?
57
-
58
- @batch.state = nil
59
- assert !@batch.in_progress?
60
- end
61
-
62
- test "state is marked completed" do
63
- @batch.state = "Completed"
64
- assert @batch.completed?
65
-
66
- @batch.state = nil
67
- assert !@batch.completed?
68
- end
69
-
70
- test "state is marked failed" do
71
- @batch.state = "Failed"
72
- assert @batch.failed?
73
-
74
- @batch.state = nil
75
- assert !@batch.failed?
76
- end
77
-
78
- test "should add a batch to a job and return a successful response" do
79
- request = fixture("batch_create_request.csv")
80
- response = fixture("batch_create_response.xml")
81
- job_id = "750E00000004NRfIAM"
82
- batch_id = "751E00000004ZmUIAU"
83
- data = [
84
- {:Id__c => '12345', :Title__c => "This is a test video", :IsPreview__c => nil},
85
- {:Id__c => '23456', :Title__c => "A second test!", :IsPreview__c => true}
86
- ]
87
-
88
- if RUBY_VERSION < '1.9'
89
- data.first.stubs(:keys).returns([:Id__c, :Title__c, :IsPreview__c])
90
- end
91
-
92
- stub_request(:post, "#{api_url(@client)}job/#{job_id}/batch").with(:body => request, :headers => @headers).to_return(:body => response, :status => 200)
93
-
94
- batch = @client.add_batch(job_id, data)
95
-
96
- assert_requested :post, "#{api_url(@client)}job/#{job_id}/batch", :body => request, :headers => @headers, :times => 1
97
-
98
- assert_equal batch.id, batch_id
99
- assert_equal batch.job_id, job_id
100
- assert_equal batch.state, 'Queued'
101
- assert_equal batch.created_at, DateTime.parse('2012-06-02T21:03:56.000Z')
102
- assert_equal batch.completed_at, DateTime.parse('2012-06-02T21:03:56.000Z')
103
- assert_equal batch.processed_records, 0
104
- assert_equal batch.failed_records, 0
105
- assert_equal batch.total_processing_time, 0
106
- assert_equal batch.api_active_processing_time, 0
107
- assert_equal batch.apex_processing_time, 0
108
- end
109
-
110
- test "should raise ArgumentError when given data array length exceeding 10000" do
111
- data = (1..10100).map { |index| {:Id => index} }
112
-
113
- assert_raise ArgumentError do
114
- @client.add_batch("750E00000004NRfIAM", data)
115
- end
116
- end
117
-
118
- test "should retrieve info for all batches in a job in a single request" do
119
- response = fixture("batch_info_list_response.xml")
120
- job_id = "750E00000004N97IAE"
121
-
122
- stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch").with(:headers => @headersWithXml).to_return(:body => response, :status => 200)
123
-
124
- batches = @client.batch_info_list(job_id)
125
-
126
- assert_requested :get, "#{api_url(@client)}job/#{job_id}/batch", :headers => @headersWithXml, :times => 1
127
-
128
- assert_kind_of Array, batches
129
- assert_kind_of SalesforceBulk::Batch, batches.first
130
- assert_equal batches.length, 2
131
-
132
- batch = batches.first
133
- assert_equal batch.id, "751E00000004ZRbIAM"
134
- assert_equal batch.job_id, job_id
135
- assert_equal batch.state, 'Completed'
136
- assert_equal batch.created_at, DateTime.parse('2012-05-31T01:22:47.000Z')
137
- assert_equal batch.completed_at, DateTime.parse('2012-05-31T01:22:47.000Z')
138
- assert_equal batch.processed_records, 2
139
- assert_equal batch.failed_records, 0
140
- assert_equal batch.total_processing_time, 72
141
- assert_equal batch.api_active_processing_time, 28
142
- assert_equal batch.apex_processing_time, 0
143
-
144
- batch = batches.last
145
- assert_equal batch.id, "751E00000004ZQsIAM"
146
- assert_equal batch.job_id, job_id
147
- assert_equal batch.state, 'Completed'
148
- assert_equal batch.created_at, DateTime.parse('2012-05-31T01:23:20.000Z')
149
- assert_equal batch.completed_at, DateTime.parse('2012-05-31T01:23:20.000Z')
150
- assert_equal batch.processed_records, 2
151
- assert_equal batch.failed_records, 0
152
- assert_equal batch.total_processing_time, 72
153
- assert_equal batch.api_active_processing_time, 28
154
- assert_equal batch.apex_processing_time, 0
155
- end
156
-
157
- test "should retrieve batch info" do
158
- response = fixture("batch_info_response.xml")
159
- job_id = "750E00000004N97IAE"
160
- batch_id = "751E00000004ZRbIAM"
161
-
162
- stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}").with(:headers => @headersWithXml).to_return(:body => response, :status => 200)
163
-
164
- batch = @client.batch_info(job_id, batch_id)
165
-
166
- assert_requested :get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}", :headers => @headersWithXml, :times => 1
167
-
168
- assert_equal batch.id, batch_id
169
- assert_equal batch.job_id, job_id
170
- assert_equal batch.state, 'Completed'
171
- assert_equal batch.created_at, DateTime.parse('2012-05-31T01:22:47.000Z')
172
- assert_equal batch.completed_at, DateTime.parse('2012-05-31T01:22:47.000Z')
173
- assert_equal batch.processed_records, 2
174
- assert_equal batch.failed_records, 0
175
- assert_equal batch.total_processing_time, 72
176
- assert_equal batch.api_active_processing_time, 28
177
- assert_equal batch.apex_processing_time, 0
178
- end
179
-
180
- test "should return batch result for a non-querying job" do
181
- response = fixture("batch_result_list_response.csv")
182
- job_id = "750E00000004NRa"
183
- batch_id = "751E00000004ZmK"
184
-
185
- # Batches that are created using CSV will always return
186
- # results in CSV format despite requesting with XML content type.
187
- # Thus the content type header is ignored.
188
-
189
- stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result").to_return(:body => response, :status => 200)
190
-
191
- results = @client.batch_result(job_id, batch_id)
192
-
193
- assert_requested :get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result", :times => 1
194
-
195
- assert_kind_of SalesforceBulk::BatchResultCollection, results
196
- assert_kind_of Array, results
197
- assert_equal results.length, 2
198
- assert_equal results.job_id, job_id
199
- assert_equal results.batch_id, batch_id
200
- assert_equal results.first.success, true
201
- assert_equal results.first.created, false
202
- assert_equal results.first.error?, false
203
- assert_equal results.first.error, ''
204
- end
205
-
206
- test "retrieve result id for a query operation" do
207
- response = fixture("query_result_list_response.xml")
208
- job_id = "750E00000004NnR"
209
- batch_id = "751E00000004aEY"
210
- result_id = "752E0000000TNaq"
211
-
212
- stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result").with(:headers => @headersWithXml).to_return(:body => response, :status => 200)
213
-
214
- @client.expects(:query_result).with(job_id, batch_id, result_id).returns([])
215
-
216
- result = @client.batch_result(job_id, batch_id)
217
-
218
- assert_requested :get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result", :headers => @headersWithXml, :times => 1
219
- assert_kind_of SalesforceBulk::QueryResultCollection, result
220
- assert_equal result.job_id, job_id
221
- assert_equal result.batch_id, batch_id
222
- assert_equal result.result_id, result_id
223
- end
224
-
225
- test "retrieve and parse a query result successfully" do
226
- response = fixture("query_result_response.csv")
227
- job_id = "750E00000004NnR"
228
- batch_id = "751E00000004aEY"
229
- result_id = "752E0000000TNaq"
230
-
231
- stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result/#{result_id}").with(:headers => @headers).to_return(:body => response, :status => 200)
232
-
233
- result = @client.query_result(job_id, batch_id, result_id)
234
-
235
- assert_requested :get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result/#{result_id}", :headers => @headers, :times => 1
236
- assert_kind_of Array, result
237
- assert result.length == 4
238
- end
239
-
240
- test "should raise SalesforceError on invalid batch response" do
241
- response = fixture("invalid_batch_error.xml")
242
- job_id = "750E00000004NnR"
243
- batch_id = "751E00000004aEY"
244
-
245
- stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result").with(:headers => @headersWithXml).to_return(:body => response, :status => 400)
246
-
247
- assert_raise SalesforceBulk::SalesforceError do
248
- @client.batch_result(job_id, batch_id)
249
- end
250
- end
251
-
252
- end
@@ -1,36 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestBatchResult < Test::Unit::TestCase
4
-
5
- def setup
6
- @result_created = SalesforceBulk::BatchResult.new('123', true, true, '')
7
- @result_updated = SalesforceBulk::BatchResult.new('123', true, false, '')
8
- @result_failed = SalesforceBulk::BatchResult.new('123', false, false, 'Some Error Message This Is')
9
- end
10
-
11
- test "basic initialization" do
12
- assert_equal @result_created.id, '123'
13
- assert_equal @result_created.success, true
14
- assert_equal @result_created.successful?, true
15
- assert_equal @result_created.created, true
16
- assert_equal @result_created.created?, true
17
- assert_equal @result_created.error, ''
18
- assert_equal @result_created.error?, false
19
- assert_equal @result_created.updated?, false
20
- end
21
-
22
- test "error?" do
23
- assert @result_failed.error?
24
-
25
- assert !@result_created.error?
26
- assert !@result_updated.error?
27
- end
28
-
29
- test "updated?" do
30
- assert @result_updated.updated?
31
-
32
- assert !@result_created.updated?
33
- assert !@result_failed.updated?
34
- end
35
-
36
- end
@@ -1,15 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestCoreExtensions < Test::Unit::TestCase
4
-
5
- test "to_b" do
6
- assert_equal "true".to_b, true
7
- assert_equal "TRUE".to_b, true
8
- assert_equal "false".to_b, false
9
- assert_equal "FALSE".to_b, false
10
- assert_equal " true ".to_b, true
11
- assert_equal " false ".to_b, false
12
- assert_equal "Any true value".to_b, "Any true value"
13
- end
14
-
15
- end
@@ -1,80 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestInitialization < Test::Unit::TestCase
4
-
5
- def setup
6
- @options = {
7
- :username => 'MyUsername',
8
- :password => 'MyPassword',
9
- }
10
-
11
- @client = SalesforceBulk::Client.new(@options)
12
- end
13
-
14
- test "initialization with default values" do
15
- assert_not_nil @client
16
- assert_equal @client.username, @options[:username]
17
- assert_equal @client.password, @options[:password]
18
- assert_equal @client.login_host, 'login.salesforce.com'
19
- assert_equal @client.version, 24.0
20
- end
21
-
22
- test "initialization overriding all default values" do
23
- @options.merge!({:login_host => 'newhost.salesforce.com', :version => 1.0})
24
-
25
- client = SalesforceBulk::Client.new(@options)
26
-
27
- assert_equal client.username, @options[:username]
28
- assert_equal client.password, @options[:password]
29
- assert_equal client.login_host, @options[:login_host]
30
- assert_equal client.version, @options[:version]
31
- end
32
-
33
- test "initialization with a YAML file" do
34
- client = SalesforceBulk::Client.new(fixture_path('config.yml'))
35
-
36
- assert_equal client.username, 'MyUsername'
37
- assert_equal client.password, 'MyPassword'
38
- assert_equal client.login_host, 'myhost.mydomain.com'
39
- assert_equal client.version, 88.0
40
- end
41
-
42
- test "initialization with invalid key raises ArgumentError" do
43
- assert_raise ArgumentError do
44
- SalesforceBulk::Client.new(:non_existing_key => '')
45
- end
46
- end
47
-
48
- test "authentication" do
49
- headers = {'Content-Type' => 'text/xml', 'SOAPAction' => 'login'}
50
- request = fixture("login_request.xml")
51
- response = fixture("login_response.xml")
52
-
53
- stub_request(:post, "https://#{@client.login_host}/services/Soap/u/24.0").with(:body => request, :headers => headers).to_return(:body => response, :status => 200)
54
-
55
- result = @client.authenticate()
56
-
57
- assert_requested :post, "https://#{@client.login_host}/services/Soap/u/24.0", :body => request, :headers => headers, :times => 1
58
-
59
- assert_equal @client.instance_host, 'na9-api.salesforce.com'
60
- assert_equal @client.instance_variable_get('@session_id'), '00DE0000000YSKp!AQ4AQNQhDKLMORZx2NwZppuKfure.ChCmdI3S35PPxpNA5MHb3ZVxhYd5STM3euVJTI5.39s.jOBT.3mKdZ3BWFDdIrddS8O'
61
- assert_equal @client, result
62
- end
63
-
64
- test "parsing instance id from server url" do
65
- assert_equal @client.instance_id('https://na1-api.salesforce.com'), 'na1-api'
66
- assert_equal @client.instance_id('https://na23-api.salesforce.com'), 'na23-api'
67
- assert_equal @client.instance_id('https://na345-api.salesforce.com'), 'na345-api'
68
- assert_equal @client.instance_id('https://NA345-API.salesforce.com'), 'NA345-API'
69
- assert_equal @client.instance_id('https://test.api.na345-api.salesforce.com'), 'test.api.na345-api'
70
-
71
- # protocol shouldn't matter, its just part of the host name we are after
72
- assert_equal @client.instance_id('://na1-api.salesforce.com'), 'na1-api'
73
- assert_equal @client.instance_id('://na23-api.salesforce.com'), 'na23-api'
74
-
75
- # in fact the .com portion shouldn't matter either
76
- assert_equal @client.instance_id('://na1-api.salesforce'), 'na1-api'
77
- assert_equal @client.instance_id('://na23-api.salesforce'), 'na23-api'
78
- end
79
-
80
- end