opencpu 0.7.8 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +13 -2
- data/lib/opencpu/client.rb +29 -16
- data/lib/opencpu/configuration.rb +3 -0
- data/lib/opencpu/version.rb +2 -2
- data/spec/fixtures/test.csv +3 -0
- data/spec/fixtures/vcr_cassettes/animation_flip_coin.yml +1012 -1
- data/spec/fixtures/vcr_cassettes/url_encoded_request.yml +61 -0
- data/spec/lib/opencpu/client_spec.rb +44 -3
- data/spec/lib/opencpu/configuration_spec.rb +12 -0
- data/spec/lib/opencpu/delayed_calculation_spec.rb +10 -22
- metadata +6 -2
@@ -0,0 +1,61 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://public.opencpu.org/ocpu/library/base/R/identity/json
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: x=data.frame(x%3D1%2Cy%3D1)
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Server:
|
16
|
+
- nginx/1.4.6 (Ubuntu)
|
17
|
+
Date:
|
18
|
+
- Tue, 14 Oct 2014 19:01:39 GMT
|
19
|
+
Content-Type:
|
20
|
+
- application/json
|
21
|
+
Location:
|
22
|
+
- https://public.opencpu.org/ocpu/tmp/x0c19f32080/
|
23
|
+
Transfer-Encoding:
|
24
|
+
- chunked
|
25
|
+
Connection:
|
26
|
+
- keep-alive
|
27
|
+
Cache-Control:
|
28
|
+
- max-age=300, public
|
29
|
+
X-Ocpu-Session:
|
30
|
+
- x0c19f32080
|
31
|
+
Access-Control-Allow-Origin:
|
32
|
+
- "*"
|
33
|
+
Access-Control-Allow-Headers:
|
34
|
+
- Origin, Content-Type, Accept, Accept-Encoding, Cache-Control
|
35
|
+
Access-Control-Expose-Headers:
|
36
|
+
- Location, X-ocpu-session, Content-Type, Cache-Control
|
37
|
+
X-Ocpu-R:
|
38
|
+
- R version 3.1.1 (2014-07-10)
|
39
|
+
X-Ocpu-Locale:
|
40
|
+
- en_US.UTF-8
|
41
|
+
X-Ocpu-Time:
|
42
|
+
- 2014-10-14 12:01:39 PDT
|
43
|
+
X-Ocpu-Version:
|
44
|
+
- 1.4.4
|
45
|
+
X-Ocpu-Server:
|
46
|
+
- rApache
|
47
|
+
X-Ocpu-Cache:
|
48
|
+
- MISS
|
49
|
+
body:
|
50
|
+
encoding: UTF-8
|
51
|
+
string: |+
|
52
|
+
[
|
53
|
+
{
|
54
|
+
"x": 1,
|
55
|
+
"y": 1
|
56
|
+
}
|
57
|
+
]
|
58
|
+
|
59
|
+
http_version:
|
60
|
+
recorded_at: Tue, 14 Oct 2014 19:01:39 GMT
|
61
|
+
recorded_with: VCR 2.9.3
|
@@ -58,7 +58,7 @@ describe OpenCPU::Client do
|
|
58
58
|
|
59
59
|
it 'returns a DelayedCalculation with correct path' do
|
60
60
|
VCR.use_cassette :prepare do
|
61
|
-
expect(delayed_calculation.location).to
|
61
|
+
expect(delayed_calculation.location).to match "https://public.opencpu.org/ocpu/tmp/x[0-9a-f]+/"
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
@@ -70,9 +70,9 @@ describe OpenCPU::Client do
|
|
70
70
|
let(:client) { described_class.new }
|
71
71
|
|
72
72
|
it 'is used to quickly return JSON results' do
|
73
|
-
VCR.use_cassette :animation_flip_coin do
|
73
|
+
VCR.use_cassette :animation_flip_coin, record: :new_episodes do
|
74
74
|
response = client.execute(:animation, 'flip.coin')
|
75
|
-
expect(response).to
|
75
|
+
expect(response).to include('freq', 'nmax')
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -89,6 +89,36 @@ describe OpenCPU::Client do
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
+
context 'url encoded request' do
|
93
|
+
it 'sends the parameters url_encoded' do
|
94
|
+
VCR.use_cassette :url_encoded_request do |cassette|
|
95
|
+
response = client.execute(:base, :identity, format: nil, data: { x: 'data.frame(x=1,y=1)' })
|
96
|
+
params = cassette.serializable_hash['http_interactions'][0]['request']['body']['string']
|
97
|
+
expect(params).to eq "x=data.frame(x%3D1%2Cy%3D1)"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
it 'accepts R-code as parameters' do
|
101
|
+
VCR.use_cassette :url_encoded_request do |cassette|
|
102
|
+
response = client.execute(:base, :identity, format: nil, data: { x: 'data.frame(x=1,y=1)' })
|
103
|
+
expect(response).to eq [{"x"=>1, "y"=>1}]
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'multipart form / file uploads' do
|
109
|
+
it "works" do
|
110
|
+
skip # vcr is broken for file uploads https://github.com/vcr/vcr/issues/441
|
111
|
+
VCR.use_cassette :multi_part_request do |cassette|
|
112
|
+
# VCR.turn_off!
|
113
|
+
# WebMock.disable!
|
114
|
+
response = client.execute(:utils, 'read.csv', format: nil, data: { file: File.new('spec/fixtures/test.csv') })
|
115
|
+
# WebMock.enable!
|
116
|
+
# VCR.turn_on!
|
117
|
+
expect(response).to eq [{"head1"=>1, "head2"=>2, "head3"=>3}, {"head1"=>4, "head2"=>5, "head3"=>6}]
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
92
122
|
context 'user packages' do
|
93
123
|
before do
|
94
124
|
OpenCPU.configure do |config|
|
@@ -98,6 +128,7 @@ describe OpenCPU::Client do
|
|
98
128
|
config.timeout = 123
|
99
129
|
end
|
100
130
|
end
|
131
|
+
after { OpenCPU.reset_configuration! }
|
101
132
|
let(:client) { described_class.new }
|
102
133
|
|
103
134
|
it "can access user packages" do
|
@@ -131,4 +162,14 @@ describe OpenCPU::Client do
|
|
131
162
|
end
|
132
163
|
end
|
133
164
|
end
|
165
|
+
|
166
|
+
describe '#request_options' do
|
167
|
+
it 'uses verify_ssl setting' do
|
168
|
+
expect(described_class.new.send(:request_options, {}, nil)[:verify]).to be_truthy
|
169
|
+
OpenCPU.configure do |config|
|
170
|
+
config.verify_ssl = false
|
171
|
+
end
|
172
|
+
expect(described_class.new.send(:request_options, {}, nil)[:verify]).to be_falsy
|
173
|
+
end
|
174
|
+
end
|
134
175
|
end
|
@@ -89,4 +89,16 @@ describe OpenCPU::Configuration do
|
|
89
89
|
expect(config.fake_responses).to eq({})
|
90
90
|
end
|
91
91
|
end
|
92
|
+
|
93
|
+
describe "#verify_ssl" do
|
94
|
+
let(:config) { described_class.new }
|
95
|
+
it "defaults to true" do
|
96
|
+
expect(config.verify_ssl).to be_truthy
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'can be changed' do
|
100
|
+
config.verify_ssl = false
|
101
|
+
expect(config.verify_ssl).to be_falsy
|
102
|
+
end
|
103
|
+
end
|
92
104
|
end
|
@@ -29,43 +29,31 @@ describe OpenCPU::DelayedCalculation do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
let(:location) { "https://public.opencpu.org/ocpu/tmp/x09dd995a16/" }
|
32
|
-
let(:
|
33
|
-
[
|
34
|
-
"/ocpu/tmp/x09dd995a16/R/.val",
|
35
|
-
"/ocpu/tmp/x09dd995a16/graphics/1",
|
36
|
-
"/ocpu/tmp/x09dd995a16/graphics/2",
|
37
|
-
"/ocpu/tmp/x09dd995a16/graphics/3",
|
38
|
-
"/ocpu/tmp/x09dd995a16/graphics/4",
|
39
|
-
"/ocpu/tmp/x09dd995a16/source",
|
40
|
-
"/ocpu/tmp/x09dd995a16/console",
|
41
|
-
"/ocpu/tmp/x09dd995a16/info"
|
42
|
-
]
|
43
|
-
end
|
44
|
-
let(:delayed_calculation) { described_class.new location, resources }
|
32
|
+
let(:delayed_calculation) { OpenCPU::client.prepare('animation', 'flip.coin') }
|
45
33
|
|
46
34
|
describe "#graphics" do
|
47
35
|
|
48
36
|
it 'defines methods to access graphic functions' do
|
49
|
-
VCR.use_cassette :animation_flip_coin do
|
37
|
+
VCR.use_cassette :animation_flip_coin, record: :new_episodes do
|
50
38
|
expect { delayed_calculation.graphics }.not_to raise_error
|
51
39
|
expect { delayed_calculation.stdout }.to raise_error OpenCPU::ResponseNotAvailableError
|
52
40
|
end
|
53
41
|
end
|
54
42
|
|
55
43
|
it "returns a SVG by default" do
|
56
|
-
VCR.use_cassette :animation_flip_coin do
|
44
|
+
VCR.use_cassette :animation_flip_coin, record: :new_episodes do
|
57
45
|
expect(delayed_calculation.graphics).to include 'svg xmlns'
|
58
46
|
end
|
59
47
|
end
|
60
48
|
|
61
49
|
it "can return a PNG" do
|
62
|
-
VCR.use_cassette :animation_flip_coin do
|
50
|
+
VCR.use_cassette :animation_flip_coin, record: :new_episodes do
|
63
51
|
expect(delayed_calculation.graphics(0, :png)).to include 'PNG'
|
64
52
|
end
|
65
53
|
end
|
66
54
|
|
67
55
|
it "does not support formats except PNG and SVG" do
|
68
|
-
VCR.use_cassette :animation_flip_coin do
|
56
|
+
VCR.use_cassette :animation_flip_coin, record: :new_episodes do
|
69
57
|
expect { delayed_calculation.graphics(0, :svg) }.not_to raise_error
|
70
58
|
expect { delayed_calculation.graphics(0, :png) }.not_to raise_error
|
71
59
|
expect { delayed_calculation.graphics(0, :foo) }.to raise_error OpenCPU::UnsupportedFormatError
|
@@ -81,15 +69,15 @@ describe OpenCPU::DelayedCalculation do
|
|
81
69
|
describe 'standard getters' do
|
82
70
|
describe '#value' do
|
83
71
|
it "returns raw R calculation result" do
|
84
|
-
VCR.use_cassette :animation_flip_coin do
|
85
|
-
expect(delayed_calculation.value).to
|
72
|
+
VCR.use_cassette :animation_flip_coin, record: :new_episodes do
|
73
|
+
expect(delayed_calculation.value).to include "$freq"
|
86
74
|
end
|
87
75
|
end
|
88
76
|
end
|
89
77
|
|
90
78
|
describe '#stdout' do
|
91
79
|
it "returns cached stdout" do
|
92
|
-
VCR.use_cassette :animation_flip_coin do
|
80
|
+
VCR.use_cassette :animation_flip_coin, record: :new_episodes do
|
93
81
|
expect { delayed_calculation.stdout }.to raise_error OpenCPU::ResponseNotAvailableError
|
94
82
|
end
|
95
83
|
end
|
@@ -97,7 +85,7 @@ describe OpenCPU::DelayedCalculation do
|
|
97
85
|
|
98
86
|
describe '#warnings' do
|
99
87
|
it 'returns cached warnings' do
|
100
|
-
VCR.use_cassette :animation_flip_coin do
|
88
|
+
VCR.use_cassette :animation_flip_coin, record: :new_episodes do
|
101
89
|
expect { delayed_calculation.warnings }.to raise_error OpenCPU::ResponseNotAvailableError
|
102
90
|
end
|
103
91
|
end
|
@@ -105,7 +93,7 @@ describe OpenCPU::DelayedCalculation do
|
|
105
93
|
|
106
94
|
describe '#info' do
|
107
95
|
it 'returns cached info' do
|
108
|
-
VCR.use_cassette :animation_flip_coin do
|
96
|
+
VCR.use_cassette :animation_flip_coin, record: :new_episodes do
|
109
97
|
expect(delayed_calculation.info).to include("R version")
|
110
98
|
end
|
111
99
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opencpu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Malykh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yajl-ruby
|
@@ -206,10 +206,12 @@ files:
|
|
206
206
|
- lib/opencpu/delayed_calculation.rb
|
207
207
|
- lib/opencpu/version.rb
|
208
208
|
- opencpu.gemspec
|
209
|
+
- spec/fixtures/test.csv
|
209
210
|
- spec/fixtures/vcr_cassettes/animation_flip_coin.yml
|
210
211
|
- spec/fixtures/vcr_cassettes/digest_hmac.yml
|
211
212
|
- spec/fixtures/vcr_cassettes/digest_hmac_no_parameters.yml
|
212
213
|
- spec/fixtures/vcr_cassettes/prepare.yml
|
214
|
+
- spec/fixtures/vcr_cassettes/url_encoded_request.yml
|
213
215
|
- spec/fixtures/vcr_cassettes/user_digest_hmac.yml
|
214
216
|
- spec/lib/opencpu/client_spec.rb
|
215
217
|
- spec/lib/opencpu/configuration_spec.rb
|
@@ -241,10 +243,12 @@ signing_key:
|
|
241
243
|
specification_version: 4
|
242
244
|
summary: Wrapper around OpenCPU REST API
|
243
245
|
test_files:
|
246
|
+
- spec/fixtures/test.csv
|
244
247
|
- spec/fixtures/vcr_cassettes/animation_flip_coin.yml
|
245
248
|
- spec/fixtures/vcr_cassettes/digest_hmac.yml
|
246
249
|
- spec/fixtures/vcr_cassettes/digest_hmac_no_parameters.yml
|
247
250
|
- spec/fixtures/vcr_cassettes/prepare.yml
|
251
|
+
- spec/fixtures/vcr_cassettes/url_encoded_request.yml
|
248
252
|
- spec/fixtures/vcr_cassettes/user_digest_hmac.yml
|
249
253
|
- spec/lib/opencpu/client_spec.rb
|
250
254
|
- spec/lib/opencpu/configuration_spec.rb
|