Ignore:
Timestamp:
11 Mar 2015, 22:44:17 (10 years ago)
Author:
uli
Message:

Implement payment related stuff for customers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/customers/tests/test_customer.py

    r12297 r12738  
    2424from cStringIO import StringIO
    2525from datetime import tzinfo
    26 from zope.component import getUtility, queryUtility, createObject
     26from zope.component import (
     27    getUtility, queryUtility, createObject, getUtilitiesFor,
     28    )
     29from zope.component.hooks import setSite
    2730from zope.catalog.interfaces import ICatalog
    2831from zope.component.interfaces import IFactory
     
    3134from zope.schema.interfaces import RequiredMissing
    3235from waeup.ikoba.interfaces import IExtFileStore, IFileStoreNameChooser
     36from waeup.ikoba.app import Company
    3337from waeup.ikoba.customers.customer import (
    34     Customer, CustomerFactory, handle_customer_removed, path_from_custid)
     38    Customer, CustomerFactory, handle_customer_removed, path_from_custid,
     39    CustomerPayer, CustomerFinder,
     40    )
    3541from waeup.ikoba.customers.interfaces import (
    3642    ICustomer, ICustomerNavigation, ICustomersUtils)
    3743from waeup.ikoba.customers.tests.test_batching import CustomerImportExportSetup
     44from waeup.ikoba.payments.interfaces import IPayer, IPayerFinder
    3845from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase
    3946
     
    9299
    93100
     101class TestCustomerHelpers(FunctionalTestCase):
     102
     103    layer = FunctionalLayer
     104
     105    def test_payer_adapter(self):
     106        # we can adapt ICustomer to IPayer (i.e. create a payer)
     107        customer = Customer()
     108        customer.firstname, customer.lastname = u'Anna', u'Tester'
     109        result = IPayer(customer)
     110        self.assertTrue(isinstance(result, CustomerPayer))
     111        verify.verifyObject(IPayer, result)
     112        self.assertEqual(result.first_name, u'Anna')
     113        self.assertEqual(result.last_name, u'Tester')
     114        self.assertEqual(result.payer_id, customer.customer_id)
     115
     116    def test_customer_finder_iface(self):
     117        # we have a customer finder that returns IPayableFinder data.
     118        verify.verifyClass(IPayerFinder, CustomerFinder)
     119
     120    def test_customer_finder_registered(self):
     121        # the customer finder is a utility registered on startup
     122        util = getUtility(IPayerFinder, name='customer_finder')
     123        self.assertTrue(isinstance(util, CustomerFinder))
     124        utils = [util for name, util in getUtilitiesFor(IPayerFinder)
     125                 if isinstance(util, CustomerFinder)]
     126        self.assertEqual(len(utils), 1)
     127
     128    def create_customer_and_site(self):
     129        customer = Customer()
     130        customer.customer_id = u'CUST1'
     131        self.getRootFolder()['app'] = Company()
     132        app = self.getRootFolder()['app']
     133        setSite(app)
     134        return customer, app
     135
     136    def test_customer_finder(self):
     137        # the customer finder can really find customers
     138        customer, app = self.create_customer_and_site()
     139        app['mycustomer'] = customer  # trigger cataloging
     140        finder = CustomerFinder()
     141        result = finder.get_payer_by_id('CUST1')
     142        self.assertTrue(result is customer)
     143
     144    def test_customer_finder_not_stored(self):
     145        # we get none if an id is not stored
     146        customer, app = self.create_customer_and_site()
     147        app['mycustomer'] = customer  # trigger cataloging
     148        finder = CustomerFinder()
     149        result = finder.get_payer_by_id('Not-a-valid-id')
     150        self.assertTrue(result is None)
     151
     152    def test_customer_finder_no_catalog(self):
     153        # customer finder does not complain about missing catalog
     154        finder = CustomerFinder()
     155        result = finder.get_payer_by_id('CUST1')
     156        self.assertTrue(result is None)
     157
     158
    94159class CustomerRemovalTests(CustomerImportExportSetup):
    95160    # Test handle_customer_removed
Note: See TracChangeset for help on using the changeset viewer.