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

Add customer document exporter tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.