forked from akretion/ooor
/
ooor_spec.rb
404 lines (337 loc) · 15.2 KB
/
ooor_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
require File.dirname(__FILE__) + '/../lib/ooor'
#RSpec executable specification; see http://rspec.info/ for more information.
#Run the file with the rspec command from the rspec gem
describe Ooor do
before(:all) do
@url = 'http://localhost:8069/xmlrpc'
@db_password = 'admin'
@username = 'admin'
@password = 'admin'
@database = 'ooor_test'
@ooor = Ooor.new(:url => @url, :username => @username, :password => @password)
end
it "should keep quiet if no database is mentioned" do
@ooor.loaded_models.should be_empty
end
it "should be able to list databases" do
@ooor.list.should be_kind_of(Array)
end
it "should be able to create a new database with demo data" do
unless @ooor.list.index(@database)
@ooor.create(@db_password, @database)
end
@ooor.list.index(@database).should_not be_nil
end
describe "Configure existing database" do
before(:all) do
@ooor = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database)
end
it "should be able to load a profile" do
accounting_module_ids = IrModuleModule.search(['|', ['name','=', 'sale'], ['name','=', 'account_voucher']])
accounting_module_ids.each do |accounting_module_id|
mod = IrModuleModule.find(accounting_module_id)
unless mod.state == "installed"
mod.button_install
end
end
wizard = BaseModuleUpgrade.create
wizard.upgrade_module
@ooor.load_models
# config5 = AccountInstaller.create(:charts => 'configurable')
# config5.action_next
@ooor.loaded_models.should_not be_empty
end
it "should be able to configure the database" do
# chart_module_id = IrModuleModule.search([['category_id', '=', 'Account Charts'], ['name','=', 'l10n_fr']])[0]
if AccountTax.search.empty?
w1 = @ooor.const_get('account.installer').create(:charts => "configurable")
w1.action_next
w1 = @ooor.const_get('wizard.multi.charts.accounts').create(:charts => "configurable")
w1.action_next
# w3 = @ooor.const_get('wizard.multi.charts.accounts').create
# w3.action_create
end
end
end
describe "Do operations on configured database" do
before(:all) do
@ooor = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database,
:models => ['res.user', 'res.partner', 'product.product', 'sale.order', 'account.invoice', 'product.category', 'stock.move', 'ir.ui.menu'])
end
describe "Finders operations" do
it "should be able to find data by id" do
p = ProductProduct.find(1)
p.should_not be_nil
p = ProductProduct.find(:first)
p.should_not be_nil
l = ProductProduct.find([1,2])
l.size.should == 2
end
it "should load required models on the fly" do
SaleOrder.find(1).shop_id.should be_kind_of(SaleShop)
end
it "should be able to specify the fields to read" do
p = ProductProduct.find(1, :fields=>["state", "id"])
p.should_not be_nil
end
it "should be able to find using ir.model.data absolute ids" do
p = ProductProduct.find('product_product_pc1')
p.should_not be_nil
p = ProductProduct.find('product.product_product_pc1')#module scoping is optionnal
p.should_not be_nil
end
it "should be able to use OpenERP domains" do
partners = ResPartner.find(:all, :domain=>[['supplier', '=', 1],['active','=',1]], :fields=>["id", "name"])
partners.should_not be_empty
products = ProductProduct.find(:all, :domain=>[['categ_id','=',1],'|',['name', '=', 'PC1'],['name','=','PC2']])
products.should be_kind_of(Array)
end
it "should mimic ActiveResource scoping" do
partners = ResPartner.find(:all, :params => {:supplier => true})
partners.should_not be_empty
end
it "should mimic ActiveResource scoping with first" do
partner = ResPartner.find(:first, :params => {:customer => true})
partner.should be_kind_of ResPartner
end
it "should support OpenERP context in finders" do
p = ProductProduct.find(1, :context => {:my_key => 'value'})
p.should_not be_nil
products = ProductProduct.find(:all, :context => {:lang => 'es_ES'})
products.should be_kind_of(Array)
end
it "should support OpenERP search method" do
partners = ResPartner.search([['name', 'ilike', 'a']], 0, 2)
partners.should_not be_empty
end
it "should cast dates properly from OpenERP to Ruby" do
o = SaleOrder.find(1)
o.date_order.should be_kind_of(Date)
m = StockMove.find(1)
m.date.should be_kind_of(Time)
end
it "should be able to call any Class method" do
ResPartner.name_search('ax', [], 'ilike', {}).should_not be_nil
end
end
describe "Relations reading" do
it "should read many2one relations" do
o = SaleOrder.find(1)
o.partner_id.should be_kind_of(ResPartner)
p = ProductProduct.find(1) #inherited via product template
p.categ_id.should be_kind_of(ProductCategory)
end
it "should read one2many relations" do
o = SaleOrder.find(1)
o.order_line.each do |line|
line.should be_kind_of(SaleOrderLine)
end
end
it "should read many2many relations" do
s = SaleOrder.find(1)
s.order_policy = 'manual'
s.save
s.wkf_action('order_confirm')
s.wkf_action('manual_invoice')
SaleOrder.find(1).order_line[1].invoice_lines.should be_kind_of(Array)
end
it "should read polymorphic references" do
IrUiMenu.find(:first, :domain => [['name', '=', 'Customers'], ['parent_id', '!=', false]]).action.should be_kind_of(IrActionsAct_window)
end
end
describe "Basic creations" do
it "should be able to assign a value to an unloaded field" do
p = ProductProduct.new
p.name = "testProduct1"
p.name.should == "testProduct1"
end
it "should be able to create a product" do
p = ProductProduct.create(:name => "testProduct1", :categ_id => 1)
ProductProduct.find(p.id).categ_id.id.should == 1
p = ProductProduct.new(:name => "testProduct1")
p.categ_id = 1
p.save
p.categ_id.id.should == 1
end
it "should support the context at object creation" do
p = ProductProduct.new({:name => "testProduct1", :categ_id => 1}, false, {:lang => 'en_US', :user_id=>1, :password => 'admin'})
p.object_session[:context][:lang] .should == 'en_US'
p.object_session[:user_id].should == 1
p.object_session[:password].should == "admin"
p.save
end
it "should support context when instanciating collections" do
products = ProductProduct.find([1, 2, 3], :context => {:lang => 'en_US', :user_id=>1, :password => 'admin'})
p = products[0]
p.object_session[:context][:lang].should == 'en_US'
p.object_session[:user_id].should == 1
p.object_session[:password].should == "admin"
p.save
end
it "should be able to create an order" do
o = SaleOrder.create(:partner_id => ResPartner.search([['name', 'ilike', 'Agrolait']])[0],
:partner_order_id => 1, :partner_invoice_id => 1, :partner_shipping_id => 1, :pricelist_id => 1)
o.id.should be_kind_of(Integer)
end
it "should be able to to create an invoice" do
i = AccountInvoice.new(:origin => 'ooor_test')
partner_id = ResPartner.search([['name', 'ilike', 'Agrolait']])[0]
i.on_change('onchange_partner_id', :partner_id, partner_id, 'out_invoice', partner_id, false, false)
i.save
i.id.should be_kind_of(Integer)
end
it "should be able to call on_change" do
o = SaleOrder.new
partner_id = ResPartner.search([['name', 'ilike', 'Agrolait']])[0]
o.on_change('onchange_partner_id', :partner_id, partner_id, partner_id)
o.save
line = SaleOrderLine.new(:order_id => o.id)
product_id = 1
pricelist_id = 1
product_uom_qty = 1
line.on_change('product_id_change', :product_id, product_id, pricelist_id, product_id, product_uom_qty, false, 1, false, false, o.partner_id.id, 'en_US', true, false, false, false)
line.save
SaleOrder.find(o.id).order_line.size.should == 1
end
it "should use default fields on creation" do
p = ProductProduct.new
p.sale_delay.should be_kind_of(Integer)
end
it "should skipped inherited default fields properly, for instance at product variant creation" do
#note that we force [] here for the default_get_fields otherwise OpenERP will blows up while trying to write in the product template!
ProductProduct.create({:product_tmpl_id => 25, :code => 'OOOR variant'}, {}, []).should be_kind_of(ProductProduct)
end
end
describe "Basic updates" do
it "should cast properly from Ruby to OpenERP" do
o = SaleOrder.find(1).copy()
o.date_order = 2.days.ago
o.save
end
it "should be able to reload resource" do
s = SaleOrder.find(1)
s.reload.should be_kind_of(SaleOrder)
end
end
describe "Relations assignations" do
it "should be able to assign many2one relations on new" do
s = SaleOrder.new(:partner_id => 2)
s.partner_id.id.should == 2
end
it "should be able to do product.taxes_id = [id1, id2]" do
p = ProductProduct.find(1)
p.taxes_id = AccountTax.search([['type_tax_use','=','sale']])[0..1]
p.save
p.taxes_id[0].should be_kind_of(AccountTax)
p.taxes_id[1].should be_kind_of(AccountTax)
end
it "should be able to create one2many relations on the fly" do
so = SaleOrder.new
partner_id = ResPartner.search([['name', 'ilike', 'Agrolait']])[0]
so.on_change('onchange_partner_id', :partner_id, partner_id, partner_id) #auto-complete the address and other data based on the partner
so.order_line = [SaleOrderLine.new(:name => 'sl1', :product_id => 1, :price_unit => 21, :product_uom => 1), SaleOrderLine.new(:name => 'sl2', :product_id => 1, :price_unit => 21, :product_uom => 1)] #create one order line
so.save
so.amount_total.should == 42.0
end
it "should be able to assign a polymorphic relation" do
#TODO implement!
end
end
describe "Old wizard management" do
it "should be possible to pay an invoice in one step" do
inv = AccountInvoice.find(:last).copy() #creates a draft invoice
inv.state.should == "draft"
inv.wkf_action('invoice_open')
inv.state.should == "open"
voucher = AccountVoucher.new({:amount=>inv.amount_total, :type=>"receipt", :partner_id => inv.partner_id.id}, {"default_amount"=>inv.amount_total, "invoice_id"=>inv.id})
voucher.on_change("onchange_partner_id", [], :partner_id, inv.partner_id.id, AccountJournal.find('account.bank_journal').id, 0.0, 1, 'receipt', false)
voucher.save
voucher.wkf_action 'proforma_voucher'
#wizard = inv.old_wizard_step('account.invoice.pay') #tip: you can inspect the wizard fields, arch and datas
#inv = wizard.reconcile({:journal_id => 6, :name =>"from_rails"}) #if you want to pay all; will give you a reloaded invoice
inv.reload
# inv.state.should == "paid" #TODO!!
end
it "should be possible to call resource actions and workflow actions" do
s = SaleOrder.find(1).copy()
s.wkf_action('order_confirm')
s.wkf_action('manual_invoice')
i = s.invoice_ids[0]
i.journal_id.update_posted = true
i.journal_id.save
i.wkf_action('invoice_open')
i.wkf_action('invoice_cancel')
i.action_cancel_draft
s.reload.state.should == "invoice_except"
end
end
describe "New style wizards" do
#already tested, see database configuration test
end
describe "Delete resources" do
it "should be able to call unlink" do
ids = ProductProduct.search([['name', 'ilike', 'testProduct']])
ProductProduct.unlink(ids)
end
it "should be able to destroy loaded business objects" do
orders = SaleOrder.find(:all, :domain => [['origin', 'ilike', 'ooor_test']])
orders.each {|order| order.destroy}
invoices = AccountInvoice.find(:all, :domain => [['origin', 'ilike', 'ooor_test']])
invoices.each {|inv| inv.destroy}
end
end
end
describe "Offer Web Client core features" do
before(:all) do
@ooor = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database,
:models => ['res.user', 'res.partner', 'product.product', 'sale.order', 'account.invoice', 'product.category', 'stock.move', 'ir.ui.menu'])
end
it "should find the default user action" do
@ooor.get_init_menu(1)
end
it "should be able to find the sub-menus of a menu" do
menu = IrUiMenu.find(:first, :domain => [['name', '=', 'Partners'], ['parent_id', '!=', false]])
menu.child_id.each do |sub_menu|
sub_menu.should be_kind_of(IrUiMenu)
end
end
it "should retrieve the action of a menu" do
Ooor::ActionWindow.from_menu(IrUiMenu.find(:first, :domain => [['name', '=', 'Customers']])).search.should be_kind_of Array
end
it "should be able to open a list view of a menu action" do
Ooor::ActionWindow.from_menu(IrUiMenu.find(:first, :domain => [['name', '=', 'Customers']])).get_fields 'tree'
end
it "should be able to open a form view of a menu action" do
Ooor::ActionWindow.from_menu(IrUiMenu.find(:first, :domain => [['name', '=', 'Customers']])).get_fields 'form'
end
end
describe "UML features" do
before(:all) do
@ooor = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database,
:models => ['res.user', 'res.partner', 'product.product', 'sale.order', 'account.invoice', 'product.category', 'stock.move', 'ir.ui.menu'])
end
it "should be able to draw the UML of any class" do
SaleOrder.print_uml.should be_true
end
it "should be able to draw the UML of several classes" do
Ooor::UML.print_uml([SaleOrder, SaleShop]).should be_true
end
it "should accept rendering options" do
SaleOrder.print_uml(:all, :detailed).should be_true
end
end
describe "Multi-instance and class name scoping" do
before(:all) do
@ooor1 = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database, :scope_prefix => 'OE1', :models => ['product.product'])
@ooor2 = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database, :scope_prefix => 'OE2', :models => ['product.product'])
end
it "should still be possible to find a ressource using an absolute id" do
OE1::ProductProduct.find('product_product_pc1').should be_kind_of(OE1::ProductProduct)
end
it "should be able to read in one instance and write in an other" do
p1 = OE1::ProductProduct.find(1)
p2 = OE2::ProductProduct.create(:name => p1.name, :categ_id => p1.categ_id.id)
p2.should be_kind_of(OE2::ProductProduct)
end
end
end