Ignore:
Timestamp:
9 Mar 2015, 04:45:52 (10 years ago)
Author:
uli
Message:

Add payment catalog lookup.

Location:
main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments
Files:
2 edited

Legend:

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

    r12696 r12700  
    2323import uuid
    2424from datetime import datetime
    25 from zope.component import getUtilitiesFor
     25from zope.catalog.interfaces import ICatalog
     26from zope.component import getUtilitiesFor, getUtility
    2627from zope.event import notify
    2728from waeup.ikoba.interfaces import MessageFactory as _
     
    3334    IPaymentGatewayServicesLister,
    3435    )
     36
     37
     38def get_payment(payment_id):
     39    """Get payment by payment id.
     40
     41    If no such payment can be found in catalog, return none.
     42    """
     43    cat = getUtility(ICatalog, name='payments_catalog')
     44    result_set = [x for x in cat.searchResults(
     45        payment_id = (payment_id, payment_id))]
     46    if len(result_set):
     47        return result_set[0]
     48    return None
    3549
    3650
  • main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/tests/test_payment.py

    r12696 r12700  
    2121import unittest
    2222from zope.component import getUtilitiesFor, getSiteManager, queryUtility
     23from zope.component.hooks import setSite
    2324from zope.interface import implements
    2425from zope.interface.verify import verifyClass, verifyObject
     
    2728    IPaymentGatewayService, IPaymentItem, IPaymentGatewayServicesLister,
    2829    )
     30from waeup.ikoba.app import Company
    2931from waeup.ikoba.payments.payment import (
    3032    Payment, get_payment_providers, PaymentItem, format_payment_item_values,
     33    get_payment,
    3134    )
    3235from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase)
     
    97100        assert len(util()) > 0
    98101
     102    def test_add_payment_item(self):
     103        # we can add payment items
     104        p1 = Payment()
     105        item1 = PaymentItem()
     106        result = p1.add_payment_item(item1)
     107        assert len(p1) == 1  # do not make assumptions about result content
     108        assert isinstance(result, basestring)
     109
     110    def test_get_payment(self):
     111        # we can lookup payments.
     112        self.getRootFolder()['app'] = Company()
     113        app = self.getRootFolder()['app']
     114        setSite(app)
     115        p1 = Payment()
     116        item1 = PaymentItem()
     117        app['payments']['1'] = p1
     118        p1.add_payment_item(item1)
     119        p_id = p1.payment_id
     120        result= get_payment(p_id)
     121        self.assertTrue(result is p1)
     122        self.assertTrue(get_payment('not-valid') is None)
     123
    99124
    100125class PaymentTests(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.