Review: Disapprove

Hello,

Your test is not correct. For example your python line: "self.create(cr, uid, 
{employee_id: hr.employee_fp, name: time.strftime('%Y-%m-%d 08:59:25'), action: 
'sign_in'}, None)" is not a valid python line, but you can't see it because you 
go into an except statement. For example, this line should become: 
"self.create(cr, uid, {'employee_id': ref('hr.employee_fp'), 'name': 
time.strftime('%Y-%m-%d 09:59:25'), 'action': 'sign_in'}, None)" . By the way 
you have to import time in !python code blocks if you want to use it.

Moreover, employee_fp already has demo data about attendance attached to it. 
First sign_in/sign_out is therefore impossible to test. Use another employee, 
such as hr.employee_niv, that hasn't any attendance data.

More generally, your tests are wrong. I take your first added test as an 
example :
-
  In order to check that first attendance must be Sign In.
-
   !python {model: hr.attendance}: |
     try:
       self.create(cr, uid, {employee_id: hr.employee_fp, name: 
time.strftime('%Y-%m-%d 09:59:25'), action: 'sign_out'}, None)
     except Exception, e:
       assert e, 'The first attendance must be Sign In'

If your Python line was correct, the create should fail (actually it indeed 
fails because your Python code is not correct, but you can't see it with your 
generic "except Exception, e" statement). Therefore you go into your except 
statement. As e exists, the message does not appear... There are several errors 
in this test. I think you should write something like:
-
  In order to check that first attendance must be Sign In.
-
  !python {model: hr.attendance}: |
    import time
    try:
      test_id = self.create(cr, uid, {'employee_id': ref('hr.employee_niv'), 
'name': time.strftime('%Y-%m-%d 09:59:25'), 'action': 'sign_out'}, None)
    except Exception, e:
      test_id = None # do not throw an error because this is the expected 
behavior
    assert (test_id == None), 'The first attendance is a sign_out but should 
not be accepted.'

If you want to be sure your test is valid, you can for example disable the code 
in '_altern_si_so' just to check that your test correctly manage wrong 
behaviors. By the way, "except Exception, e" is maybe not the best way to 
handle it. Catching correct exceptions is important. I let you dig into that.

Those tests can be a bit tricky, because for some tests you want the framework 
to actually launch exceptions. In some cases, a framework error is not a test 
error. Therefore you have to carefully think about your tests, what is the 
expected behavior, and what we want to highlight in errors.

I hope everything is clear. Do not hesitate to ask !

Best regards,

Thibault.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-885387-mdi/+merge/86388
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-bug-885387-mdi.

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to