Changeset 12260


Ignore:
Timestamp:
19 Dec 2014, 08:11:12 (10 years ago)
Author:
Henrik Bettermann
Message:

Validate document and contract ids properly.

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  
    2323from waeup.ikoba.interfaces import MessageFactory as _
    2424from waeup.ikoba.interfaces import (
    25     IIkobaObject, validate_email, ICSVExporter)
     25    IIkobaObject, validate_email, ICSVExporter, validate_uuid)
    2626from waeup.ikoba.schema import TextLineChoice, FormattedDate, PhoneNumber
    2727from waeup.ikoba.browser.interfaces import ICustomerNavigationBase
     
    128128        constraint=validate_email,
    129129        )
     130
    130131    phone = PhoneNumber(
    131132        title = _(u'Phone'),
     
    243244    is_editable_by_manager = Attribute('Document editable by manager')
    244245
    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
     253class ICustomerPDFDocument(ICustomerDocument):
    247254    """A customer document.
    248255
     
    282289        title = _(u'Contract Id'),
    283290        required = False,
     291        constraint=validate_uuid,
    284292        )
    285293
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_batching.py

    r12259 r12260  
    337337            dict(document_id='DOC', class_name='CustomerSampleDocument'))
    338338        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)
    342342        errs, inv_errs, conv_dict = self.processor.checkConversion(
    343343            dict(document_id='DOC', class_name='WrongDocument'))
     
    468468                 document_object='DOC1', product_object='SAM'))
    469469        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)
    473473        errs, inv_errs, conv_dict = self.processor.checkConversion(
    474474            dict(contract_id='CON3', class_name='WrongContract'))
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/batching.py

    r12256 r12260  
    119119                errs.append(('class_name','wrong processor'))
    120120        document_id = row.get('document_id', None)
    121         if ' ' in document_id:
    122             errs.append(('document_id','must not contain spaces'))
    123121        return errs, inv_errs, conv_dict
    124122
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/interfaces.py

    r12256 r12260  
    1919from zope import schema
    2020from waeup.ikoba.interfaces import (
    21     IIkobaObject,
     21    IIkobaObject, validate_id,
    2222    ContextualDictSourceFactoryBase)
    2323from waeup.ikoba.interfaces import MessageFactory as _
     
    5252        title = _(u'Document Id'),
    5353        required = False,
     54        constraint=validate_id,
    5455        )
    5556
  • main/waeup.ikoba/trunk/src/waeup/ikoba/interfaces.py

    r12251 r12260  
    142142    return True
    143143
     144# Define a validation method for email addresses
     145class NotIdValue(schema.ValidationError):
     146    __doc__ = u"Invalid id"
     147
     148#: Regular expressions to check id formats.
     149check_id = re.compile(r"^[a-zA-Z0-9_-]{2,6}$").match
     150check_uuid = re.compile( r"^[a-zA-Z0-9]{32}$").match
     151
     152def validate_id(value):
     153    if not check_id(value):
     154        raise NotIdValue(value)
     155    return True
     156
     157def 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
    144163# Define a validation method for international phone numbers
    145164class InvalidPhoneNumber(schema.ValidationError):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/tests/test_interfaces.py

    r11949 r12260  
    2121import grok
    2222import unittest
    23 from waeup.ikoba.interfaces import DuplicationError, RoleSource, check_email
     23from waeup.ikoba.interfaces import (
     24    DuplicationError, RoleSource, check_email, check_id, check_uuid)
    2425from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase
    2526
     
    6162        self.assertTrue(check_email('bob@foo,alice@bar') is None)
    6263        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
    6381
    6482class DuplicationErrorTests(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.