Community mailing list archives

community@mail.odoo.com

Re: unit testing odoo constraint

by
n.schmitt
- 06/04/2015 10:00:26
Hi,

The best way I have found to use the assertRaises is using it like this:

with self.assertRaises(ExceptionType):
    # code that should raise the error

Tell me how it goes.
Regards,
Schmitt Nicolas

On 04/06/15, Jos De Graeve wrote:
> Hi,
> I want to write a test to validate an odoo orm constraint
> https://github.com/apertoso/pos/blob/89552e4a3eb158e390ef5053bfddf957deae7611/pos_require_customer/pos.py#L40-45 [1]
> The constraint throws an  openerp.exceptions.ValidationError  when some condition is not met.
> I my test i set the condition for the exception to be raised and check with  assertRaises  to verify it.
> https://github.com/apertoso/pos/blob/89552e4a3eb158e390ef5053bfddf957deae7611/pos_require_customer/tests/test_pos.py#L34-41 [2]
> But when i run my test, the test fails with my validationError:
> https://travis-ci.org/apertoso/pos/jobs/65357458#L269 [3]
> Some way or another, i'm doing something wrong with  assertRaises  but i can't see why.
> Any tips ?
> Jos De Graeve - Apertoso business ICT
> http://www.apertoso.be/ [4]
> Guido Gezellelaan 16 - B-9800 Deinze - Belgium   Direct: +32 9 381 64 51 General:+32 9 381 64 50 Mobile: +32 475 54 68 80 mail/im/skype: Jos.DeGraeve@apertoso.be [5] - apertoso
> 
> _______________________________________________
> Mailing-List: https://www.odoo.com/groups/community-59
> Post to: mailto:community@mail.odoo.com
> Unsubscribe: https://www.odoo.com/groups?unsubscribe
> 
> 
> 
> [1] https://github.com/apertoso/pos/blob/89552e4a3eb158e390ef5053bfddf957deae7611/pos_require_customer/pos.py#L40-45
> [2] https://github.com/apertoso/pos/blob/89552e4a3eb158e390ef5053bfddf957deae7611/pos_require_customer/tests/test_pos.py#L34-41
> [3] https://travis-ci.org/apertoso/pos/jobs/65357458#L269
> [4] http://www.apertoso.be/
> [5] mailto:Jos.DeGraeve@apertoso.be