Changeset 12007 for main


Ignore:
Timestamp:
20 Nov 2014, 09:10:54 (10 years ago)
Author:
Henrik Bettermann
Message:

Add customer document exporter tests.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/export.py

    r12006 r12007  
    157157        """Treat location values special.
    158158        """
     159        if name == 'history':
     160            value = value.messages
    159161        if context is not None:
    160162            customer = context.customer
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_export.py

    r11997 r12007  
    1010from waeup.ikoba.customers.catalog import CustomersQuery
    1111from waeup.ikoba.customers.export import (
    12     CustomersExporter, get_customers)
     12    CustomersExporter, CustomerDocumentsExporter, get_customers)
    1313from waeup.ikoba.customers.interfaces import ICSVCustomerExporter
    1414from waeup.ikoba.customers.customer import Customer
     15from waeup.ikoba.customers.documents import CustomerDocument
    1516from waeup.ikoba.customers.tests.test_batching import CustomerImportExportSetup
    1617from waeup.ikoba.testing import FunctionalLayer
     
    106107            )
    107108        return
     109
     110class CustomerDocumentsExporterTest(CustomerImportExportSetup):
     111
     112    layer = FunctionalLayer
     113
     114    def setUp(self):
     115        super(CustomerDocumentsExporterTest, self).setUp()
     116        self.setup_for_export()
     117        return
     118
     119    def test_ifaces(self):
     120        # make sure we fullfill interface contracts
     121        obj = CustomerDocumentsExporter()
     122        verifyObject(ICSVCustomerExporter, obj)
     123        verifyClass(ICSVCustomerExporter, CustomerDocumentsExporter)
     124        return
     125
     126    def test_get_as_utility(self):
     127        # we can get a documents exporter as utility
     128        result = queryUtility(ICSVExporter, name="customerdocuments")
     129        self.assertTrue(result is not None)
     130        return
     131
     132    def test_export_empty(self):
     133        # we can export a nearly empty document
     134        document = CustomerDocument()
     135        exporter = CustomerDocumentsExporter()
     136        exporter.export([document], self.outfile)
     137        result = open(self.outfile, 'rb').read()
     138        self.assertEqual(
     139            result,
     140            'doctype,document_id,history,title,customer_id\r\n'
     141            ',d101,[],,\r\n'
     142            )
     143        return
     144
     145    def test_export(self):
     146        # we can really export customer documents.
     147        # set values we can expect in export file
     148        self.setup_customer(self.customer)
     149        document = self.customer['documents']['d101']
     150        exporter = CustomerDocumentsExporter()
     151        exporter.export([document], self.outfile)
     152        result = open(self.outfile, 'rb').read()
     153        self.assertTrue(
     154            'doctype,document_id,history,title,customer_id\r\n'
     155            in result
     156            )
     157        self.assertTrue(
     158            'Document created by system\'],My Document,A111111\r\n'
     159            in result
     160            )
     161        return
     162
     163    def test_export_all(self):
     164        # we can really export all documents
     165        # set values we can expect in export file
     166        self.setup_customer(self.customer)
     167        exporter = CustomerDocumentsExporter()
     168        exporter.export_all(self.app, self.outfile)
     169        result = open(self.outfile, 'rb').read()
     170        self.assertTrue(
     171            'doctype,document_id,history,title,customer_id\r\n'
     172            in result)
     173        self.assertTrue(
     174            ' Document created by system\'],My Document,A111111\r\n'
     175            in result)
     176        return
     177
     178    def test_export_customer(self):
     179        # we can really export all documents of a certain customer
     180        # set values we can expect in export file
     181        self.setup_customer(self.customer)
     182        exporter = CustomerDocumentsExporter()
     183        exporter.export_customer(self.customer, self.outfile)
     184        result = open(self.outfile, 'rb').read()
     185        self.assertTrue(
     186            'doctype,document_id,history,title,customer_id\r\n'
     187            in result)
     188        self.assertTrue(
     189            ' Document created by system\'],My Document,A111111\r\n'
     190            in result)
     191        return
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/interfaces.py

    r12005 r12007  
    2323from waeup.ikoba.interfaces import MessageFactory as _
    2424
    25 class DocumentCategorySource(ContextualDictSourceFactoryBase):
     25class DocumentTypeSource(ContextualDictSourceFactoryBase):
    2626    """A document type source delivers all types of documents.
    2727
     
    4646    history = Attribute('Object history, a list of messages')
    4747
    48     category = schema.Choice(
    49         title = _(u'Document Category'),
    50         source = DocumentCategorySource(),
     48    doctype = schema.Choice(
     49        title = _(u'Document Type'),
     50        source = DocumentTypeSource(),
    5151        required = True,
    5252        )
Note: See TracChangeset for help on using the changeset viewer.