Discussion:
[Erp5-dev] How to test quantity step?
Łukasz Nowak
2007-10-10 09:37:56 UTC
Permalink
Hello,

I'm playing lot with purchase supplies and I'd like to write test for
quantity step on purchase supply line.

I create Purchase Supply, in it Purchase Supply Line, associated
resource with it, then:

def stepFillPurchaseSupplyLineDefineRange(self, sequence=None, **kw):
purchase_supply_line = sequence.get('purchase_supply_line')
purchase_supply_line.setQuantityStepList([5.0,10.0])

Now tic is invoked and then:

price_matrix_list = [
{
'range' : {
'min' : None,
'max' : 5.0,
},
'update_dict' : {
'base_price' : low_quantity_price,
},
},
{
'range' : {
'min' : 5.0,
'max' : 10.0,
},
'update_dict' : {
'base_price' : medium_quantity_price,
},
},
{
'range' : {
'min' : 10.0,
'max' : None,
},
'update_dict' : {
'base_price' : high_quantity_price,
},
},
]

def stepFillPurchaseSupplyLineFillRange(self, sequence=None, **kw):
purchase_supply_line = sequence.get('purchase_supply_line')

id = 0
for cell_dict in self.price_matrix_list:
purchase_supply_cell = purchase_supply_line.newContent(
portal_type = self.purchase_supply_cell_portal_type,
id = 'path_%s'%(id,)
)
purchase_supply_cell.setCriterionProperty('quantity')
purchase_supply_cell.edit(**cell_dict['update_dict'])
purchase_supply_cell.setCriterion('quantity',**cell_dict['range'])
id = id + 1

Tic again. Then I do pdb on test - navigate to created Purchase Supply
Line and matrix is filled.

Then I'm creating Purchase Order which find this matrix as predicate.
But it do not this. But if I navigate again to created PSL and edit eg.
base_price from UI, go to portal_activities, invoke all of them then
prices are copied to Purchase Order Lines...

I've seen then supply_line_interaction workflow is associated to method
_setQuantityStepList - but AFAIK it do not matter - and it do not
matter - even if I use _setQuantityStepList instead of
setQuantityStepList those activities aren't invoked.

I tried to search for similar test, but grep didn't helped me too much.

Any suggestions? What API (if any available) shall be used from unit
test point of view? While using UI everything works fine, but my
knowledge about tracing zope-ish invocations is not good enough to
track it down.

Regards,
Luke
--
?ukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...''
Jérome Perrin
2007-10-10 10:49:14 UTC
Permalink
Post by Łukasz Nowak
Hello,
I'm playing lot with purchase supplies and I'd like to write test for
quantity step on purchase supply line.
Hi,
I already tried to test exactly the same thing about one year ago, but
gave up.
Post by Łukasz Nowak
Any suggestions? What API (if any available) shall be used from unit
test point of view?
Matrix cells are created in Base_edit, there's no real API for this.
Maybe you can call Base_edit in your test, but you have to fake REQUEST
correctly ... I didn't try this.

J?rome
Łukasz Nowak
2007-10-10 11:45:27 UTC
Permalink
Hello,

On 2007-10-10, 12:49:14
Post by Jérome Perrin
Post by Łukasz Nowak
I'm playing lot with purchase supplies and I'd like to write test
for quantity step on purchase supply line.
Hi,
I already tried to test exactly the same thing about one year ago,
but gave up.
Post by Łukasz Nowak
Any suggestions? What API (if any available) shall be used from unit
test point of view?
Matrix cells are created in Base_edit, there's no real API for this.
Maybe you can call Base_edit in your test, but you have to fake
REQUEST correctly ... I didn't try this.
Ok. I'll try to do it by magic with REQUESTs. If I achieve needed
results I'll share them ASAP. But if anyone has better solution it is
badly needed.

Regards,
Luke
--
?ukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...''
Łukasz Nowak
2007-10-10 14:12:30 UTC
Permalink
Hello,

On 2007-10-10, 13:45:27
?ukasz Nowak <lukasz.nowak at ventis.com.pl> wrote:

