openerp-dev-web team mailing list archive
-
openerp-dev-web team
-
Mailing list archive
-
Message #06166
[Merge] lp:~openerp-dev/openobject-addons/6.0-bug-773126-xrg into lp:openobject-addons/6.0
xrg has proposed merging lp:~openerp-dev/openobject-addons/6.0-bug-773126-xrg into lp:openobject-addons/6.0.
Requested reviews:
OpenERP Core Team (openerp)
Related bugs:
Bug #773126 in OpenERP Addons: "base_vat: yaml test for VAT validation (using samples in csv)"
https://bugs.launchpad.net/openobject-addons/+bug/773126
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/6.0-bug-773126-xrg/+merge/59490
--
https://code.launchpad.net/~openerp-dev/openobject-addons/6.0-bug-773126-xrg/+merge/59490
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/6.0-bug-773126-xrg.
=== added directory 'base_vat/test'
=== added file 'base_vat/test/base_vat_short.yml'
--- base_vat/test/base_vat_short.yml 1970-01-01 00:00:00 +0000
+++ base_vat/test/base_vat_short.yml 2011-04-29 10:53:32 +0000
@@ -0,0 +1,68 @@
+-
+ In order to check the VAT validation engine
+-
+ I will take a small sample of VATs and directly check them
+ against the corresponding functions
+-
+ !python {model: res.partner}: |
+ import csv
+ import addons
+ import logging
+
+ tlog = logging.getLogger('test.base_vat')
+ cfname = addons.get_module_resource('base_vat','test','sample-short.csv')
+ assert cfname, "Sample VATs not found!"
+
+ cfile = open(cfname,'rb')
+
+ rit = csv.reader(cfile, delimiter=',', quotechar='"')
+
+ fields = rit.next()
+ assert fields == ['country','vat', 'result'], fields
+
+ countries_fail = {}
+ lines_checked = 0
+ num_fails = 0
+ for line in rit:
+ lines_checked += 1
+ assert len(line) == len(fields)
+
+ r = dict(zip(fields, line))
+
+ fn = getattr(self, 'check_vat_%s' % r['country'].lower(), False)
+ if not fn:
+ countries_fail.setdefault(r['country'].upper(),set()).add('No fn')
+ continue
+
+ exp_res = bool(r['result'].lower() in ('1','t', 'true','yes'))
+
+ try:
+ res = fn(r['vat'])
+ except Exception:
+ tlog.log(logging.TEST, "Exception when validating %s for country %s", r['vat'], r['country'], exc_info=True)
+ countries_fail.setdefault(r['country'].upper(),set()).add('exc')
+ continue
+
+ if res != exp_res:
+ if num_fails < 100:
+ tlog.log(logging.TEST, "VAT check fails for %s %s : got %s instead of %s",
+ r['country'], r['vat'], res, exp_res)
+ num_fails += 1
+ if res and not exp_res:
+ countries_fail.setdefault(r['country'].upper(),set()).add('False positive')
+ elif exp_res and not res:
+ countries_fail.setdefault(r['country'].upper(),set()).add('False negative')
+
+ if num_fails > 1000:
+ break
+ # end for
+
+ if countries_fail:
+ sum_fails = sum(map(len, countries_fail.values()))
+ cstrs = []
+ for c, st in countries_fail.items():
+ cstrs.append("%s: %s" % (c, ','.join(st)))
+ raise AssertionError('VAT checks: %d problems, %d fails in %d checks: %s' % \
+ (sum_fails, num_fails, lines_checked, ' '.join(cstrs)))
+
+ tlog.log(logging.TEST,"VAT checks: all %d lines passed", lines_checked)
=== added file 'base_vat/test/sample-short.csv'
--- base_vat/test/sample-short.csv 1970-01-01 00:00:00 +0000
+++ base_vat/test/sample-short.csv 2011-04-29 10:53:32 +0000
@@ -0,0 +1,10 @@
+country,vat,result
+be,0477472701,true
+be,0231423473,false
+gr,099288170,true
+gr,3242342134,false
+mx,LOCM850414S83,true
+mx,oeña790311j96,true
+mx,oeo010221398,true
+mx,cama5610019q0,true
+mx,bco101026uf9,true
\ No newline at end of file