bintje 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/COPYRIGHT.txt +162 -0
- data/Gemfile +4 -0
- data/README.md +51 -0
- data/Rakefile +3 -0
- data/bintje.gemspec +27 -0
- data/copyright_script.sh +8 -0
- data/lib/bintje.rb +29 -0
- data/lib/bintje/version.rb +25 -0
- data/lib/helpers.rb +22 -0
- data/lib/open_object.rb +210 -0
- data/lib/xmlrpc/parser_patch.rb +50 -0
- data/license_header.txt +22 -0
- data/spec/data/faultCode.txt +1 -0
- data/spec/data/faultString.txt +5 -0
- data/spec/openerp_common_spec.rb +77 -0
- data/spec/reciever_model_spec.rb +270 -0
- data/spec/request_shared_examples.rb +42 -0
- data/spec/server_stub.rb +155 -0
- data/spec/spec_helper.rb +16 -0
- metadata +131 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
##
|
2
|
+
#
|
3
|
+
# Bintje Maps OpenERP xml object to Ruby objects
|
4
|
+
#
|
5
|
+
# Copyright (C) 2013 Siclic
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Affero General Public License as
|
9
|
+
# published by the Free Software Foundation, either version 3 of the
|
10
|
+
# License, or (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Affero General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Affero General Public License
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
##
|
21
|
+
|
22
|
+
|
23
|
+
module XMLRPC
|
24
|
+
module Convert
|
25
|
+
|
26
|
+
# Converts the given +hash+ to an XMLRPC::FaultException object by passing
|
27
|
+
# the +faultCode+ and +faultString+ attributes of the Hash to
|
28
|
+
# XMLRPC::FaultException.new
|
29
|
+
#
|
30
|
+
# Raises an Exception if the given +hash+ doesn't meet the requirements.
|
31
|
+
# Those requirements being:
|
32
|
+
# * 2 keys
|
33
|
+
# * <code>'faultCode'</code> key is an Integer
|
34
|
+
# * <code>'faultString'</code> key is a String
|
35
|
+
#
|
36
|
+
# @param hash [Hash] the fault exception
|
37
|
+
# @return [XMLRPC:FaultException] the better exception
|
38
|
+
def self.fault(hash)
|
39
|
+
if hash.kind_of? Hash and hash.size == 2 and
|
40
|
+
hash.has_key? "faultCode" and hash.has_key? "faultString" and
|
41
|
+
hash["faultCode"].kind_of? Integer or hash["faultCode"].kind_of? String and hash["faultString"].kind_of? String
|
42
|
+
|
43
|
+
XMLRPC::FaultException.new(hash["faultCode"], hash["faultString"])
|
44
|
+
else
|
45
|
+
raise "wrong fault-structure: #{hash.inspect}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
data/license_header.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
##
|
2
|
+
#
|
3
|
+
# Bintje Maps OpenERP xml object to Ruby objects
|
4
|
+
#
|
5
|
+
# Copyright (C) 2013 Siclic
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Affero General Public License as
|
9
|
+
# published by the Free Software Foundation, either version 3 of the
|
10
|
+
# License, or (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Affero General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Affero General Public License
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
##
|
21
|
+
|
22
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
warning -- Erreur d'accès Opération interdite par les règles d'accès, ou effectué sur un document déjà supprimé (Opération : lecture, Type de document: openstc.ask).
|
@@ -0,0 +1,5 @@
|
|
1
|
+
XMLRPC::FaultException ():
|
2
|
+
app/controllers/openstc/api/intervention_requests_controller.rb:19:in `update'
|
3
|
+
Rendered /home/cedric/.rvm/gems/ruby-2.0.0-p195@barakafrites/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
|
4
|
+
Rendered /home/cedric/.rvm/gems/ruby-2.0.0-p195@barakafrites/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.6ms)
|
5
|
+
Rendered /home/cedric/.rvm/gems/ruby-2.0.0-p195@barakafrites/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (30.2ms)
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'request_shared_examples'
|
3
|
+
|
4
|
+
describe "OpenObject" do
|
5
|
+
|
6
|
+
context 'for common context' do
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
open_object_settings
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.common_client' do
|
13
|
+
it 'build new XMLRPC connection client Proxy' do
|
14
|
+
allow_message_expectations_on_nil
|
15
|
+
XMLRPC::Client.should_receive(:new)
|
16
|
+
.with('localhost', '/xmlrpc/common', '8069')
|
17
|
+
.and_return().should_receive(:proxy).with(nil)
|
18
|
+
OpenObject.common_client
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.login' do
|
23
|
+
|
24
|
+
context 'with wrong database name' do
|
25
|
+
before(:each) do
|
26
|
+
ServerStub::Common::Login.wrong_data_base_name
|
27
|
+
end
|
28
|
+
let(:response) { OpenObject.login('dbname', 'user', 'password') }
|
29
|
+
|
30
|
+
it "response.success : false" do
|
31
|
+
response.success.should be false
|
32
|
+
end
|
33
|
+
|
34
|
+
it " response.errors : #{ServerStub::Common::Login.wrong_database_name_fault_code}" do
|
35
|
+
response.errors[:faultCode].should include(ServerStub::Common::Login.wrong_database_name_fault_code)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'with wrong user name and/or password' do
|
41
|
+
before(:each) do
|
42
|
+
ServerStub::Common::Login.wrong_user_name
|
43
|
+
end
|
44
|
+
let(:response) { OpenObject.login('dbname', 'user', 'password') }
|
45
|
+
|
46
|
+
it "response.success : false" do
|
47
|
+
response.success.should be false
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
context 'on successful authentication request' do
|
54
|
+
before(:each) do
|
55
|
+
ServerStub::Common::Login.successful
|
56
|
+
end
|
57
|
+
let(:response) { OpenObject.login('dbname', 'user', 'password') }
|
58
|
+
|
59
|
+
it_behaves_like 'any successful request'
|
60
|
+
|
61
|
+
it "response.content.class = Fixnum (user id)" do
|
62
|
+
response.content.class.should be Fixnum
|
63
|
+
end
|
64
|
+
|
65
|
+
it "response.content == #{ServerStub::Common::Login.uid} (expected user id)" do
|
66
|
+
response.content.should be ServerStub::Common::Login.uid
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,270 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'reciever model' do
|
4
|
+
before(:each) do
|
5
|
+
open_object_settings
|
6
|
+
end
|
7
|
+
let(:user_context) { {dbname: 'dbname', uid: 2, pwd: 'pwd'} }
|
8
|
+
|
9
|
+
class ReceiverModel
|
10
|
+
include OpenObject
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should respond to .open_object_model' do
|
14
|
+
ReceiverModel.should respond_to(:open_object_model)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
describe '.open_object_model_name' do
|
19
|
+
context 'when not defined in model' do
|
20
|
+
|
21
|
+
it 'should be a string' do
|
22
|
+
ReceiverModel.open_object_model.class.should be String
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should be humanized model name' do
|
26
|
+
ReceiverModel.open_object_model.should eql 'receiver_model'
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe ".set_open_object_mode('another_name')" do
|
32
|
+
class AnotherModel
|
33
|
+
include OpenObject
|
34
|
+
end
|
35
|
+
it "should set the open_object model name with the given string" do
|
36
|
+
AnotherModel.set_open_object_model "another_name"
|
37
|
+
AnotherModel.open_object_model.should eql "another_name"
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
describe ".connection(user_context:{dbname:String,uid:Fixnum,pwd:String})" do
|
45
|
+
|
46
|
+
|
47
|
+
it "should build a new XMLRPC connection" do
|
48
|
+
allow_message_expectations_on_nil
|
49
|
+
XMLRPC::Client.should_receive(:new)
|
50
|
+
.with(OpenObject.host, OpenObject.object, OpenObject.port)
|
51
|
+
.and_return().should_receive(:proxy)
|
52
|
+
ReceiverModel.connection(user_context)
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe ".search(user_context, args = [], limit:Fixnum, offset:Fixnum)" do
|
59
|
+
before(:each) do
|
60
|
+
allow_message_expectations_on_nil
|
61
|
+
ServerStub::Object::Search.prologue
|
62
|
+
end
|
63
|
+
|
64
|
+
let(:response) { ReceiverModel.search(user_context, [["field", "operator", "value"]]) }
|
65
|
+
|
66
|
+
|
67
|
+
context "with offset and limit parameters" do
|
68
|
+
let(:response) { ReceiverModel.search(user_context, [["field", "operator", "value"]],offset: 10,limit: 5) }
|
69
|
+
|
70
|
+
it "invokes execute with model_name, search, [params], offset,limit" do
|
71
|
+
ServerStub::Object::Connection.prologue.should_receive(:execute)
|
72
|
+
.with('receiver_model','search',[["field", "operator", "value"]], 10 , 5 )
|
73
|
+
response
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
context "with limit parameter (missing offset)" do
|
79
|
+
let(:response) { ReceiverModel.search(user_context, [["field", "operator", "value"]],limit: 5) }
|
80
|
+
|
81
|
+
it "invokes execute with model_name, search, [params], offset :0, limit " do
|
82
|
+
ServerStub::Object::Connection.prologue.should_receive(:execute)
|
83
|
+
.with('receiver_model','search',[["field", "operator", "value"]], 0 , 5 )
|
84
|
+
response
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
context "with offset parameter (missing limit)" do
|
90
|
+
let(:response) { ReceiverModel.search(user_context, [["field", "operator", "value"]], offset: 10) }
|
91
|
+
|
92
|
+
it "invokes execute with model_name, search, [params], offset, limit: 0" do
|
93
|
+
ServerStub::Object::Connection.prologue.should_receive(:execute)
|
94
|
+
.with('receiver_model','search',[["field", "operator", "value"]], 10 , 0 )
|
95
|
+
response
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
context "without limit and offset" do
|
101
|
+
|
102
|
+
it_behaves_like "any object request"
|
103
|
+
|
104
|
+
it "invokes execute with model_name, search, [params], 0, 0" do
|
105
|
+
ServerStub::Object::Connection.prologue.should_receive(:execute)
|
106
|
+
.with('receiver_model','search',[["field", "operator", "value"]], 0,0)
|
107
|
+
response
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
context "with order parameter" do
|
114
|
+
let(:response) { ReceiverModel.search(user_context, [["field", "operator", "value"]], order: 'name DESC') }
|
115
|
+
|
116
|
+
it "invokes execute with model_name, search, [params], 0, 0, order" do
|
117
|
+
ServerStub::Object::Connection.prologue.should_receive(:execute)
|
118
|
+
.with('receiver_model','search',[["field", "operator", "value"]], 0,0, 'name DESC')
|
119
|
+
response
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
context "successful request" do
|
125
|
+
before(:each) { ServerStub::Object::Search.successful }
|
126
|
+
let(:response) { ReceiverModel.search(user_context, [["field", "operator", "value"]]) }
|
127
|
+
|
128
|
+
it_behaves_like "any successful request"
|
129
|
+
|
130
|
+
it "response.content should be an Array" do
|
131
|
+
response.content.should be_an Array
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
context "failed request" do
|
137
|
+
before(:each) do
|
138
|
+
ServerStub::Object::Search.failure
|
139
|
+
end
|
140
|
+
|
141
|
+
it_behaves_like "any failed request"
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
describe ".read(user_context,[ids],[fields])" do
|
148
|
+
before(:each) do
|
149
|
+
allow_message_expectations_on_nil
|
150
|
+
ServerStub::Object::Read.prologue
|
151
|
+
end
|
152
|
+
|
153
|
+
let(:response) {ReceiverModel.read(user_context,[1,2],['fields']) }
|
154
|
+
|
155
|
+
it_behaves_like "any object request"
|
156
|
+
|
157
|
+
it "invokes execute with model_name, read, [ids], [fields]" do
|
158
|
+
ServerStub::Object::Connection.prologue.should_receive(:execute)
|
159
|
+
.with('receiver_model','read',[1,2],['fields'])
|
160
|
+
response
|
161
|
+
end
|
162
|
+
|
163
|
+
context "successful request" do
|
164
|
+
before(:each) do
|
165
|
+
ServerStub::Object::Read.successful
|
166
|
+
end
|
167
|
+
|
168
|
+
it_behaves_like "any successful request"
|
169
|
+
|
170
|
+
it "response.content should be Array" do
|
171
|
+
response.content.should be_an Array
|
172
|
+
end
|
173
|
+
|
174
|
+
it "reponse.content.first should be #{ServerStub::Object::Read.standard_response.first}" do
|
175
|
+
response.content.first.should eql ServerStub::Object::Read.standard_response.first
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
context "failed request" do
|
181
|
+
before(:each) do
|
182
|
+
ServerStub::Object::Read.failure
|
183
|
+
end
|
184
|
+
|
185
|
+
it_behaves_like "any failed request"
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
describe ".write(user_context,[ids],{field:'value'})" do
|
192
|
+
before(:each) do
|
193
|
+
allow_message_expectations_on_nil
|
194
|
+
ServerStub::Object::Write.prologue
|
195
|
+
end
|
196
|
+
let(:response) { ReceiverModel.write(user_context, [1,2],{field:'value'})}
|
197
|
+
|
198
|
+
it_behaves_like "any object request"
|
199
|
+
|
200
|
+
it "invokes execute with model_name, 'write', [ids], {field:'value'}" do
|
201
|
+
ServerStub::Object::Connection.prologue.should_receive(:execute)
|
202
|
+
.with('receiver_model', 'write', [1,2], {field:'value'})
|
203
|
+
response
|
204
|
+
end
|
205
|
+
|
206
|
+
context "successful request" do
|
207
|
+
before(:each) do
|
208
|
+
ServerStub::Object::Write.successful
|
209
|
+
end
|
210
|
+
|
211
|
+
it_behaves_like "any successful request"
|
212
|
+
|
213
|
+
it "response.content should be nil" do
|
214
|
+
response.content.should be nil
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
context "failed request" do
|
220
|
+
before(:each) do
|
221
|
+
ServerStub::Object::Write.failure
|
222
|
+
end
|
223
|
+
|
224
|
+
it_behaves_like "any failed request"
|
225
|
+
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
describe ".create(user_context,{field:value})" do
|
231
|
+
before(:each) do
|
232
|
+
allow_message_expectations_on_nil
|
233
|
+
ServerStub::Object::Create.prologue
|
234
|
+
end
|
235
|
+
|
236
|
+
let(:response) { ReceiverModel.create(user_context,{field:'value'})}
|
237
|
+
|
238
|
+
it_behaves_like "any object request"
|
239
|
+
|
240
|
+
it "invokes execute with model_name, 'create', {field:'value'}" do
|
241
|
+
ServerStub::Object::Connection.prologue.should_receive(:execute)
|
242
|
+
.with('receiver_model', 'create', {field:'value'})
|
243
|
+
response
|
244
|
+
end
|
245
|
+
|
246
|
+
context "successful request" do
|
247
|
+
before(:each) do
|
248
|
+
ServerStub::Object::Create.successful
|
249
|
+
end
|
250
|
+
|
251
|
+
it_behaves_like "any successful request"
|
252
|
+
|
253
|
+
it "reponse.content should be 1" do
|
254
|
+
response.content.should be 1
|
255
|
+
end
|
256
|
+
|
257
|
+
end
|
258
|
+
|
259
|
+
context "failed request" do
|
260
|
+
before(:each) do
|
261
|
+
ServerStub::Object::Create.failure
|
262
|
+
end
|
263
|
+
|
264
|
+
it_behaves_like "any failed request"
|
265
|
+
|
266
|
+
end
|
267
|
+
|
268
|
+
end
|
269
|
+
|
270
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module RequestSharedExamples
|
2
|
+
|
3
|
+
|
4
|
+
shared_examples_for "any request" do
|
5
|
+
it "response.class == OpenObject::BackendResponse" do
|
6
|
+
response.class.should be OpenObject::BackendResponse
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
shared_examples_for "any successful request" do
|
11
|
+
it_behaves_like "any request"
|
12
|
+
it "response.success : true" do
|
13
|
+
response.success.should be true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
shared_examples_for "any failed request" do
|
18
|
+
it_behaves_like "any request"
|
19
|
+
it "response.success : false" do
|
20
|
+
response.success.should be false
|
21
|
+
end
|
22
|
+
|
23
|
+
it "response.errors[:faultCode] Server faultCode" do
|
24
|
+
response.errors[:faultCode].should eql ServerStub.faultCode
|
25
|
+
end
|
26
|
+
|
27
|
+
it "response.errors[:faultString] Server faultString" do
|
28
|
+
response.errors[:faultString].should eql ServerStub.faultString
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
shared_examples_for "any object request" do
|
35
|
+
it "creates connection with context" do
|
36
|
+
ReceiverModel.should_receive(:connection).with(user_context)
|
37
|
+
response
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|