Ignore:
Timestamp:
10 Mar 2015, 14:59:34 (10 years ago)
Author:
uli
Message:

Introduce contract finder.

File:
1 edited

Legend:

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

    r12697 r12716  
    2121import decimal
    2222from zope.interface.verify import verifyClass, verifyObject
    23 from zope.component import createObject
     23from zope.component import createObject, getUtility, getUtilitiesFor
     24from zope.component.hooks import setSite
    2425from hurry.workflow.interfaces import (
    2526    IWorkflowInfo, IWorkflowState, InvalidTransitionError)
     
    2829from waeup.ikoba.customers.contracts import (
    2930    ContractsContainer, SampleContract, payment_items_from_contract,
    30     ContractPayer,
     31    ContractPayer, ContractFinder
    3132    )
     33from waeup.ikoba.app import Company
    3234from waeup.ikoba.customers.customer import Customer
    33 from waeup.ikoba.payments.interfaces import IPaymentItem, IPayer
     35from waeup.ikoba.payments.interfaces import (
     36    IPaymentItem, IPayer, IPayableFinder,
     37    )
    3438from waeup.ikoba.products.productoptions import ProductOption
    3539from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase)
     
    138142        self.assertEqual(result.last_name, u'Tester')
    139143        self.assertEqual(result.payer_id, customer.customer_id)
     144
     145    def test_contract_finder_iface(self):
     146        # we have a contract finder that returns IPayableFinder data.
     147        verifyClass(IPayableFinder, ContractFinder)
     148
     149    def test_contract_finder_registered(self):
     150        # the contract finder is a utility registered on startup
     151        util = getUtility(IPayableFinder, name='contracts_finder')
     152        self.assertTrue(isinstance(util, ContractFinder))
     153        utils = [util for name, util in getUtilitiesFor(IPayableFinder)
     154                 if isinstance(util, ContractFinder)]
     155        self.assertEqual(len(utils), 1)
     156
     157    def create_contract_and_site(self):
     158        contract = SampleContract()
     159        option1 = ProductOption(u"Fee 1", decimal.Decimal("31.10"), "USD")
     160        option2 = ProductOption(u"Fee 2", decimal.Decimal("12.12"), "USD")
     161        contract.product_options = [option1, option2]
     162        contract.contract_id = u'CON1234'
     163        self.getRootFolder()['app'] = Company()
     164        app = self.getRootFolder()['app']
     165        setSite(app)
     166        return contract, app
     167
     168    def test_contract_finder(self):
     169        # the contract finder can really find contracts
     170        contract, app = self.create_contract_and_site()
     171        app['mycontract'] = contract  # trigger cataloging
     172        finder = ContractFinder()
     173        result = finder.get_item_by_id('CON1234')
     174        self.assertTrue(result is contract)
     175
     176    def test_contract_finder_not_stored(self):
     177        # we get none if an id is not stored
     178        contract, app = self.create_contract_and_site()
     179        app['mycontract'] = contract  # trigger cataloging
     180        finder = ContractFinder()
     181        result = finder.get_item_by_id('Not-a-valid-id')
     182        self.assertTrue(result is None)
Note: See TracChangeset for help on using the changeset viewer.