Commit 06753911 authored by Jérome Perrin's avatar Jérome Perrin

Add validators for IBAN & BIC

parent b4043cf5
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>"""External Validator for BIC on bank account\n
"""\n
if not editor:\n
return True\n
\n
if len(editor) not in (8, 11):\n
return False\n
\n
if not editor[:5].isalpha():\n
return False\n
\n
if not editor[5:].isalnum():\n
return False\n
\n
return True\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>editor, request</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>BankAccount_validateBIC</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>"""External Validator for IBAN on bank account\n
"""\n
import string\n
if not editor:\n
return True\n
\n
editor = editor.replace(\' \', \'\').upper()\n
country_code = editor[:2]\n
checksum = editor[2:4]\n
bban = editor[4:]\n
\n
iban_len_dict = {\n
\'AD\': 24,\n
\'AT\': 20,\n
\'BA\': 20,\n
\'BE\': 16,\n
\'BG\': 22,\n
\'CH\': 21,\n
\'CY\': 28,\n
\'CZ\': 24,\n
\'DE\': 22,\n
\'DK\': 18,\n
\'EE\': 20,\n
\'ES\': 24,\n
\'FI\': 18,\n
\'FO\': 18,\n
\'FR\': 27,\n
\'GB\': 22,\n
\'GI\': 23,\n
\'GL\': 18,\n
\'GR\': 27,\n
\'HR\': 21,\n
\'HU\': 28,\n
\'IE\': 22,\n
\'IL\': 23,\n
\'IS\': 26,\n
\'IT\': 27,\n
\'LI\': 21,\n
\'LT\': 20,\n
\'LU\': 20,\n
\'LV\': 21,\n
\'MA\': 24,\n
\'MC\': 27,\n
\'ME\': 22,\n
\'MK\': 19,\n
\'MT\': 31,\n
\'NL\': 18,\n
\'NO\': 15,\n
\'PL\': 28,\n
\'PT\': 25,\n
\'RO\': 24,\n
\'RS\': 22,\n
\'SE\': 24,\n
\'SI\': 19,\n
\'SK\': 24,\n
\'SM\': 27,\n
\'TN\': 24,\n
\'TR\': 26\n
}\n
\n
if len(editor) != iban_len_dict.get(country_code, -1):\n
return False\n
\n
letter_code_dict = dict( zip(string.ascii_uppercase, range(10,36)) )\n
\n
iban_code = \'\'.join([str(letter_code_dict.get(x, x))\n
for x in bban + country_code + checksum])\n
\n
try:\n
iban_int = int(iban_code)\n
except ValueError:\n
return False\n
\n
return iban_int % 97 == 1\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>editor, request</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>BankAccount_validateIBAN</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
1052 1053
\ No newline at end of file \ No newline at end of file
...@@ -1386,6 +1386,33 @@ class TestERP5Base(ERP5TypeTestCase): ...@@ -1386,6 +1386,33 @@ class TestERP5Base(ERP5TypeTestCase):
# edit content_type on document which has no content_type property configured # edit content_type on document which has no content_type property configured
person.edit(content_type='text/xml') person.edit(content_type='text/xml')
def test_BankAccount_validateIBAN(self):
self.assertTrue(
self.portal.BankAccount_validateIBAN(
'GR1601101250000000012300695', request=None))
# spaces are allowed
self.assertTrue(
self.portal.BankAccount_validateIBAN(
'GR16 0110 1250 0000 0001 2300 695', request=None))
self.assertFalse(
self.portal.BankAccount_validateIBAN(
'GR16 0110 1250 0000 0001 2300 696', request=None))
self.assertFalse(
self.portal.BankAccount_validateIBAN(
'12345', request=None))
def test_BankAccount_validateBIC(self):
self.assertTrue(
self.portal.BankAccount_validateBIC(
'DEUTDEFF', request=None))
self.assertTrue(
self.portal.BankAccount_validateBIC(
'NEDSZAJJ', request=None))
self.assertFalse(
self.portal.BankAccount_validateBIC(
'X', request=None))
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestERP5Base)) suite.addTest(unittest.makeSuite(TestERP5Base))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment