Ignore:
Timestamp:
3 Jan 2015, 18:02:11 (12 years ago)
Author:
Henrik Bettermann
Message:

Implement two different types of PCN customer documents.

Location:
main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/tests/test_browser.py

    r12371 r12384  
    3232from ikobacustom.pcn.customers.export import (
    3333    PCNCustomerExporter,
    34     PCNCustomerDocumentExporter,
     34    PCNCustomerPDFDocumentExporter,
     35    PCNCustomerJPGDocumentExporter,
    3536    PCNContractExporter)
    3637from ikobacustom.pcn.customers.batching import (
    3738    PCNCustomerProcessor,
    38     PCNCustomerDocumentProcessor,
     39    PCNCustomerPDFDocumentProcessor,
     40    PCNCustomerJPGDocumentProcessor,
    3941    PCNContractProcessor)
    4042from ikobacustom.pcn.testing import FunctionalLayer, samples_dir
    … …  
    5658        IWorkflowState(customer).setState('started')
    5759        self.app['customers'].addCustomer(customer)
    58         document = createObject(u'waeup.PCNCustomerDocument')
    59         document.title = u'My first document'
    60         customer['documents'].addDocument(document)
     60        document1 = createObject(u'waeup.PCNCustomerPDFDocument')
     61        document1.title = u'My first document'
     62        document2 = createObject(u'waeup.PCNCustomerJPGDocument')
     63        document2.title = u'My second document'
     64        customer['documents'].addDocument(document1)
     65        customer['documents'].addDocument(document2)
    6166        contract = createObject(u'waeup.PCNContract')
    6267        contract.tc_dict = {'en':u'Hello World'}
    6368        customer['contracts'].addContract(contract)
    6469        self.customer = customer
    65         self.document = document
     70        self.document1 = document1
     71        self.document2 = document2
    6672        self.contract = contract
    6773        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
    … …  
    108114        return
    109115
    110     def test_export_reimport_documents(self):
     116    def test_export_reimport_pdf_documents(self):
    111117        # we can export all documents in a portal
    112118        # set values we can expect in export file
    113119        self.setup_for_export()
    114         exporter = PCNCustomerDocumentExporter()
     120        exporter = PCNCustomerPDFDocumentExporter()
    115121        exporter.export_all(self.app, self.outfile)
    116122        result = open(self.outfile, 'rb').read()
    117123        self.assertMatches(result,
    118124            'class_name,document_id,history,state,title,user_id\r\n'
    119             'PCNCustomerDocument,%s,'
     125            'PCNCustomerPDFDocument,%s,'
    120126            '[u\'2014-12-21 17:00:36 WAT - Document created by system\'],'
    121127            'created,My first document,K1000000\r\n'
    122             % self.document.document_id)
     128            % self.document1.document_id)
    123129        # We can reimport the file if we change the header (user_id -> customer_id)
    124         processor = PCNCustomerDocumentProcessor()
     130        processor = PCNCustomerPDFDocumentProcessor()
    125131        open(self.outfile, 'wb').write(
    126132            'customer_id,class_name,document_id,state,title\r\n'
    127             'K1000000,PCNCustomerDocument,%s,started,My first title\r\n'
    128             % self.document.document_id)
     133            'K1000000,PCNCustomerPDFDocument,%s,started,My first title\r\n'
     134            % self.document1.document_id)
    129135        result = processor.doImport(
    130136            self.outfile,
    … …  
    135141        self.assertEqual(num_fail,1)
    136142        # We remove the original document.
    137         del self.customer['documents'][self.document.document_id]
     143        del self.customer['documents'][self.document1.document_id]
     144        result = processor.doImport(
     145            self.outfile,
     146            ['customer_id','class_name','document_id','state','title'],
     147            mode='create')
     148        num_succ, num_fail, finished_path, failed_path = result
     149        self.assertEqual(num_fail,0)
     150        # We can import the same file in update mode.
     151        result = processor.doImport(
     152            self.outfile,
     153            ['customer_id','class_name','document_id','state','title'],
     154            mode='update')
     155        num_succ, num_fail, finished_path, failed_path = result
     156        self.assertEqual(num_succ,1)
     157        self.assertEqual(num_fail,0)
     158        return
     159
     160    def test_export_reimport_jpg_documents(self):
     161        # we can export all documents in a portal
     162        # set values we can expect in export file
     163        self.setup_for_export()
     164        exporter = PCNCustomerJPGDocumentExporter()
     165        exporter.export_all(self.app, self.outfile)
     166        result = open(self.outfile, 'rb').read()
     167        self.assertMatches(result,
     168            'class_name,document_id,history,state,title,user_id\r\n'
     169            'PCNCustomerJPGDocument,%s,'
     170            '[u\'2014-12-21 17:00:36 WAT - Document created by system\'],'
     171            'created,My second document,K1000000\r\n'
     172            % self.document2.document_id)
     173        # We can reimport the file if we change the header (user_id -> customer_id)
     174        processor = PCNCustomerJPGDocumentProcessor()
     175        open(self.outfile, 'wb').write(
     176            'customer_id,class_name,document_id,state,title\r\n'
     177            'K1000000,PCNCustomerJPGDocument,%s,started,My second title\r\n'
     178            % self.document2.document_id)
     179        result = processor.doImport(
     180            self.outfile,
     181            ['customer_id','class_name','document_id','state','title'],
     182            mode='create')
     183        num, num_fail, finished_path, failed_path = result
     184        # The object exists.
     185        self.assertEqual(num_fail,1)
     186        # We remove the original document.
     187        del self.customer['documents'][self.document2.document_id]
    138188        result = processor.doImport(
    139189            self.outfile,
    … …  
    219269        self.browser.open(self.customer_path + '/documents')
    220270        self.browser.getControl("Add document").click()
    221         self.browser.getControl(name="doctype").value = ['PCNCustomerDocument']
     271        self.browser.getControl(name="doctype").value = ['PCNCustomerPDFDocument']
    222272        self.browser.getControl(name="form.title").value = 'My PCN Document'
    223273        self.browser.getControl("Add document").click()
    … …  
    247297            name='upload_pdfscanmanageupload').click()
    248298        self.assertTrue(
    249             'href="http://localhost/app/customers/K1000000/documents/%s/sample.pdf">PDF File</a>'
     299            'href="http://localhost/app/customers/K1000000/documents/%s/scan.pdf">PDF File</a>'
    250300            % docid in self.browser.contents)
    251301        # Browsing the link shows a real pdf
    252         self.browser.open('sample.pdf')
     302        self.browser.open('scan.pdf')
    253303        self.assertEqual(
    254304            self.browser.headers['content-type'], 'application/pdf')
  • main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/tests/test_document.py

    r12371 r12384  
    2929
    3030from ikobacustom.pcn.testing import (FunctionalLayer, FunctionalTestCase)
    31 from ikobacustom.pcn.customers.documents import PCNCustomerDocument
    32 from ikobacustom.pcn.customers.interfaces import IPCNCustomerDocument
     31from ikobacustom.pcn.customers.documents import PCNCustomerPDFDocument
     32from ikobacustom.pcn.customers.interfaces import IPCNCustomerPDFDocument
    3333
    3434
    … …  
    3838
    3939    def test_interfaces(self):
    40         verify.verifyClass(IPCNCustomerDocument, PCNCustomerDocument)
    41         verify.verifyClass(ICustomerNavigation, PCNCustomerDocument)
    42         verify.verifyObject(IPCNCustomerDocument, PCNCustomerDocument())
    43         verify.verifyObject(ICustomerNavigation, PCNCustomerDocument())
     40        verify.verifyClass(IPCNCustomerPDFDocument, PCNCustomerPDFDocument)
     41        verify.verifyClass(ICustomerNavigation, PCNCustomerPDFDocument)
     42        verify.verifyObject(IPCNCustomerPDFDocument, PCNCustomerPDFDocument())
     43        verify.verifyObject(ICustomerNavigation, PCNCustomerPDFDocument())
    4444        return
    4545
    4646    def test_addDocument(self):
    4747        container = CustomerDocumentsContainer()
    48         document = createObject(u'waeup.PCNCustomerDocument')
     48        document = createObject(u'waeup.PCNCustomerPDFDocument')
    4949        id = document.document_id
    5050        container.addDocument(document)
    5151        self.assertEqual(container[id], document)
    5252        self.assertRaises(TypeError, container.addDocument, object())
    53         self.assertEqual(document.class_name, 'PCNCustomerDocument')
     53        self.assertEqual(document.class_name, 'PCNCustomerPDFDocument')
    5454        return
Note: See TracChangeset for help on using the changeset viewer.