Ignore:
Timestamp:
18 Dec 2014, 12:58:12 (10 years ago)
Author:
Henrik Bettermann
Message:

Change document_id generation algorithm. Use Universally Unique IDentifiers instead of consecutive numbers.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/sample_contract_data.csv

    r12131 r12256  
    11class_name,contract_id,reg_number,title,product_object,document_object
    2 SampleContract,c3,1,My first contract,SAM,d101
    3 SampleContract,c4,2,My second contract,SAM,d101
    4 SampleContract,c5,3,My third contract,SAM,d101
    5 SampleContract,,1,My 4th contract,SAM,d101
    6 SampleContract,c5,2,My stolen contract,SAM,d101
     2SampleContract,c3,1,My first contract,SAM,DOC1
     3SampleContract,c4,2,My second contract,SAM,DOC1
     4SampleContract,c5,3,My third contract,SAM,DOC1
     5SampleContract,,1,My 4th contract,SAM,DOC1
     6SampleContract,c5,2,My stolen contract,SAM,DOC1
    77SampleContract,c6,3,My 5th contract,SAM,NONEXISTENT
    8 SampleContract,c7,3,My sixt contract,NONEXISTENT,d101
     8SampleContract,c7,3,My sixt contract,NONEXISTENT,DOC1
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_batching.py

    r12250 r12256  
    132132        document = createObject('waeup.CustomerSampleDocument')
    133133        document.title = u'My Document'
     134        document.document_id = u'DOC1'
    134135        customer['documents'].addDocument(document)
    135136        IWorkflowState(document).setState(VERIFIED)
     
    151152        super(CustomerProcessorTest, self).setUp()
    152153
    153         # Add customer with subobjects
     154        # Add customer
    154155        customer = Customer()
    155156        self.app['customers'].addCustomer(customer)
     
    305306            dict(customer_id='ID_NONE', document_id='nonsense'), self.app) is None
    306307        assert self.processor.getEntry(
    307             dict(customer_id=self.customer.customer_id, document_id='d101'),
    308             self.app) is self.customer['documents']['d101']
     308            dict(customer_id=self.customer.customer_id, document_id='DOC1'),
     309            self.app) is self.customer['documents']['DOC1']
    309310
    310311    def test_delEntry(self):
    311312        assert self.processor.getEntry(
    312             dict(customer_id=self.customer.customer_id, document_id='d101'),
    313             self.app) is self.customer['documents']['d101']
     313            dict(customer_id=self.customer.customer_id, document_id='DOC1'),
     314            self.app) is self.customer['documents']['DOC1']
    314315        self.assertEqual(len(self.customer['documents'].keys()),1)
    315316        self.processor.delEntry(
    316             dict(customer_id=self.customer.customer_id, document_id='d101'),
     317            dict(customer_id=self.customer.customer_id, document_id='DOC1'),
    317318            self.app)
    318319        assert self.processor.getEntry(
    319             dict(customer_id=self.customer.customer_id, document_id='d101'),
     320            dict(customer_id=self.customer.customer_id, document_id='DOC1'),
    320321            self.app) is None
    321322        self.assertEqual(len(self.customer['documents'].keys()),0)
    322323
    323324    def test_addEntry(self):
    324         self.assertEqual(self.app._curr_doc_id, 102)
    325325        self.assertEqual(len(self.customer['documents'].keys()),1)
    326326        document1 = createObject(u'waeup.CustomerSampleDocument')
    327         document1.document_id = 'd234'
     327        document1.document_id = u'd234'
    328328        self.processor.addEntry(
    329329            document1, dict(customer_id=self.customer.customer_id, document_id='d234'),
     
    331331        self.assertEqual(len(self.customer['documents'].keys()),2)
    332332        self.assertEqual(self.customer['documents']['d234'].document_id, 'd234')
    333         # _curr_doc_id hasn't changed
    334         self.assertEqual(self.app._curr_doc_id, 102)
    335333
    336334    def test_checkConversion(self):
    337         self.assertEqual(self.app._curr_doc_id, 102)
    338         errs, inv_errs, conv_dict = self.processor.checkConversion(
    339             dict(document_id='d126', class_name='CustomerSampleDocument'))
     335        errs, inv_errs, conv_dict = self.processor.checkConversion(
     336            dict(document_id='DOC', class_name='CustomerSampleDocument'))
    340337        self.assertEqual(len(errs),0)
    341         errs, inv_errs, conv_dict = self.processor.checkConversion(
    342             dict(document_id='nonsense', class_name='CustomerSampleDocument'))
     338        #errs, inv_errs, conv_dict = self.processor.checkConversion(
     339        #    dict(document_id='id with spaces', class_name='CustomerSampleDocument'))
     340        #self.assertEqual(len(errs),1)
     341        errs, inv_errs, conv_dict = self.processor.checkConversion(
     342            dict(document_id='DOC', class_name='WrongDocument'))
    343343        self.assertEqual(len(errs),1)
    344         errs, inv_errs, conv_dict = self.processor.checkConversion(
    345             dict(document_id='d127', class_name='WrongDocument'))
    346         self.assertEqual(len(errs),1)
    347         errs, inv_errs, conv_dict = self.processor.checkConversion(
    348             dict(document_id='', class_name='CustomerSampleDocument',
    349             mode='update'))
    350         self.assertEqual(len(errs),1)
    351         # _curr_doc_id hasn't changed
    352         self.assertEqual(self.app._curr_doc_id, 102)
    353344
    354345    def test_import(self):
    355346        num, num_warns, fin_file, fail_file = self.processor.doImport(
    356347            self.csv_file, DOCUMENT_HEADER_FIELDS,'create')
     348        fail_file = open(fail_file).read()
    357349        self.assertEqual(num_warns,1)
    358350        # document_id must be unique
    359         fail_file = open(fail_file).read()
    360351        self.assertEqual(fail_file,
    361352            'class_name,reg_number,document_id,title,--ERRORS--\r\n'
    362             'CustomerSampleDocument,2,d5,My stolen doc,document_id: id exists\r\n')
     353            'CustomerSampleDocument,2,d5,My stolen doc,'
     354            'This object already exists. Skipping.\r\n')
    363355        document = self.processor.getEntry(dict(reg_number='1',
    364356            document_id='d3'), self.app)
     
    371363        shutil.rmtree(os.path.dirname(fin_file))
    372364        logcontent = open(self.logfile).read()
    373         # Logging message from updateEntry
     365        # Fetch uuid
     366        docid = [i for i in self.app['customers']['X666666']['documents'].keys()
     367            if len(i) > 10][0]
     368         # Logging message from updateEntry
    374369        self.assertTrue(
    375370            'INFO - system - CustomerDocument Processor - '
    376             'sample_document_data - X666666 - updated: '
    377             'document_id=d3, title=My first doc'
    378             in logcontent)
     371            'sample_document_data - X666666 - %s - updated: title=My 4th doc'
     372            % docid in logcontent)
    379373
    380374    def test_import_update(self):
     
    387381        num, num_warns, fin_file, fail_file = self.processor.doImport(
    388382            self.csv_file, DOCUMENT_HEADER_FIELDS,'update')
    389         # There is one record without document_id and one duplicate
    390         self.assertEqual(num_warns,2)
     383        # There is one record without document_id
     384        self.assertEqual(num_warns,1)
    391385        shutil.rmtree(os.path.dirname(fin_file))
    392386
     
    475469        errs, inv_errs, conv_dict = self.processor.checkConversion(
    476470            dict(contract_id='c126', class_name='SampleContract',
    477                  document_object='d101', product_object='SAM'))
     471                 document_object='DOC1', product_object='SAM'))
    478472        self.assertEqual(len(errs),0)
    479473        errs, inv_errs, conv_dict = self.processor.checkConversion(
     
    495489            'reg_number,contract_id,title,class_name,product_object,'
    496490            'document_object,--ERRORS--\r\n'
    497             '2,c5,My stolen contract,SampleContract,SAM,d101,'
     491            '2,c5,My stolen contract,SampleContract,SAM,DOC1,'
    498492            'contract_id: id exists\r\n'
    499493            '3,c6,My 5th contract,SampleContract,SAM,NONEXISTENT,'
    500494            'document_object: Invalid value\r\n'
    501             '3,c7,My sixt contract,SampleContract,NONEXISTENT,d101,'
     495            '3,c7,My sixt contract,SampleContract,NONEXISTENT,DOC1,'
    502496            'product_object: Invalid value\r\n')
    503497        contract = self.processor.getEntry(dict(reg_number='1',
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12246 r12256  
    120120        self.document = createObject('waeup.CustomerSampleDocument')
    121121        self.document.title = u'My first document'
     122        self.document.document_id = u'DOC1'
    122123        self.customer['documents'].addDocument(self.document)
    123124        self.contract = createObject('waeup.SampleContract')
     
    834835        self.browser.getControl("Add document").click()
    835836        self.assertTrue('PDF Document added.' in self.browser.contents)
    836         document = self.customer['documents']['d102']
     837        docid = [i for i in self.customer['documents'].keys() if len(i) > 10][0]
     838        document = self.customer['documents'][docid]
    837839
    838840        # Document can be edited
    839         self.browser.getLink("d102").click()
     841        self.browser.getLink(docid).click()
    840842        self.browser.getLink("Manage").click()
    841843        self.browser.getControl(name="form.title").value = 'My second doc'
     
    843845        self.assertTrue('Form has been saved.' in self.browser.contents)
    844846        self.browser.getLink("View").click()
    845         self.assertEqual(self.browser.url, self.documents_path + '/d102/index')
     847        self.assertEqual(self.browser.url,
     848            self.documents_path + '/' + docid + '/index')
    846849
    847850        # Transitions can be performed
     
    859862
    860863        # Manage button and form is no longer available
    861         self.browser.open(self.documents_path + '/d102/index')
     864        self.browser.open(self.documents_path + '/' + docid + '/index')
    862865        self.assertFalse(
    863             'href="http://localhost/app/customers/K1000000/documents/d102/manage"'
    864             in self.browser.contents)
    865         self.browser.open(self.documents_path + '/d102/manage')
     866            'href="http://localhost/app/customers/K1000000/documents/%s/manage"'
     867            % docid in self.browser.contents)
     868        self.browser.open(self.documents_path + '/' + docid + '/manage')
    866869        self.assertTrue(
    867870            'The requested form is locked (read-only)'
     
    881884
    882885        self.assertTrue(
    883             'INFO - system - K1000000 - d101 - Document created'
     886            'INFO - system - K1000000 - DOC1 - Document created'
    884887            in logcontent)
    885888        self.assertTrue(
     
    889892        self.assertTrue(
    890893            'INFO - zope.mgr - customers.browser.DocumentManageFormPage '
    891             '- K1000000 - d102 - saved: title'
     894            '- K1000000 - %s - saved: title' % docid
    892895            in logcontent)
    893896        self.assertTrue(
    894             'INFO - zope.mgr - K1000000 - d102 - Submitted for verification'
    895             in logcontent)
     897            'INFO - zope.mgr - K1000000 - %s - Submitted for verification'
     898            % docid in logcontent)
    896899        self.assertTrue(
    897900            'INFO - zope.mgr - customers.browser.DocumentsManageFormPage '
    898             '- K1000000 - removed: d102'
     901            '- K1000000 - removed: %s' % docid
    899902            in logcontent)
    900903
     
    913916        self.browser.getControl("Add document").click()
    914917        self.assertTrue('Sample Document added.' in self.browser.contents)
    915         document = self.customer['documents']['d102']
     918        docid = [i for i in self.customer['documents'].keys() if len(i) > 10][0]
     919        document = self.customer['documents'][docid]
    916920
    917921        # Document can be edited ...
    918         self.browser.getLink("d102").click()
    919         self.browser.open(self.documents_path + '/d102/edit')
     922        self.browser.getLink(docid).click()
     923        self.browser.open(self.documents_path + '/' + docid + '/edit')
    920924        #self.browser.getLink("Edit").click()
    921925        self.assertTrue('The requested form is locked' in self.browser.contents)
    922926        # Customer is in wrong state
    923927        IWorkflowState(self.customer).setState(APPROVED)
    924         self.browser.open(self.documents_path + '/d102/edit')
     928        self.browser.open(self.documents_path + '/' + docid + '/edit')
    925929        self.browser.getControl(name="form.title").value = 'My second doc'
    926930        self.browser.getControl("Save").click()
     
    928932        self.assertTrue('Form has been saved.' in self.browser.contents)
    929933        self.browser.getLink("View").click()
    930         self.assertEqual(self.browser.url, self.documents_path + '/d102/index')
     934        self.assertEqual(
     935            self.browser.url, self.documents_path + '/%s/index' % docid)
    931936        # Costumer can upload a document.
    932937        self.browser.getLink("Edit").click()
     
    938943            name='upload_samplescaneditupload').click()
    939944        self.assertTrue(
    940             'href="http://localhost/app/customers/K1000000/documents/d102/sample"'
    941             in self.browser.contents)
     945            'href="http://localhost/app/customers/K1000000/documents/%s/sample"'
     946            % docid in self.browser.contents)
    942947        # Costumer can submit the form. The form is also saved.
    943948        self.browser.getControl(name="form.title").value = 'My third doc'
     
    947952        self.assertTrue('Document State: submitted for verification' in self.browser.contents)
    948953        # Customer can't edit the document once it has been submitted
    949         self.browser.open(self.documents_path + '/d102/edit')
     954        self.browser.open(self.documents_path + '/%s/edit' % docid)
    950955        self.assertTrue('The requested form is locked' in self.browser.contents)
    951956
     
    954959        # The image is stored even if form has errors
    955960        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    956         self.browser.open(self.customer_path + '/documents/d101/manage')
     961        self.browser.open(self.customer_path + '/documents/DOC1/manage')
    957962        # Create a pseudo image file and select it to be uploaded
    958963        image = open(SAMPLE_IMAGE, 'rb')
     
    963968        self.browser.getControl("Save").click() # submit form
    964969        self.assertFalse(
    965             'href="http://localhost/app/customers/K1000000/documents/d101/sample"'
     970            'href="http://localhost/app/customers/K1000000/documents/DOC1/sample"'
    966971            in self.browser.contents)
    967972        # ... but the correct upload submit button does
     
    973978            name='upload_samplescanmanageupload').click()
    974979        self.assertTrue(
    975             'href="http://localhost/app/customers/K1000000/documents/d101/sample"'
     980            'href="http://localhost/app/customers/K1000000/documents/DOC1/sample"'
    976981            in self.browser.contents)
    977982        # Browsing the link shows a real image
     
    981986        self.assertEqual(len(self.browser.contents), 2787)
    982987        # We can't reupload a file. The existing file must be deleted first.
    983         self.browser.open(self.customer_path + '/documents/d101/manage')
     988        self.browser.open(self.customer_path + '/documents/DOC1/manage')
    984989        self.assertFalse(
    985990            'upload_samplescanmanageupload' in self.browser.contents)
     
    10241029    def test_verify_document(self):
    10251030        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    1026         self.browser.open(self.customer_path + '/documents/d101/manage')
     1031        self.browser.open(self.customer_path + '/documents/DOC1/manage')
    10271032        image = open(SAMPLE_IMAGE, 'rb')
    10281033        ctrl = self.browser.getControl(name='samplescanmanageupload')
     
    10351040        self.assertEqual(
    10361041            getattr(self.document, 'sample_md5', None), None)
    1037         self.browser.open(self.documents_path + '/d101/trigtrans')
     1042        self.browser.open(self.documents_path + '/DOC1/trigtrans')
    10381043        self.browser.getControl(name="transition").value = ['verify']
    10391044        self.browser.getControl("Apply now").click()
     
    10511056        self.browser.getControl(name="form.title").value = 'My PDF Document'
    10521057        self.browser.getControl("Add document").click()
    1053         self.browser.open(self.documents_path + '/d102/manage')
     1058        docid = [i for i in self.customer['documents'].keys() if len(i) > 10][0]
     1059        self.browser.open(self.documents_path + '/%s/manage' % docid)
    10541060        # Create a pseudo image file and select it to be uploaded
    10551061        image = open(SAMPLE_IMAGE, 'rb')
     
    10751081            name='upload_pdfscanmanageupload').click()
    10761082        self.assertTrue(
    1077             'href="http://localhost/app/customers/K1000000/documents/d102/sample.pdf">PDF File</a>'
    1078             in self.browser.contents)
     1083            'href="http://localhost/app/customers/K1000000/documents/%s/sample.pdf">PDF File</a>'
     1084            % docid in self.browser.contents)
    10791085        # Browsing the link shows a real pdf
    10801086        self.browser.open('sample.pdf')
     
    10981104        jpegfile = open(SAMPLE_IMAGE, 'rb')
    10991105        fs.createFile(file_id, jpegfile)
    1100         self.browser.open(self.customer_path + '/documents/d101')
     1106        self.browser.open(self.customer_path + '/documents/DOC1')
    11011107        self.browser.getLink("Download document slip").click()
    11021108        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     
    11141120        pdffile = open(SAMPLE_PDF, 'rb')
    11151121        fs.createFile(file_id, pdffile)
    1116         self.browser.open(self.customer_path + '/documents/d102')
     1122        docid = [i for i in self.customer['documents'].keys() if len(i) > 10][0]
     1123        self.browser.open(self.customer_path + '/documents/' + docid)
    11171124        self.browser.getLink("Download document slip").click()
    11181125        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     
    11291136        fs.createFile(file_id, StringIO('my sample 1'))
    11301137        result = fs.getFileByContext(self.document, attr='sample')
    1131         self.assertEqual(file_id, '__file-customerdocument__01000/K1000000/sample_d101_K1000000')
     1138        self.assertEqual(file_id, '__file-customerdocument__01000/K1000000/sample_DOC1_K1000000')
    11321139        self.assertEqual(result.read(), 'my sample 1')
    11331140        self.assertEqual(self.document.connected_files[0][1].read(), 'my sample 1')
     
    12531260        self.browser.open(self.contracts_path + '/c102/edit')
    12541261        self.browser.getControl(name="form.product_object").value = ['SAM']
    1255         self.browser.getControl(name="form.document_object").value = ['d101']
     1262        self.browser.getControl(name="form.document_object").value = ['DOC1']
    12561263        self.browser.getControl(name="form.title").value = 'My second contract'
    12571264        self.browser.getControl("Save").click()
     
    12731280            in self.browser.contents)
    12741281        self.assertTrue(
    1275             '<a href="http://localhost/app/customers/K1000000/documents/d101">d101 -'
     1282            '<a href="http://localhost/app/customers/K1000000/documents/DOC1">DOC1 -'
    12761283            in self.browser.contents)
    12771284        # Customer can submit the form. The form is also saved.
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_catalog.py

    r12195 r12256  
    213213        logcontent = open(logfile).read()
    214214        self.assertTrue(
    215             'INFO - system - ObjectRemovedEvent - K1000000 - c101 - removed: d101\n'
    216             in logcontent)
    217 
     215            'INFO - system - ObjectRemovedEvent - K1000000 - c101 - removed: %s\n'
     216            % self.document_id in logcontent)
     217
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_document.py

    r12205 r12256  
    156156        # we can't get an image filename for documents not owned by a customer
    157157        doc = CustomerSampleDocument()
     158        doc.document_id = u'DOC1'
    158159        chooser = IFileStoreNameChooser(doc)
    159160        # no customer can be found
     
    168169        result = chooser.chooseName('sample.jpg')
    169170        self.assertEqual(
    170             result, '__file-customerdocument__01000/K1000001/sample_d123_K1000001.jpg')
     171            result, '__file-customerdocument__01000/K1000001/sample_DOC1_K1000001.jpg')
    171172        return
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_export.py

    r12221 r12256  
    156156        # we can export a nearly empty document
    157157        document = CustomerSampleDocument()
     158        document.document_id = u'DOC1'
    158159        exporter = CustomerDocumentExporter()
    159160        exporter.export([document], self.outfile)
     
    162163            result,
    163164            'class_name,document_id,history,state,title,user_id\r\n'
    164             'CustomerSampleDocument,d101,[],,,\r\n'
     165            'CustomerSampleDocument,DOC1,[],,,\r\n'
    165166            )
    166167        return
     
    170171        # set values we can expect in export file
    171172        self.setup_customer(self.customer)
    172         document = self.customer['documents']['d101']
     173        document = self.customer['documents']['DOC1']
    173174        exporter = CustomerDocumentExporter()
    174175        exporter.export([document], self.outfile)
     
    179180            )
    180181        self.assertMatches(
    181             '...CustomerSampleDocument,d101,[u\'2014-11-25 06:57:24 UTC - '
     182            '...CustomerSampleDocument,DOC1,[u\'2014-11-25 06:57:24 UTC - '
    182183            'Document created by system\'],'
    183184            'verified,My Document,A111111...',
     
    197198            in result)
    198199        self.assertMatches(
    199             '...CustomerSampleDocument,d101,[u\'2014-11-25 06:57:24 UTC - '
     200            '...CustomerSampleDocument,DOC1,[u\'2014-11-25 06:57:24 UTC - '
    200201            'Document created by system\'],'
    201202            'verified,My Document,A111111...',
     
    215216            in result)
    216217        self.assertMatches(
    217             '...CustomerSampleDocument,d101,[u\'2014-11-25 06:57:24 UTC - '
     218            '...CustomerSampleDocument,DOC1,[u\'2014-11-25 06:57:24 UTC - '
    218219            'Document created by system\'],'
    219220            'verified,My Document,A111111...',
     
    273274            'product_object,state,title\r\n'
    274275
    275             'SampleContract,sample,c101,d101,[u\'2014-12-04 12:10:46 UTC - '
     276            'SampleContract,sample,c101,DOC1,[u\'2014-12-04 12:10:46 UTC - '
    276277            'Contract created by system\'],,'
    277278            'SAM,created,My Contract\r\n',
     
    292293            'product_object,state,title\r\n'
    293294
    294             'SampleContract,sample,c101,d101,[u\'2014-12-04 12:10:46 UTC - '
     295            'SampleContract,sample,c101,DOC1,[u\'2014-12-04 12:10:46 UTC - '
    295296            'Contract created by system\'],,'
    296297            'SAM,created,My Contract\r\n',
     
    311312            'product_object,state,title\r\n'
    312313
    313             'SampleContract,sample,c101,d101,[u\'2014-12-04 12:10:46 UTC - '
     314            'SampleContract,sample,c101,DOC1,[u\'2014-12-04 12:10:46 UTC - '
    314315            'Contract created by system\'],,'
    315316            'SAM,created,My Contract\r\n',
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_interfaces.py

    r12102 r12256  
    7777        document = createObject('waeup.CustomerSampleDocument')
    7878        document.title = u'My Samle Document'
     79        document.document_id = u'DOC1'
    7980        self.customer['documents'].addDocument(document)
    8081        self.document_id = document.document_id
     
    107108        source = CustomerDocumentSource()
    108109        result = source.factory.getTitle(object(), self.document)
    109         self.assertEqual(result, u'd101 - My Samle Document')
     110        self.assertEqual(result, u'DOC1 - My Samle Document')
    110111
Note: See TracChangeset for help on using the changeset viewer.