Changeset 12260
- Timestamp:
- 19 Dec 2014, 08:11:12 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py
r12258 r12260 23 23 from waeup.ikoba.interfaces import MessageFactory as _ 24 24 from waeup.ikoba.interfaces import ( 25 IIkobaObject, validate_email, ICSVExporter )25 IIkobaObject, validate_email, ICSVExporter, validate_uuid) 26 26 from waeup.ikoba.schema import TextLineChoice, FormattedDate, PhoneNumber 27 27 from waeup.ikoba.browser.interfaces import ICustomerNavigationBase … … 128 128 constraint=validate_email, 129 129 ) 130 130 131 phone = PhoneNumber( 131 132 title = _(u'Phone'), … … 243 244 is_editable_by_manager = Attribute('Document editable by manager') 244 245 245 246 class ICustomerPDFDocument(IDocument): 246 document_id = schema.TextLine( 247 title = _(u'Document Id'), 248 required = False, 249 constraint=validate_uuid, 250 ) 251 252 253 class ICustomerPDFDocument(ICustomerDocument): 247 254 """A customer document. 248 255 … … 282 289 title = _(u'Contract Id'), 283 290 required = False, 291 constraint=validate_uuid, 284 292 ) 285 293 -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_batching.py
r12259 r12260 337 337 dict(document_id='DOC', class_name='CustomerSampleDocument')) 338 338 self.assertEqual(len(errs),0) 339 #errs, inv_errs, conv_dict = self.processor.checkConversion(340 #dict(document_id='id with spaces', class_name='CustomerSampleDocument'))341 #self.assertEqual(len(errs),1)339 errs, inv_errs, conv_dict = self.processor.checkConversion( 340 dict(document_id='id with spaces', class_name='CustomerSampleDocument')) 341 self.assertEqual(len(errs),1) 342 342 errs, inv_errs, conv_dict = self.processor.checkConversion( 343 343 dict(document_id='DOC', class_name='WrongDocument')) … … 468 468 document_object='DOC1', product_object='SAM')) 469 469 self.assertEqual(len(errs),0) 470 #errs, inv_errs, conv_dict = self.processor.checkConversion(471 #dict(contract_id='id with spaces', class_name='SampleContract'))472 #self.assertEqual(len(errs),1)470 errs, inv_errs, conv_dict = self.processor.checkConversion( 471 dict(contract_id='id with spaces', class_name='SampleContract')) 472 self.assertEqual(len(errs),1) 473 473 errs, inv_errs, conv_dict = self.processor.checkConversion( 474 474 dict(contract_id='CON3', class_name='WrongContract')) -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/batching.py
r12256 r12260 119 119 errs.append(('class_name','wrong processor')) 120 120 document_id = row.get('document_id', None) 121 if ' ' in document_id:122 errs.append(('document_id','must not contain spaces'))123 121 return errs, inv_errs, conv_dict 124 122 -
main/waeup.ikoba/trunk/src/waeup/ikoba/documents/interfaces.py
r12256 r12260 19 19 from zope import schema 20 20 from waeup.ikoba.interfaces import ( 21 IIkobaObject, 21 IIkobaObject, validate_id, 22 22 ContextualDictSourceFactoryBase) 23 23 from waeup.ikoba.interfaces import MessageFactory as _ … … 52 52 title = _(u'Document Id'), 53 53 required = False, 54 constraint=validate_id, 54 55 ) 55 56 -
main/waeup.ikoba/trunk/src/waeup/ikoba/interfaces.py
r12251 r12260 142 142 return True 143 143 144 # Define a validation method for email addresses 145 class NotIdValue(schema.ValidationError): 146 __doc__ = u"Invalid id" 147 148 #: Regular expressions to check id formats. 149 check_id = re.compile(r"^[a-zA-Z0-9_-]{2,6}$").match 150 check_uuid = re.compile( r"^[a-zA-Z0-9]{32}$").match 151 152 def validate_id(value): 153 if not check_id(value): 154 raise NotIdValue(value) 155 return True 156 157 def validate_uuid(value): 158 # We are using also short ids in tests 159 if not check_uuid(value) and not check_id(value): 160 raise NotIdValue(value) 161 return True 162 144 163 # Define a validation method for international phone numbers 145 164 class InvalidPhoneNumber(schema.ValidationError): -
main/waeup.ikoba/trunk/src/waeup/ikoba/tests/test_interfaces.py
r11949 r12260 21 21 import grok 22 22 import unittest 23 from waeup.ikoba.interfaces import DuplicationError, RoleSource, check_email 23 from waeup.ikoba.interfaces import ( 24 DuplicationError, RoleSource, check_email, check_id, check_uuid) 24 25 from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase 25 26 … … 61 62 self.assertTrue(check_email('bob@foo,alice@bar') is None) 62 63 return 64 65 def test_check_id(self): 66 self.assertTrue(check_id('abcABC') is not None) 67 # No spaces 68 self.assertTrue(check_id('abc ABC') is None) 69 # More than 6 characters are not allowed 70 self.assertTrue(check_id('abcdefg') is None) 71 # Only underscores and hyphens are allowed 72 self.assertTrue(check_id('a+b') is None) 73 self.assertTrue(check_id('a/b') is None) 74 self.assertTrue(check_id('a-b') is not None) 75 self.assertTrue(check_id('a_b') is not None) 76 # 32 charachters are allowed 77 self.assertTrue( 78 check_uuid('dfceb5c587364faf95e17b3cbaf98d5f') is not None) 79 return 80 63 81 64 82 class DuplicationErrorTests(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.