Commit 89d0481d authored by Rafael Monnerat's avatar Rafael Monnerat

Modified and extended the Regex approach. This was made by Lucas.

Updated tests.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21298 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 38c5b0f6
...@@ -67,37 +67,231 @@ class Telephone(Coordinate, Base): ...@@ -67,37 +67,231 @@ class Telephone(Coordinate, Base):
, PropertySheet.Telephone , PropertySheet.Telephone
) )
# The country_dict is used by getRegexDict mapping
# the country number to country name
country_dict = {
'33' : 'france',
'55' : 'brazil',
'221' : 'dakar',
'64' : 'tokio'
}
# The notation always need to have: # The notation always need to have:
# <country> or <area> or <number> or <ext> # <country> or <area> or <number> or <ext>
# If uses a different tag it will be ignored. # If uses a different tag it will be ignored.
standard_dict = { standard_dict = {
'default' : { # France
"input" : "((\+|)(?P<country>[\d]*))(0)?(( |)(\(0\)|)(\(|)(?P<area>[\d]*))?((\)|)(-|)(?P<number>[\d^ ^-]*))((\/|)(?P<ext>[\d]*))", '33' : {
"notation" : "+<country>(0)<area>-<number>/<ext>" "regex_input_list" : [
}, # Country, Area, Number, Extension*
'france' : { # +33(0)2-27224896/999 or +33(0)2-27224896/ or +33(0)2-27224896
"input" : "((\+|)(?P<country>[\d]*))(0)?(( |)(\(0\)|)(\(|)(?P<area>[\d]*))?((\)|)(-|)(?P<number>[\d^ ^-]*))((\/|)(?P<ext>[\d]*))", "\+(?P<country>\d+)\(0\)(?P<area>\d+)\-(?P<number>[\d\ ]*)(?:\/)?(?P<ext>\d+|)",
# Missing country
# +(0)2-27224896/999" or +(0)2-27224896/ or +(0)2-27224896
"\+\(0\)(?P<area>\d+)\-(?P<number>[\d\ ]*)(?:\/)?(?P<ext>\d+|)",
# Missing area
# +33(0)-27224896/999" or +33(0)-27224896/ or +33(0)-27224896
"\+(?P<country>\d+)\(0\)\-(?P<number>[\d\ ]*)(?:\/)?(?P<ext>\d+|)",
# Missing Country and Area
# +(0)-27224896/999" or +(0)-27224896/ or +(0)-27224896
"\+\(0\)\-(?P<number>[\d\ ]*)(?:\/)?(?P<ext>\d+|)",
# Country, Area, Number, Extension*
# The area between parenthesis.
# +33(629)024425/222 or +33(629)024425/ or +33(629)024425
"^\+(?P<country>\d+)\((?P<area>\d+)\)(?P<number>[\d\ ]+)/?(?P<ext>\d+|)$",
# Area, Number Extension*
# Area between parenthesis.
# (22)27224897/333 or (22)27224897/ or (22)27224897
"\((?P<area>\d+)\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Area, Number, Extension*
# Area followed by '-'
# (22)-12345678/222 or (22)-12345678/ or (22)-12345678
"\((?P<area>\d+)\)\-?(?P<number>[\d\ ]*)(?:\/)?(?P<ext>\d+|)",
# Country, Area, Number and Extension*
# Country space area space number slash extension or not
# +33 2 098765432/1 or +33 2 098765432/ or +33 2 098765432
"\+(?P<country>\d+)\ (?P<area>\d+)\ (?P<number>[\d\ ]*)(?:\/)?(?P<ext>\d+|)",
# This regex is to handle two inputs very similar
# but with different behavior
# 631 22 43/999 or 631 22 43 or 631 22 43
# will result in {'area':'', 'country':'631 22 43', 'ext':'999 or empty'}
#
# 631-22 43/999 or 631-22 43 or 631-22 43
# will result in {'area':'631', 'country':'22 43', 'ext':'999 or empty'}
"^(?:0)?((?P<area>\d+)-)?(?P<number>[\d\-\ ]*)(?:\/)?(?P<ext>\d+|)$",
# Area, Number, Extension*
# 047-336-5411/999 or 047-336-5411/ or 047-336-5411
"^0(?P<area>\d+)-(?P<number>[\d\-\ ]*)(?:\/)?(?P<ext>\d+|)$",
# Area, Number, Extension*
# 047(336)5411/999 or 047(336)5411/ or 047(336)5411
"^0(?P<area>\d+)\((?P<number>[\d\)\(\ \-]*)(?:\/)?(?P<ext>\d+|)$"
],
"notation" : "+<country>(0)<area>-<number>/<ext>" "notation" : "+<country>(0)<area>-<number>/<ext>"
}, },
'brazil' : { # Brazil
"input" : "((\+|)(?P<country>[\d]*))(0)?(( |)(\(0\)|)(\(|)(?P<area>[\d]*))?((\)|)(-|)(?P<number>[\d^ ^-]*))((\/|)(?P<ext>[\d]*))", '55' : {
"regex_input_list" : [
# Country, Area, Number, Extension*
# +55(2)27224896/999 or +55(2)27224896/ or +55(2)27224896
"\+(?P<country>\d+)\((?P<area>\d+)\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Country, Area, Number, Extension*
# +55-2-27224896/999 or +55-2-27224896/ or +55-2-27224896
"\+(?P<country>\d+)-(?P<area>\d+)-(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Missing country
# +(2)27224896/999 or +(2)27224896/ or +(2)27224896
"\+\((?P<area>\d+)\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Missing area
# +55()-27224896/999 or +55()-27224896/ or +55()-27224896
# +55()27224896/999 or +55()27224896/ or +55()27224896
"\+(?P<country>\d+)\(\)(?:\-)?(?P<number>[\d\ ]*)(?:\/)?(?P<ext>\d+|)",
# Missing Country and Area
# +()27224896/999 or +()27224896/ or +()27224896
"\+\(\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Country, Area, Number, Extension*
# The area between parenthesis.
# +55(629)024425/222 or +55(629)024425/ or +55(629)024425
"^\+(?P<country>\d+)\((?P<area>\d+)\)(?P<number>[\d\ ]+)/?(?P<ext>\d+|)$",
# Area, Number Extension*
# Area between parenthesis.
# (22)27224897/333 or (22)27224897/ or (22)27224897
"\((?P<area>\d+)\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Country, Area, Number and Extension*
# Country space area space number slash extension or not
# +55 2 098765432/1 or +55 2 098765432/ or +55 2 098765432
"\+(?P<country>\d+)\ (?P<area>\d+)\ (?P<number>[\d\ ]*)(?:\/)?(?P<ext>\d+|)",
# This regex is to handle two inputs very similar
# but with different behavior
# 631 22 43/999 or 631 22 43 or 631 22 43
# will result in {'area':'', 'country':'631 22 43', 'ext':'999 or empty'}
#
# 631-22 43/999 or 631-22 43 or 631-22 43
# will result in {'area':'631', 'country':'22 43', 'ext':'999 or empty'}
"^((?P<area>\d+)-)?(?P<number>[\d\-\ ]*)(?:\/)?(?P<ext>\d+|)$",
# Area, Number, Extension*
# 047-336-5411/999 or 047-336-5411/ or 047-336-5411
"^(?P<area>\d+)-(?P<number>[\d\-\ ]*)(?:\/)?(?P<ext>\d+|)$",
# Area, Number, Extension*
# 047(336)5411/999 or 047(336)5411/ or 047(336)5411
"^(?P<area>\d+)\((?P<number>[\d\)\(\ \-]*)(?:\/)?(?P<ext>\d+|)$"
],
"notation" : "+<country>(<area>)<number>/<ext>", "notation" : "+<country>(<area>)<number>/<ext>",
}, },
'dakar' : { # Senegal
"input" : "((\+|)(\(|)(?P<country>[\d]*))?((\)|)(-|)(?P<number>[\d^ ^-]*))((\/|)(?P<ext>[\d]*)", '221' : {
"notation" : "+<country> <number>/<ext>", "regex_input_list" : [
# Country, Area, Number, Extension*
# +221(2)27224896/999 or +221(2)27224896/ or +221(2)27224896
"\+(?P<country>\d+)\((?P<area>\d+)\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Country, Area, Number, Extension*
# +221-2-27224896/999 or +221-2-27224896/ or +221-2-27224896
"\+(?P<country>\d+)-(?P<area>\d+)-(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Missing country
# +(2)27224896/999" or +(2)27224896/ or +(2)27224896
"\+\((?P<area>\d+)\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Missing area
# +221()27224896/999" or +221()27224896/ or +221()27224896
"\+(?P<country>\d+)\(\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Missing Country and Area
# +()27224896/999" or +()27224896/ or +()27224896
"\+\(\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Country, Area, Number, Extension*
# The area between parenthesis.
# +221(629)024425/222 or +221(629)024425/ or +221(629)024425
"^\+(?P<country>\d+)\((?P<area>\d+)\)(?P<number>[\d\ ]+)/?(?P<ext>\d+|)$",
# Area, Number Extension*
# Area between parenthesis.
# (22)27224897/333 or (22)27224897/ or (22)27224897
"\((?P<area>\d+)\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Country, Area, Number and Extension*
# Country space area space number slash extension or not
# +221 2 098765432/1 or +221 2 098765432/ or +221 2 098765432
"\+(?P<country>\d+)\ (?P<area>\d+)\ (?P<number>[\d\ ]*)(?:\/)?(?P<ext>\d+|)",
# This regex is to handle two inputs very similar
# but with different behavior
# 631 22 43/999 or 631 22 43 or 631 22 43
# will result in {'area':'', 'country':'631 22 43', 'ext':'999 or empty'}
#
# 631-22 43/999 or 631-22 43 or 631-22 43
# will result in {'area':'631', 'country':'22 43', 'ext':'999 or empty'}
"^((?P<area>\d+)-)?(?P<number>[\d\-\ ]*)(?:\/)?(?P<ext>\d+|)$",
# Area, Number, Extension*
# 047-336-5411/999 or 047-336-5411/ or 047-336-5411
"^(?P<area>\d+)-(?P<number>[\d\-\ ]*)(?:\/)?(?P<ext>\d+|)$",
# Area, Number, Extension*
# 047(336)5411/999 or 047(336)5411/ or 047(336)5411
"^(?P<area>\d+)\((?P<number>[\d\)\(\ \-]*)(?:\/)?(?P<ext>\d+|)$"
],
"notation" : "+<country>(<area>)<number>/<ext>",
}, },
'tokio' : { # Japan
"input" : "((\+|)(?P<country>[\d]*))(0)?(( |)(\(0\)|)(\(|)(?P<area>[\d]*))?((\)|)(-|)(?P<number>[\d^ ^-]*))((\/|)(?P<ext>[\d]*))", '81' : {
"regex_input_list" : [
# Country, Area, Number, Extension*
# +81(2)27224896/999 or +81(2)27224896/ or +81(2)27224896
"\+(?P<country>\d+)\((?P<area>\d+)\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Country, Area, Number, Extension*
# +81-2-27224896/999 or +81-2-27224896/ or +81-2-27224896
"\+(?P<country>\d+)-(?P<area>\d+)-(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Missing country
# +(2)27224896/999" or +(2)27224896/ or +(2)27224896
"\+\((?P<area>\d+)\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Missing Country and Area
# +()27224896/999" or +()27224896/ or +()27224896
"\+\(\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Country, Area, Number, Extension*
# The area between parenthesis.
# +81(629)024425/222 or +81(629)024425/ or +81(629)024425
"^\+(?P<country>\d+)\((?P<area>\d+)\)(?P<number>[\d\ ]+)/?(?P<ext>\d+|)$",
# Area, Number Extension*
# Area between parenthesis.
# (22)27224897/333 or (22)27224897/ or (22)27224897
"\((?P<area>\d+)\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Country, Area, Number and Extension*
# Country space area space number slash extension or not
# +81 2 098765432/1 or +81 2 098765432/ or +81 2 098765432
"\+(?P<country>\d+)\ (?P<area>\d+)\ (?P<number>[\d\ ]*)(?:\/)?(?P<ext>\d+|)",
# This regex is to handle two inputs very similar
# but with different behavior
# 631 22 43/999 or 631 22 43 or 631 22 43
# will result in {'area':'', 'country':'631 22 43', 'ext':'999 or empty'}
#
# 631-22 43/999 or 631-22 43 or 631-22 43
# will result in {'area':'631', 'country':'22 43', 'ext':'999 or empty'}
"^((?P<area>\d+)-)?(?P<number>[\d\-\ ]*)(?:\/)?(?P<ext>\d+|)$",
# Area, Number, Extension*
# 047-336-5411/999 or 047-336-5411/ or 047-336-5411
"^(?P<area>\d+)-(?P<number>[\d\-\ ]*)(?:\/)?(?P<ext>\d+|)$",
# Area, Number, Extension*
# 047(336)5411/999 or 047(336)5411/ or 047(336)5411
"^(?P<area>\d+)\((?P<number>[\d\)\(\ \-]*)(?:\/)?(?P<ext>\d+|)$"
],
"notation" : "+<country>(<area>)<number>/<ext>", "notation" : "+<country>(<area>)<number>/<ext>",
} }
} }
...@@ -112,23 +306,30 @@ class Telephone(Coordinate, Base): ...@@ -112,23 +306,30 @@ class Telephone(Coordinate, Base):
if coordinate_text is None: if coordinate_text is None:
coordinate_text = '' coordinate_text = ''
#This regexp get the coordinate text and extract only numbers # This regexp get the coordinate text
onlynumber = ''.join(re.findall('[0-9]', coordinate_text)) # and extract number and letters
input_regex_without_markup = '[0-9A-Za-z]'
#Test if coordinate_text has or not markups. input_without_markup = ''.join(re.findall(input_regex_without_markup,\
if len(coordinate_text) > len(onlynumber): coordinate_text))
#trying to get a possible contry number to be used by script # Test if coordinate_text has or not markups.
country = re.match('((\+|)(?P<country>\d*))', \ if len(coordinate_text) > len(input_without_markup):
coordinate_text).groupdict().get('country','') # Trying to get the regex list.
regexdict = self.getRegexDict(index=country) input_parser_list = self._getRegexList(coordinate_text=coordinate_text)
input_parser = regexdict.get('input') number_match = None
number_match = re.match(input_parser, coordinate_text) for input_parser in input_parser_list:
if not number_match: possible_number_match = re.match(input_parser, coordinate_text)
if possible_number_match not in [None]:
number_match = possible_number_match
break
if number_match == None:
from zLOG import LOG, WARNING
msg = "Doesn't exist a regex to handle this telephone: ", coordinate_text
LOG('*** Telephone ***',WARNING,msg)
return return
number_dict = number_match.groupdict() number_dict = number_match.groupdict()
else: else:
number_dict = {'number' : coordinate_text} number_dict = {'number' : coordinate_text}
country=number_dict.get('country','') country=number_dict.get('country','')
area=number_dict.get('area','') area=number_dict.get('area','')
number=number_dict.get('number','') number=number_dict.get('number','')
...@@ -138,17 +339,28 @@ class Telephone(Coordinate, Base): ...@@ -138,17 +339,28 @@ class Telephone(Coordinate, Base):
(area in ['', None]) and \ (area in ['', None]) and \
(number in ['', None]) and \ (number in ['', None]) and \
(ext in ['', None])): (ext in ['', None])):
country = area = number = extension='' country = area = number = extension = ''
else: else:
# The country and area is trying to get from dict, # The country and area is trying to get from dict,
# but if it fails must be get from preference # but if it fails must be get from preference
country_default_number = self.portal_preferences.getPreferredTelephoneDefaultCountryNumber()
area_default_number = self.portal_preferences.getPreferredTelephoneDefaultAreaNumber()
country = (number_dict.get('country') or \ country = (number_dict.get('country') or \
self.portal_preferences.getPreferredTelephoneDefaultCountryNumber() or \ country_default_number or \
'').strip() '').strip()
area = (number_dict.get('area') or \ area = (number_dict.get('area') or \
self.portal_preferences.getPreferredTelephoneDefaultAreaNumber() or area_default_number or
'').strip() '').strip()
number = (number_dict.get('number') or '').strip().replace('-', '').replace(' ','') number = (number_dict.get('number') or '').strip()
# Formating the number.
# Removing any ")", "(", "-" and " "
number = number.replace('-', '')
number = number.replace(' ','')
number = number.replace(')','')
number = number.replace('(','')
extension = (number_dict.get('ext') or '').strip() extension = (number_dict.get('ext') or '').strip()
self.edit(telephone_country = country, self.edit(telephone_country = country,
...@@ -180,10 +392,9 @@ class Telephone(Coordinate, Base): ...@@ -180,10 +392,9 @@ class Telephone(Coordinate, Base):
(telephone_number == '') and \ (telephone_number == '') and \
(telephone_extension == '')): (telephone_extension == '')):
return '' return ''
regexdict = self.getRegexDict(index=telephone_country) # Trying to get the notation
notation = regexdict.get('notation') notation = self._getNotation(telephone_country=telephone_country)
if notation not in [None, '']: if notation not in [None, '']:
notation=notation.replace('<country>',telephone_country) notation=notation.replace('<country>',telephone_country)
notation=notation.replace('<area>',telephone_area) notation=notation.replace('<area>',telephone_area)
...@@ -226,37 +437,33 @@ class Telephone(Coordinate, Base): ...@@ -226,37 +437,33 @@ class Telephone(Coordinate, Base):
""" """
return ("+33(0)6-62 05 76 14",) return ("+33(0)6-62 05 76 14",)
def getRegexDict(self, index=None): def _getRegexDict(self, index=None):
""" """
Returns a dict with Regex and Notations based from Returns a dict with Regex and Notations based from
country or region country or region
""" """
# In case of index is a number # Trying to get the Regex Dict
# should return a region from dict or from form field if index not in self.standard_dict.keys():
if index not in [None,'']: index = self.portal_preferences.getPreferredTelephoneDefaultCountryNumber() or '33'
# If index is not in country_dict
# the possible country can be found at region field return self.standard_dict.get(index)
# in context or in preferences
if index not in self.country_dict.keys(): def _getRegexList(self, coordinate_text):
region = self.getRegion() or \ """
self.portal_preferences.getPreferredTelephoneDefaultRegion() Returns the regex list.
else: """
region = self.country_dict.get(index,'') # Trying to get a possible contry number
else: country_regex = '((\+|)(?P<country>\d*))'
region = self.getRegion() or \ country = re.match(country_regex, \
self.portal_preferences.getPreferredTelephoneDefaultRegion() coordinate_text).groupdict().get('country','')
regex_dict = self._getRegexDict(index=country)
# Find the region in standard_dict input_parser = regex_dict.get('regex_input_list')
if region is not None: return input_parser
region_list=region.split('/')
for i in region_list: def _getNotation(self, telephone_country):
if self.standard_dict.get(i) is not None: """
region = i Returns the notation that will be used by asText method.
"""
# If region doesn't exist this method regex_dict = self._getRegexDict(index=telephone_country)
# should to return a default regex. notation = regex_dict.get('notation')
if region not in self.standard_dict.keys() or region is None: return notation
region = 'default'
dict = self.standard_dict.get(region)
return dict
...@@ -873,26 +873,341 @@ class TestERP5Base(ERP5TypeTestCase): ...@@ -873,26 +873,341 @@ class TestERP5Base(ERP5TypeTestCase):
tel.setTelephoneExtension(999) tel.setTelephoneExtension(999)
self.assertEquals('+33(0)2-12345678/999', tel.asText()) self.assertEquals('+33(0)2-12345678/999', tel.asText())
def test_TelephoneInputList(self): def test_TelephoneInputListForFrance(self):
pers = self.getPersonModule().newContent(portal_type='Person') pers = self.getPersonModule().newContent(portal_type='Person')
tel = pers.newContent(portal_type='Telephone') tel = pers.newContent(portal_type='Telephone')
pref = self.portal_preferences.default_site_preference pref = self.portal_preferences.default_site_preference
pref.setPreferredTelephoneDefaultCountryNumber('33') pref.setPreferredTelephoneDefaultCountryNumber('33')
pref.setPreferredTelephoneDefaultAreaNumber('2') pref.setPreferredTelephoneDefaultAreaNumber('2')
pref.enable() pref.enable()
inputdict=[ input_list = [
['+33(0)2-27224896/999','+33(0)2-27224896/999'], ["+33(0)2-27224896/999","+33(0)2-27224896/999"],
['+33(0)2-27224896/','+33(0)2-27224896/'], ["+33(0)2-27224896/","+33(0)2-27224896/"],
['+33(629)02 44 25/222','+33(0)629-024425/222'], ["+33(0)2-27224896","+33(0)2-27224896/"],
['(22)27224897','+33(0)22-27224897/'],
['12345678','+33(0)2-12345678/'], ["+33(0)-5744896/999","+33(0)2-5744896/999"],
['(22) 12345678','+33(0)22-12345678/'], ["+33(0)-5744896/","+33(0)2-5744896/"],
['66187654321','+33(0)2-66187654321/'], ["+33(0)-5744896","+33(0)2-5744896/"],
['(22)-12345678','+33(0)22-12345678/'],
['33 2 098765432/1','+33(0)2-098765432/1'] ["+(0)2-27224896/999","+33(0)2-27224896/999"],
["+(0)2-27224896/","+33(0)2-27224896/"],
["+(0)2-27224896","+33(0)2-27224896/"],
["+(0)-27224896/999","+33(0)2-27224896/999"],
["+(0)-27224896/","+33(0)2-27224896/"],
["+(0)-27224896","+33(0)2-27224896/"],
["+33(629)024425/222","+33(0)629-024425/222"],
["+33(629)024425/","+33(0)629-024425/"],
["+33(629)024425","+33(0)629-024425/"],
["(22)27224897/333","+33(0)22-27224897/333"],
["(22)27224897/","+33(0)22-27224897/"],
["(22)27224897","+33(0)22-27224897/"],
["(22)-12345678/222","+33(0)22-12345678/222"],
["(22)-12345678/","+33(0)22-12345678/"],
["(22)-12345678","+33(0)22-12345678/"],
["+33 2 098765432/1","+33(0)2-098765432/1"],
["+33 2 098765432/","+33(0)2-098765432/"],
["+33 2 098765432","+33(0)2-098765432/"],
["+33 662 1241 1233/999","+33(0)662-12411233/999"],
["+33 662 1241 1233/","+33(0)662-12411233/"],
["+33 662 1241 1233","+33(0)662-12411233/"],
["6-62 05 76 14/999","+33(0)6-62057614/999"],
["6-62 05 76 14/","+33(0)6-62057614/"],
["6-62 05 76 14","+33(0)6-62057614/"],
["62 05 76 14/999","+33(0)2-62057614/999"],
["62 05 76 14/","+33(0)2-62057614/"],
["62 05 76 14","+33(0)2-62057614/"],
["631 22 43/999","+33(0)2-6312243/999"],
["631 22 43/","+33(0)2-6312243/"],
["631 22 43","+33(0)2-6312243/"],
["631-22 43/999","+33(0)631-2243/999"],
["631-22 43/","+33(0)631-2243/"],
["631-22 43","+33(0)631-2243/"],
["8291212/33","+33(0)2-8291212/33"],
["047-336-5411/999","+33(0)47-3365411/999"],
["047-336-5411/","+33(0)47-3365411/"],
["047-336-5411","+33(0)47-3365411/"],
["047(336)5411/999","+33(0)47-3365411/999"],
["047(336)5411/","+33(0)47-3365411/"],
["047(336)5411","+33(0)47-3365411/"],
["+33 662 1244 4112/999","+33(0)662-12444112/999"],
["+33 662 1244 4112/","+33(0)662-12444112/"],
["+33 662 1244 4112","+33(0)662-12444112/"],
]
for i in input_list:
tel.fromText(coordinate_text=i[0])
self.assertEquals(i[1],tel.asText())
def test_TelephoneInputListForSenegal(self):
pers = self.getPersonModule().newContent(portal_type='Person')
tel = pers.newContent(portal_type='Telephone')
pref = self.portal_preferences.default_site_preference
pref.setPreferredTelephoneDefaultCountryNumber('221')
pref.setPreferredTelephoneDefaultAreaNumber('')
pref.enable()
input_list = [
["+221(2)27224896/999","+221(2)27224896/999"],
["+221(2)27224896/","+221(2)27224896/"],
["+221(2)27224896","+221(2)27224896/"],
["+221()27224896/999","+221()27224896/999"],
["+221()27224896/","+221()27224896/"],
["+221()27224896","+221()27224896/"],
["+221()-27224896/999","+221()27224896/999"],
["+221()-27224896/","+221()27224896/"],
["+221()-27224896","+221()27224896/"],
["+(2)27224896/999","+221(2)27224896/999"],
["+(2)27224896/","+221(2)27224896/"],
["+(2)27224896","+221(2)27224896/"],
["+()27224896/999","+221()27224896/999"],
["+()27224896/","+221()27224896/"],
["+()27224896","+221()27224896/"],
["+221(629)024425/222","+221(629)024425/222"],
["+221(629)024425/","+221(629)024425/"],
["+221(629)024425","+221(629)024425/"],
["(22)27224897/333","+221(22)27224897/333"],
["(22)27224897/","+221(22)27224897/"],
["(22)27224897","+221(22)27224897/"],
["(22)-12345678/222","+221(22)12345678/222"],
["(22)-12345678/","+221(22)12345678/"],
["(22)-12345678","+221(22)12345678/"],
["+221 2 098765432/1","+221(2)098765432/1"],
["+221 2 098765432/","+221(2)098765432/"],
["+221 2 098765432","+221(2)098765432/"],
["+221 662 1241 1233/999","+221(662)12411233/999"],
["+221 662 1241 1233/","+221(662)12411233/"],
["+221 662 1241 1233","+221(662)12411233/"],
["6-62 05 76 14/999","+221(6)62057614/999"],
["6-62 05 76 14/","+221(6)62057614/"],
["6-62 05 76 14","+221(6)62057614/"],
["62 05 76 14/999","+221()62057614/999"],
["62 05 76 14/","+221()62057614/"],
["62 05 76 14","+221()62057614/"],
["631 22 43/999","+221()6312243/999"],
["631 22 43/","+221()6312243/"],
["631 22 43","+221()6312243/"],
["631-22 43/999","+221(631)2243/999"],
["631-22 43/","+221(631)2243/"],
["631-22 43","+221(631)2243/"],
["8291212/33","+221()8291212/33"],
["047-336-5411/999","+221(047)3365411/999"],
["047-336-5411/","+221(047)3365411/"],
["047-336-5411","+221(047)3365411/"],
["047(336)5411/999","+221(047)3365411/999"],
["047(336)5411/","+221(047)3365411/"],
["047(336)5411","+221(047)3365411/"],
["+221 662 1244 4112/999","+221(662)12444112/999"],
["+221 662 1244 4112/","+221(662)12444112/"],
["+221 662 1244 4112","+221(662)12444112/"],
["+221-047-12345678/990","+221(047)12345678/990"],
["+221-047-12345678/","+221(047)12345678/"],
["+221-047-12345678","+221(047)12345678/"]
]
for i in input_list:
tel.fromText(coordinate_text=i[0])
self.assertEquals(i[1],tel.asText())
def test_TelephoneInputListForBrazil(self):
pers = self.getPersonModule().newContent(portal_type='Person')
tel = pers.newContent(portal_type='Telephone')
pref = self.portal_preferences.default_site_preference
pref.setPreferredTelephoneDefaultCountryNumber('55')
pref.setPreferredTelephoneDefaultAreaNumber('2')
pref.enable()
input_list = [
["+55(2)27224896/999","+55(2)27224896/999"],
["+55(2)27224896/","+55(2)27224896/"],
["+55(2)27224896","+55(2)27224896/"],
["+55()27224896/999","+55(2)27224896/999"],
["+55()27224896/","+55(2)27224896/"],
["+55()27224896","+55(2)27224896/"],
["+55()-27224896/999","+55(2)27224896/999"],
["+55()-27224896/","+55(2)27224896/"],
["+55()-27224896","+55(2)27224896/"],
["+(2)27224896/999","+55(2)27224896/999"],
["+(2)27224896/","+55(2)27224896/"],
["+(2)27224896","+55(2)27224896/"],
["+()27224896/999","+55(2)27224896/999"],
["+()27224896/","+55(2)27224896/"],
["+()27224896","+55(2)27224896/"],
["+55(629)024425/222","+55(629)024425/222"],
["+55(629)024425/","+55(629)024425/"],
["+55(629)024425","+55(629)024425/"],
["(22)27224897/333","+55(22)27224897/333"],
["(22)27224897/","+55(22)27224897/"],
["(22)27224897","+55(22)27224897/"],
["(22)-12345678/222","+55(22)12345678/222"],
["(22)-12345678/","+55(22)12345678/"],
["(22)-12345678","+55(22)12345678/"],
["+55 2 098765432/1","+55(2)098765432/1"],
["+55 2 098765432/","+55(2)098765432/"],
["+55 2 098765432","+55(2)098765432/"],
["+55 662 1241 1233/999","+55(662)12411233/999"],
["+55 662 1241 1233/","+55(662)12411233/"],
["+55 662 1241 1233","+55(662)12411233/"],
["6-62 05 76 14/999","+55(6)62057614/999"],
["6-62 05 76 14/","+55(6)62057614/"],
["6-62 05 76 14","+55(6)62057614/"],
["62 05 76 14/999","+55(2)62057614/999"],
["62 05 76 14/","+55(2)62057614/"],
["62 05 76 14","+55(2)62057614/"],
["631 22 43/999","+55(2)6312243/999"],
["631 22 43/","+55(2)6312243/"],
["631 22 43","+55(2)6312243/"],
["631-22 43/999","+55(631)2243/999"],
["631-22 43/","+55(631)2243/"],
["631-22 43","+55(631)2243/"],
["8291212/33","+55(2)8291212/33"],
["047-336-5411/999","+55(047)3365411/999"],
["047-336-5411/","+55(047)3365411/"],
["047-336-5411","+55(047)3365411/"],
["047(336)5411/999","+55(047)3365411/999"],
["047(336)5411/","+55(047)3365411/"],
["047(336)5411","+55(047)3365411/"],
["+55 662 1244 4112/999","+55(662)12444112/999"],
["+55 662 1244 4112/","+55(662)12444112/"],
["+55 662 1244 4112","+55(662)12444112/"],
["+55-047-12345678/990","+55(047)12345678/990"],
["+55-047-12345678/","+55(047)12345678/"],
["+55-047-12345678","+55(047)12345678/"]
]
# To help with debug,
for i in input_list:
tel.fromText(coordinate_text=i[0])
self.assertEquals(i[1],tel.asText())
def test_TelephoneInputListForJapan(self):
pers = self.getPersonModule().newContent(portal_type='Person')
tel = pers.newContent(portal_type='Telephone')
pref = self.portal_preferences.default_site_preference
pref.setPreferredTelephoneDefaultCountryNumber('81')
pref.setPreferredTelephoneDefaultAreaNumber('2')
pref.enable()
input_list = [
["+81(2)27224896/999","+81(2)27224896/999"],
["+81(2)27224896/","+81(2)27224896/"],
["+81(2)27224896","+81(2)27224896/"],
["+(2)27224896/999","+81(2)27224896/999"],
["+(2)27224896/","+81(2)27224896/"],
["+(2)27224896","+81(2)27224896/"],
["+()27224896/999","+81(2)27224896/999"],
["+()27224896/","+81(2)27224896/"],
["+()27224896","+81(2)27224896/"],
["+81(629)024425/222","+81(629)024425/222"],
["+81(629)024425/","+81(629)024425/"],
["+81(629)024425","+81(629)024425/"],
["(22)27224897/333","+81(22)27224897/333"],
["(22)27224897/","+81(22)27224897/"],
["(22)27224897","+81(22)27224897/"],
["(22)-12345678/222","+81(22)12345678/222"],
["(22)-12345678/","+81(22)12345678/"],
["(22)-12345678","+81(22)12345678/"],
["+81 2 098765432/1","+81(2)098765432/1"],
["+81 2 098765432/","+81(2)098765432/"],
["+81 2 098765432","+81(2)098765432/"],
["+81 662 1241 1233/999","+81(662)12411233/999"],
["+81 662 1241 1233/","+81(662)12411233/"],
["+81 662 1241 1233","+81(662)12411233/"],
["6-62 05 76 14/999","+81(6)62057614/999"],
["6-62 05 76 14/","+81(6)62057614/"],
["6-62 05 76 14","+81(6)62057614/"],
["62 05 76 14/999","+81(2)62057614/999"],
["62 05 76 14/","+81(2)62057614/"],
["62 05 76 14","+81(2)62057614/"],
["631 22 43/999","+81(2)6312243/999"],
["631 22 43/","+81(2)6312243/"],
["631 22 43","+81(2)6312243/"],
["631-22 43/999","+81(631)2243/999"],
["631-22 43/","+81(631)2243/"],
["631-22 43","+81(631)2243/"],
["8291212/33","+81(2)8291212/33"],
["047-336-5411/999","+81(047)3365411/999"],
["047-336-5411/","+81(047)3365411/"],
["047-336-5411","+81(047)3365411/"],
["047(336)5411/999","+81(047)3365411/999"],
["047(336)5411/","+81(047)3365411/"],
["047(336)5411","+81(047)3365411/"],
["+81 662 1244 4112/999","+81(662)12444112/999"],
["+81 662 1244 4112/","+81(662)12444112/"],
["+81 662 1244 4112","+81(662)12444112/"],
["+81-047-12345678/990","+81(047)12345678/990"],
["+81-047-12345678/","+81(047)12345678/"],
["+81-047-12345678","+81(047)12345678/"]
] ]
for i in inputdict: for i in input_list:
tel.fromText(coordinate_text=i[0]) tel.fromText(coordinate_text=i[0])
self.assertEquals(i[1],tel.asText()) self.assertEquals(i[1],tel.asText())
......
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