Ignore:
Timestamp:
4 Dec 2014, 12:22:03 (10 years ago)
Author:
Henrik Bettermann
Message:

Add contract exporter.

File:
1 edited

Legend:

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

    r12131 r12143  
    3131from waeup.ikoba.customers.catalog import CustomersQuery
    3232from waeup.ikoba.customers.export import (
    33     CustomerExporter, CustomerDocumentExporter, get_customers)
     33    CustomerExporter, CustomerDocumentExporter, ContractExporter,
     34    get_customers)
    3435from waeup.ikoba.customers.interfaces import ICSVCustomerExporter
    3536from waeup.ikoba.customers.customer import Customer
    3637from waeup.ikoba.customers.documents import CustomerSampleDocument
     38from waeup.ikoba.customers.contracts import SampleContract
    3739from waeup.ikoba.customers.tests.test_batching import CustomerImportExportSetup
    3840from waeup.ikoba.testing import FunctionalLayer
     
    8890        exporter.export([self.customer], self.outfile)
    8991        result = open(self.outfile, 'rb').read()
    90         self.assertTrue(
    91             'customer_id,email,firstname,lastname,middlename,phone,'
    92             'reg_number,sex,suspended,suspended_comment,password,state,'
    93             'history\r\n'
    94             'A111111,anna@sample.com,Anna,Tester,M.,+234-123-12345#,'
    95             '123,,0,,,created'
    96             in result
     92        self.assertMatches(
     93            'customer_id,email,firstname,lastname,middlename,phone,reg_number,'
     94            'sex,suspended,suspended_comment,password,state,history\r\n'
     95            'A111111,anna@sample.com,Anna,Tester,M.,+234-123-12345#,123,,0,,,'
     96            'created,[u\'2014-12-04 11:25:35 UTC - Customer record created '
     97            'by system\']\r\n',
     98            result
    9799            )
    98100        return
     
    202204        return
    203205
    204     def test_export_customer(self):
     206    def test_export_customer_document(self):
    205207        # we can really export all documents of a certain customer
    206208        # set values we can expect in export file
     
    219221            )
    220222        return
     223
     224
     225class ContractExporterTest(CustomerImportExportSetup):
     226
     227    layer = FunctionalLayer
     228
     229    def setUp(self):
     230        super(ContractExporterTest, self).setUp()
     231        self.setup_for_export()
     232        return
     233
     234    def test_ifaces(self):
     235        # make sure we fullfill interface contracts
     236        obj = ContractExporter()
     237        verifyObject(ICSVCustomerExporter, obj)
     238        verifyClass(ICSVCustomerExporter, ContractExporter)
     239        return
     240
     241    def test_get_as_utility(self):
     242        # we can get a contracts exporter as utility
     243        result = queryUtility(ICSVExporter, name="contracts")
     244        self.assertTrue(result is not None)
     245        return
     246
     247    def test_export_empty(self):
     248        # we can export a nearly empty contract
     249        contract = SampleContract()
     250        exporter = ContractExporter()
     251        exporter.export([contract], self.outfile)
     252        result = open(self.outfile, 'rb').read()
     253        self.assertEqual(
     254            result,
     255            'class_name,contract_category,contract_id,document_object,'
     256            'history,is_editable,last_product_id,last_transition_date,'
     257            'product_object,state,title\r\n'
     258
     259            'SampleContract,sample,c101,,[],1,,,,,\r\n'
     260            )
     261        return
     262
     263    def test_export(self):
     264        # we can really export customer contracts.
     265        # set values we can expect in export file
     266        self.setup_customer(self.customer)
     267        exporter = ContractExporter()
     268        exporter.export([self.contract], self.outfile)
     269        result = open(self.outfile, 'rb').read()
     270        self.assertMatches(
     271            'class_name,contract_category,contract_id,document_object,'
     272            'history,is_editable,last_product_id,last_transition_date,'
     273            'product_object,state,title\r\n'
     274
     275            'SampleContract,sample,c101,d101,[u\'2014-12-04 12:10:46 UTC - '
     276            'Contract record created by system\'],0,,'
     277            '2014-12-04 12:10:46.333445#,SAM,created,My Contract\r\n',
     278            result
     279            )
     280        return
     281
     282    def test_export_all(self):
     283        # we can really export all contracts
     284        # set values we can expect in export file
     285        self.setup_customer(self.customer)
     286        exporter = ContractExporter()
     287        exporter.export_all(self.app, self.outfile)
     288        result = open(self.outfile, 'rb').read()
     289        self.assertMatches(
     290            'class_name,contract_category,contract_id,document_object,'
     291            'history,is_editable,last_product_id,last_transition_date,'
     292            'product_object,state,title\r\n'
     293
     294            'SampleContract,sample,c101,d101,[u\'2014-12-04 12:10:46 UTC - '
     295            'Contract record created by system\'],0,,'
     296            '2014-12-04 12:10:46.333445#,SAM,created,My Contract\r\n',
     297            result
     298            )
     299        return
     300
     301    def test_export_contract(self):
     302        # we can really export all contracts of a certain customer
     303        # set values we can expect in export file
     304        self.setup_customer(self.customer)
     305        exporter = ContractExporter()
     306        exporter.export_customer(self.customer, self.outfile)
     307        result = open(self.outfile, 'rb').read()
     308        self.assertMatches(
     309            'class_name,contract_category,contract_id,document_object,'
     310            'history,is_editable,last_product_id,last_transition_date,'
     311            'product_object,state,title\r\n'
     312
     313            'SampleContract,sample,c101,d101,[u\'2014-12-04 12:10:46 UTC - '
     314            'Contract record created by system\'],0,,'
     315            '2014-12-04 12:10:46.333445#,SAM,created,My Contract\r\n',
     316            result
     317            )
     318        return
     319
Note: See TracChangeset for help on using the changeset viewer.