(...)
Post by Łukasz Nowak
Ok. I'll try to do it by magic with REQUESTs. If I achieve needed
results I'll share them ASAP. But if anyone has better solution it is
badly needed.
I'm stucked again.

This is my code snippet:

def stepFillPurchaseSupplyLineDefineRange(self, sequence=None, **kw):
purchase_supply_line = sequence.get('purchase_supply_line')
from Testing.makerequest import makerequest
user_folder = self.getPortal().acl_users
user = user_folder.getUserById('ERP5TypeTestCase').__of__(user_folder)

psl = makerequest(purchase_supply_line)
request = purchase_supply_line.REQUEST
request['quantity_step_list'] = self.quantity_step_list
request.AUTHENTICATED_USER = user
psl.Base_edit(form_id='PurchaseSupplyLine_viewBasePrice')

Which ends up with not so understandable traceback:
Traceback (most recent call last):
File "/usr/lib/zope/lib/python/Testing/ZopeTestCase/profiler.py",
line 80, in __call__ testMethod()
File
"/home/shufla/work/erp5instance/unit_test/Products/VentisTests/tests/testVentisPricingOfResourcesWithQuantityStepOnPurchaseSupply.py",
line 400, in
test_01_check_if_pricing_is_correct_if_componet_has_quantity_step_on_purchase_supply
sequence_list.play(self) File
"/home/shufla/work/erp5instance/unit_test/Products/ERP5Type/tests/Sequence.py",
line 122, in play sequence.play(context, sequence_number=i,
quiet=quiet) File
"/home/shufla/work/erp5instance/unit_test/Products/ERP5Type/tests/Sequence.py",
line 72, in play step.play(context, sequence=self, quiet=quiet) File
"/home/shufla/work/erp5instance/unit_test/Products/ERP5Type/tests/Sequence.py",
line 58, in play method(sequence=sequence) File
"/home/shufla/work/erp5instance/unit_test/Products/VentisTests/tests/testVentisPricingOfResourcesWithQuantityStepOnPurchaseSupply.py",
line 208, in stepFillPurchaseSupplyLineDefineRange
psl.Base_edit(form_id='PurchaseSupplyLine_viewBasePrice') File
"/home/shufla/erp5/lib/python/Shared/DC/Scripts/Bindings.py", line 306,
in __call__ return self._bindAndExec(args, kw, None) File
"/home/shufla/erp5/lib/python/Shared/DC/Scripts/Bindings.py", line 343,
in _bindAndExec return self._exec(bound_data, args, kw) File
"/home/shufla/erp5/lib/python/Products/PythonScripts/PythonScript.py",
line 323, in _exec result = f(*args, **kw) File "Script (Python)", line
24, in Base_edit File
"/home/shufla/erp5/lib/python/Products/Formulator/Form.py", line 396,
in validate_all_to_request result = self.validate_all(REQUEST) File
"/home/shufla/work/erp5instance/Products/ERP5Form/Form.py", line 475,
in validate_all value = field.validate(REQUEST) File
"/home/shufla/erp5/lib/python/Products/Formulator/Field.py", line 266,
in validate return self._validate_helper( File
"/home/shufla/erp5/lib/python/Products/Formulator/Field.py", line 255,
in _validate_helper value = self.validator.validate(self, key, REQUEST)
File "/home/shufla/work/erp5instance/Products/ERP5Form/ProxyField.py",
line 125, in validate result = proxy_field.validator.validate(field,
key, REQUEST) File
"/home/shufla/work/erp5instance/Products/ERP5Form/FormulatorPatch.py",
line 951, in validate year = field.validate_sub_field('year', REQUEST,
key=key) File
"/home/shufla/work/erp5instance/Products/ERP5Form/FormulatorPatch.py",
line 90, in Field_validate_sub_field return
self.sub_form.get_field(id)._validate_helper( AttributeError: sub_form

Regards,
Luke
--
?ukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...''
Jérome Perrin
2007-10-10 15:02:12 UTC
Permalink
Post by Łukasz Nowak
Hello,
On 2007-10-10, 13:45:27
(...)
Post by Łukasz Nowak
Ok. I'll try to do it by magic with REQUESTs. If I achieve needed
results I'll share them ASAP. But if anyone has better solution it is
badly needed.
I'm stucked again.
purchase_supply_line = sequence.get('purchase_supply_line')
from Testing.makerequest import makerequest
user_folder = self.getPortal().acl_users
user = user_folder.getUserById('ERP5TypeTestCase').__of__(user_folder)
psl = makerequest(purchase_supply_line)
request = purchase_supply_line.REQUEST
request['quantity_step_list'] = self.quantity_step_list
request.AUTHENTICATED_USER = user
psl.Base_edit(form_id='PurchaseSupplyLine_viewBasePrice')
It's even more horrible, Base_edit validates the form, so before calling
it, REQUEST.form must contains formulator keys (you can view those in
html page source).

Try something like this:

request = purchase_supply_line.REQUEST.form
request['field_my_quantity_step_list'] = self.quantity_step_list
request['subfield_field_my_start_date_range_max_year'] = '2007'
request['subfield_field_my_start_date_range_max_month'] = '10'
request['subfield_field_my_start_date_range_max_day'] = '10'

and so on...

There might be a better solution I'm not aware of, though.

J?rome
Łukasz Nowak
2007-10-11 08:06:17 UTC
Permalink
Hello,

On 2007-10-10, 17:02:12
Post by Jérome Perrin
Post by Łukasz Nowak
(...)
Post by Łukasz Nowak
Ok. I'll try to do it by magic with REQUESTs. If I achieve needed
results I'll share them ASAP. But if anyone has better solution it
is badly needed.
I'm stucked again.
def stepFillPurchaseSupplyLineDefineRange(self, sequence=None,
**kw): purchase_supply_line = sequence.get('purchase_supply_line')
from Testing.makerequest import makerequest
user_folder = self.getPortal().acl_users
user =
user_folder.getUserById('ERP5TypeTestCase').__of__(user_folder)
psl = makerequest(purchase_supply_line)
request = purchase_supply_line.REQUEST
request['quantity_step_list'] = self.quantity_step_list
request.AUTHENTICATED_USER = user
psl.Base_edit(form_id='PurchaseSupplyLine_viewBasePrice')
It's even more horrible, Base_edit validates the form, so before
calling it, REQUEST.form must contains formulator keys (you can view
those in html page source).
Horrible, good to know. Ok - I hope I do not have to pass matrixbox*
fields?
Post by Jérome Perrin
request = purchase_supply_line.REQUEST.form
request['field_my_quantity_step_list'] = self.quantity_step_list
request['subfield_field_my_start_date_range_max_year'] = '2007'
request['subfield_field_my_start_date_range_max_month'] = '10'
request['subfield_field_my_start_date_range_max_day'] = '10'
and so on...
Tried.
case1-snippet.txt gives case1-traceback.txt.
case2.snippet.txt gives case2-traceback.txt.
Post by Jérome Perrin
There might be a better solution I'm not aware of, though.
So I'm stucked again. I'm shocked, that so much work is needed to
simulate such important user interaction. Are there any solution? I
tried to invoke edit() on purchase_supply_line, do it all in
activities, wait, do again. Is Base_edit really the only way to achieve
this? Or shall I copy&paste enough from Base_edit to simulate it
without validation?

Regards,
Luke
--
?ukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...''
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: case1-snippet.txt
URL: <http://mail.tiolive.com/pipermail/erp5-dev/attachments/20071011/c34bffaa/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: case1-traceback.txt
URL: <http://mail.tiolive.com/pipermail/erp5-dev/attachments/20071011/c34bffaa/attachment-0001.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: case2-snippet.txt
URL: <http://mail.tiolive.com/pipermail/erp5-dev/attachments/20071011/c34bffaa/attachment-0002.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: case2-traceback.txt
URL: <http://mail.tiolive.com/pipermail/erp5-dev/attachments/20071011/c34bffaa/attachment-0003.txt>
Loading...