Commit d7d089e8 authored by Rafael Monnerat's avatar Rafael Monnerat

Replaced dictionary per simple list of regex (Lucas)

Improved the code style (Rafael and Lucas)



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21309 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 63dd1305
...@@ -66,235 +66,93 @@ class Telephone(Coordinate, Base): ...@@ -66,235 +66,93 @@ class Telephone(Coordinate, Base):
, PropertySheet.SimpleItem , PropertySheet.SimpleItem
, PropertySheet.Telephone , PropertySheet.Telephone
) )
# This is a list of regex.
# The notation always need to have: # Each regex into the list handle a single (or should handle) input.
# <country> or <area> or <number> or <ext> # The list is a priority list,
# If uses a different tag it will be ignored. # be carefull to add a new regex.
standard_dict = { regex_list = [
# France
'33' : {
"regex_input_list" : [
# Country, Area, Number, Extension* # Country, Area, Number, Extension*
# +33(0)2-27224896/999 or +33(0)2-27224896/ or +33(0)2-27224896 # +33(0)2-27224896/999 or +33(0)2-27224896/ or +33(0)2-27224896
"\+(?P<country>\d+)\(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 # Country, Area, Number, Extension*
# +(0)2-27224896/999" or +(0)2-27224896/ or +(0)2-27224896 # +81-2-27224896/999 or +81-2-27224896/ or +81-2-27224896
"\+\(0\)(?P<area>\d+)\-(?P<number>[\d\ ]*)(?:\/)?(?P<ext>\d+|)", "\+(?P<country>\d+)-(?P<area>\d+)-(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Missing area # Missing area
# +33(0)-27224896/999" or +33(0)-27224896/ or +33(0)-27224896 # +33(0)-27224896/999" or +33(0)-27224896/ or +33(0)-27224896
"\+(?P<country>\d+)\(0\)\-(?P<number>[\d\ ]*)(?:\/)?(?P<ext>\d+|)", "\+(?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>"
},
# Brazil
'55' : {
"regex_input_list" : [
# Country, Area, Number, Extension* # Country, Area, Number, Extension*
# +55(2)27224896/999 or +55(2)27224896/ or +55(2)27224896 # +55(2)27224896/999 or +55(2)27224896/ or +55(2)27224896
"\+(?P<country>\d+)\((?P<area>\d+)\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)", "\+(?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>",
},
# Senegal
'221' : {
"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* # Country, Area, Number, Extension*
# +221-2-27224896/999 or +221-2-27224896/ or +221-2-27224896 # +221-2-27224896/999 or +221-2-27224896/ or +221-2-27224896
"\+(?P<country>\d+)-(?P<area>\d+)-(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)", "\+(?P<country>\d+)-(?P<area>\d+)-(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)",
# Missing country # Missing country
# +(2)27224896/999" or +(2)27224896/ or +(2)27224896 # +(0)2-27224896/999" or +(0)2-27224896/ or +(0)2-27224896
"\+\((?P<area>\d+)\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)", "\+\(0\)(?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 # Missing Country and Area
# +()27224896/999" or +()27224896/ or +()27224896 # +(0)-27224896/999" or +(0)-27224896/ or +(0)-27224896
"\+\(\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)", "\+\(0\)\-(?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, Number Extension*
# Area between parenthesis. # Area between parenthesis.
# (22)27224897/333 or (22)27224897/ or (22)27224897 # (22)27224897/333 or (22)27224897/ or (22)27224897
"\((?P<area>\d+)\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)", "\((?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>",
},
# Japan
'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 # Missing country
# +(2)27224896/999" or +(2)27224896/ or +(2)27224896 # +(2)27224896/999" or +(2)27224896/ or +(2)27224896
"\+\((?P<area>\d+)\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)", "\+\((?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, Area, Number and Extension*
# Country space area space number slash extension or not # Country space area space number slash extension or not
# +81 2 098765432/1 or +81 2 098765432/ or +81 2 098765432 # +33 2 098765432/1 or +33 2 098765432/ or +33 2 098765432
"\+(?P<country>\d+)\ (?P<area>\d+)\ (?P<number>[\d\ ]*)(?:\/)?(?P<ext>\d+|)", "\+(?P<country>\d+)\ (?P<area>\d+)\ (?P<number>[\d\ ]*)(?:\/)?(?P<ext>\d+|)",
# This regex is to handle two inputs very similar # This regex is to handle two inputs very similar
# but with different behavior # but with different behavior
# 631 22 43/999 or 631 22 43 or 631 22 43 # 631 22 43/999 or 631 22 43 or 631 22 43
# will result in {'area':'', 'country':'631 22 43', 'ext':'999 or empty'} # will result in {'area':'', 'number':'631 22 43', 'ext':'999 or empty'}
# #
# 631-22 43/999 or 631-22 43 or 631-22 43 # 631-22 43/999 or 631-22 43 or 631-22 43
# will result in {'area':'631', 'country':'22 43', 'ext':'999 or empty'} # will result in {'area':'631', 'number':'22 43', 'ext':'999 or empty'}
"^((?P<area>\d+)-)?(?P<number>[\d\-\ ]*)(?:\/)?(?P<ext>\d+|)$", "^(?:0)?((?P<area>\d+)-)?(?P<number>[\d\-\ ]*)(?:\/)?(?P<ext>\d+|)$",
# Area, Number, Extension* # Area, Number, Extension*
# It is a common input in France
# and in Japan but with different behavior.
# 047-336-5411/999 or 047-336-5411/ or 047-336-5411 # 047-336-5411/999 or 047-336-5411/ or 047-336-5411
"^(?P<area>\d+)-(?P<number>[\d\-\ ]*)(?:\/)?(?P<ext>\d+|)$", # will result in {'area':'47', 'number':'336-5411', \
# 'ext':'999 or empty'} <= France
# will result in {'area':'047', 'number':'336-5411',
# 'ext':'999 or empty'} <= Japan
# so we have here two regex:
# To France: "^0(?P<area>\d+)-(?P<number>[\d\-\ ]*)(?:\/)?(?P<ext>\d+|)$",
# To Japan: "^(?P<area>\d+)-(?P<number>[\d\-\ ]*)(?:\/)?(?P<ext>\d+|)$",
"^0(?P<area>\d+)-(?P<number>[\d\-\ ]*)(?:\/)?(?P<ext>\d+|)$",
# Area, Number, Extension* # Area, Number, Extension*
# It is a common input in France and in Japan but with different behavior.
# 047(336)5411/999 or 047(336)5411/ or 047(336)5411 # 047(336)5411/999 or 047(336)5411/ or 047(336)5411
"^(?P<area>\d+)\((?P<number>[\d\)\(\ \-]*)(?:\/)?(?P<ext>\d+|)$" # will result in {'area':'47', 'number':'336)5411',
], # 'ext':'999 or empty'} <= France
"notation" : "+<country>(<area>)<number>/<ext>", # will result in {'area':'047', 'number':'336)5411',
} # 'ext':'999 or empty'} <= Japan
} # so we have here two regex:
#To France:
# "^0(?P<area>\d+)\((?P<number>[\d\)\(\ \-]*)(?:\/)?(?P<ext>\d+|)$",
#To Japan:
# "^(?P<area>\d+)\((?P<number>[\d\)\(\ \-]*)(?:\/)?(?P<ext>\d+|)$",
"^0(?P<area>\d+)\((?P<number>[\d\)\(\ \-]*)(?:\/)?(?P<ext>\d+|)$",
# Missing area
# +55()27224896/999" or +55()27224896/ or +55()27224896
"\+(?P<country>\d+)\(\)(?P<number>[\d\ \-]*)(?:\/)?(?P<ext>\d+|)"
]
security.declareProtected(Permissions.ModifyPortalContent, 'fromText') security.declareProtected(Permissions.ModifyPortalContent, 'fromText')
def fromText(self, coordinate_text): def fromText(self, coordinate_text):
...@@ -313,55 +171,50 @@ class Telephone(Coordinate, Base): ...@@ -313,55 +171,50 @@ class Telephone(Coordinate, Base):
coordinate_text)) coordinate_text))
# Test if coordinate_text has or not markups. # Test if coordinate_text has or not markups.
if len(coordinate_text) > len(input_without_markup): if len(coordinate_text) > len(input_without_markup):
# Trying to get the regex list.
input_parser_list = self._getRegexList(coordinate_text=coordinate_text)
number_match = None number_match = None
for input_parser in input_parser_list: for regex in self._getRegexList():
possible_number_match = re.match(input_parser, coordinate_text) possible_number_match = re.match(regex, coordinate_text)
if possible_number_match not in [None]: if possible_number_match not in [None]:
number_match = possible_number_match number_match = possible_number_match
break break
if number_match == None: if number_match == None:
from zLOG import LOG, WARNING from zLOG import LOG, WARNING
msg = "Doesn't exist a regex to handle this telephone: ", coordinate_text msg = "Doesn't exist a regex to handle this telephone: ", \
LOG('*** Telephone ***',WARNING,msg) coordinate_text
LOG('Telephone.fromText', 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','')
ext=number_dict.get('ext','') extension = number_dict.get('ext','')
if ((country in ['', None]) and \ if ((country in ['', None]) and \
(area in ['', None]) and \ (area in ['', None]) and \
(number in ['', None]) and \ (number in ['', None]) and \
(ext in ['', None])): (extension 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() preference_tool = self.portal_preferences
area_default_number = self.portal_preferences.getPreferredTelephoneDefaultAreaNumber() if country in ['', None]:
country = preference_tool.getPreferredTelephoneDefaultCountryNumber('')
if area in ['', None]:
area = preference_tool.getPreferredTelephoneDefaultAreaNumber('')
country = (number_dict.get('country') or \ country = country.strip()
country_default_number or \ area = area.strip()
'').strip() number = number.strip()
area = (number_dict.get('area') or \ extension = extension.strip()
area_default_number or
'').strip()
number = (number_dict.get('number') or '').strip()
# Formating the number. # Formating the number.
# Removing any ")", "(", "-" and " " # Removing any ")", "(", "-" and " "
number = number.replace('-', '') for token in [")", "(", "-" ," "]:
number = number.replace(' ','') number = number.replace(token, '')
number = number.replace(')','')
number = number.replace('(','')
extension = (number_dict.get('ext') or '').strip()
self.edit(telephone_country = country, self.edit(telephone_country = country,
telephone_area = area, telephone_area = area,
...@@ -380,29 +233,29 @@ class Telephone(Coordinate, Base): ...@@ -380,29 +233,29 @@ class Telephone(Coordinate, Base):
if script is not None: if script is not None:
return script() return script()
telephone_country = self.getTelephoneCountry() or '' country = self.getTelephoneCountry('')
telephone_area = self.getTelephoneArea() or '' area = self.getTelephoneArea('')
telephone_number = self.getTelephoneNumber() or '' number = self.getTelephoneNumber('')
telephone_extension = self.getTelephoneExtension() or '' extension = self.getTelephoneExtension('')
# If country, area, number, extension are blank # If country, area, number, extension are blank
# the method should to return blank. # the method should to return blank.
if ((telephone_country == '') and \ if ((country == '') and \
(telephone_area == '') and \ (area == '') and \
(telephone_number == '') and \ (number == '') and \
(telephone_extension == '')): (extension == '')):
return '' return ''
# Trying to get the notation # Define the notation
notation = self._getNotation(telephone_country=telephone_country) notation = self._getNotation()
if notation not in [None, '']: if notation not in [None, '']:
notation=notation.replace('<country>',telephone_country) notation = notation.replace('<country>',country)
notation=notation.replace('<area>',telephone_area) notation = notation.replace('<area>',area)
notation=notation.replace('<number>',telephone_number) notation = notation.replace('<number>',number)
notation=notation.replace('<ext>',telephone_extension) notation = notation.replace('<ext>',extension)
if telephone_extension == '': if extension == '':
notation=notation.replace('/','') notation = notation.replace('/','')
return notation return notation
...@@ -440,33 +293,16 @@ class Telephone(Coordinate, Base): ...@@ -440,33 +293,16 @@ 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 _getNotation(self):
""" """
Returns a dict with Regex and Notations based from Returns the notation that will be used by asText method.
country or region
""" """
# Trying to get the Regex Dict # The notation can be changed.
if index not in self.standard_dict.keys(): # But needs to have <country>, <area>, <number> and <ext>
index = self.portal_preferences.getPreferredTelephoneDefaultCountryNumber() or '33' return "+<country>(0)<area>-<number>/<ext>"
return self.standard_dict.get(index) def _getRegexList(self):
def _getRegexList(self, coordinate_text):
"""
Returns the regex list.
""" """
# Trying to get a possible contry number Returns the regex list that will be used by fromText method.
country_regex = '((\+|)(?P<country>\d*))'
country = re.match(country_regex, \
coordinate_text).groupdict().get('country','')
regex_dict = self._getRegexDict(index=country)
input_parser = regex_dict.get('regex_input_list')
return input_parser
def _getNotation(self, telephone_country):
""" """
Returns the notation that will be used by asText method. return self.regex_list
"""
regex_dict = self._getRegexDict(index=telephone_country)
notation = regex_dict.get('notation')
return notation
...@@ -873,7 +873,7 @@ class TestERP5Base(ERP5TypeTestCase): ...@@ -873,7 +873,7 @@ 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_TelephoneInputListForFrance(self): def test_TelephoneInputList(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
...@@ -925,7 +925,6 @@ class TestERP5Base(ERP5TypeTestCase): ...@@ -925,7 +925,6 @@ class TestERP5Base(ERP5TypeTestCase):
["62 05 76 14/","+33(0)2-62057614"], ["62 05 76 14/","+33(0)2-62057614"],
["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/999","+33(0)2-6312243/999"],
["631 22 43/","+33(0)2-6312243"], ["631 22 43/","+33(0)2-6312243"],
["631 22 43","+33(0)2-6312243"], ["631 22 43","+33(0)2-6312243"],
...@@ -947,263 +946,35 @@ class TestERP5Base(ERP5TypeTestCase): ...@@ -947,263 +946,35 @@ class TestERP5Base(ERP5TypeTestCase):
["+33 662 1244 4112/999","+33(0)662-12444112/999"], ["+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"],
["+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"]
]
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"],
["+55(2)27224896/999","+55(0)2-27224896/999"],
["+55(2)27224896/","+55(0)2-27224896"],
["+55(2)27224896","+55(0)2-27224896"],
["631 22 43/999","+81(2)6312243/999"], ["+55()27224896/999","+55(0)2-27224896/999"],
["631 22 43/","+81(2)6312243"], ["+55()27224896/","+55(0)2-27224896"],
["631 22 43","+81(2)6312243"], ["+55()27224896","+55(0)2-27224896"],
["631-22 43/999","+81(631)2243/999"], ["+55()-27224896/999","+55(0)2-27224896/999"],
["631-22 43/","+81(631)2243"], ["+55()-27224896/","+55(0)2-27224896"],
["631-22 43","+81(631)2243"], ["+55()-27224896","+55(0)2-27224896"],
["8291212/33","+81(2)8291212/33"], ["+55(629)024425/222","+55(0)629-024425/222"],
["+55(629)024425/","+55(0)629-024425"],
["+55(629)024425","+55(0)629-024425"],
["047-336-5411/999","+81(047)3365411/999"], ["+55 2 098765432/1","+55(0)2-098765432/1"],
["047-336-5411/","+81(047)3365411"], ["+55 2 098765432/","+55(0)2-098765432"],
["047-336-5411","+81(047)3365411"], ["+55 2 098765432","+55(0)2-098765432"],
["047(336)5411/999","+81(047)3365411/999"], ["+55 662 1241 1233/999","+55(0)662-12411233/999"],
["047(336)5411/","+81(047)3365411"], ["+55 662 1241 1233/","+55(0)662-12411233"],
["047(336)5411","+81(047)3365411"], ["+55 662 1241 1233","+55(0)662-12411233"],
["+81 662 1244 4112/999","+81(662)12444112/999"], ["+55-047-12345678/990","+55(0)047-12345678/990"],
["+81 662 1244 4112/","+81(662)12444112"], ["+55-047-12345678/","+55(0)047-12345678"],
["+81 662 1244 4112","+81(662)12444112"], ["+55-047-12345678","+55(0)047-12345678"]
["+81-047-12345678/990","+81(047)12345678/990"],
["+81-047-12345678/","+81(047)12345678"],
["+81-047-12345678","+81(047)12345678"]
] ]
for i in input_list: for i in input_list:
......
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