Ignore:
Timestamp:
10 Mar 2015, 16:01:59 (10 years ago)
Author:
uli
Message:

Test payable finder.

File:
1 edited

Legend:

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

    r12700 r12719  
    2020import re
    2121import unittest
    22 from zope.component import getUtilitiesFor, getSiteManager, queryUtility
     22from zope.component import (
     23    getUtilitiesFor, getSiteManager, queryUtility, getGlobalSiteManager,
     24    )
    2325from zope.component.hooks import setSite
    2426from zope.interface import implements
     
    2729    IPayment, STATE_UNPAID, STATE_PAID, STATE_FAILED,
    2830    IPaymentGatewayService, IPaymentItem, IPaymentGatewayServicesLister,
     31    IPayableFinder,
    2932    )
    3033from waeup.ikoba.app import Company
    3134from waeup.ikoba.payments.payment import (
    3235    Payment, get_payment_providers, PaymentItem, format_payment_item_values,
    33     get_payment,
     36    get_payment, find_payable_from_payable_id,
    3437    )
    3538from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase)
     
    118121        p1.add_payment_item(item1)
    119122        p_id = p1.payment_id
    120         result= get_payment(p_id)
     123        result = get_payment(p_id)
    121124        self.assertTrue(result is p1)
    122125        self.assertTrue(get_payment('not-valid') is None)
     126
     127    def test_find_payable_from_payable_id(self):
     128        # we can find payables.
     129        obj1 = object()
     130        obj2 = object()
     131
     132        class FakeFinder(object):
     133            valid = {'id1': obj1, 'id3': obj2}
     134
     135            def get_payable_by_id(self, the_id):
     136                return self.valid.get(the_id)
     137
     138        finder1 = FakeFinder()
     139        finder1.valid = {'id1': obj1}
     140        finder2 = FakeFinder()
     141        finder2.valid = {'id2': obj2}
     142        gsm = getGlobalSiteManager()
     143        try:
     144            gsm.registerUtility(finder1, provided=IPayableFinder, name='f1')
     145            gsm.registerUtility(finder2, provided=IPayableFinder, name='f2')
     146            result1 = find_payable_from_payable_id('id1')
     147            result2 = find_payable_from_payable_id('id2')
     148            result3 = find_payable_from_payable_id('id3')
     149        finally:
     150            gsm.unregisterUtility(finder1, IPayableFinder)
     151            gsm.unregisterUtility(finder2, IPayableFinder)
     152        self.assertTrue(result1 is obj1)
     153        self.assertTrue(result2 is obj2)
     154        self.assertTrue(result3 is None)
    123155
    124156
Note: See TracChangeset for help on using the changeset viewer.