Changeset 12824 for main/waeup.ikoba/trunk/src/waeup/ikoba/payments
- Timestamp:
- 24 Mar 2015, 11:51:08 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba/payments
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/payments/catalog.py
r12823 r12824 19 19 """ 20 20 import grok 21 from hurry.query import Eq22 from hurry.query.query import Query23 21 from zope.catalog.interfaces import ICatalog 24 22 from zope.component import queryUtility … … 30 28 """Search payments catalog. 31 29 32 `query` gives a string we search, `searchtype` the fieldname. 30 `query` gives a string we search for, `searchtype` the fieldname. 31 32 Query '*' returns all entries stored. 33 34 Fields containing strings are searched in a 35 'startswith'-manner. That means, we find all entries starting with 36 the given query string. 37 38 For other fields we only return exact matches. For instance for 39 `anount`, we require a decimal number (no string) and will find 40 all payments with that very amount given in `query`. 41 42 Returns a (possibly empty) catalog result set. 33 43 """ 34 44 # Temporary solution to display all payments added 45 cat = queryUtility(ICatalog, name='payments_catalog') 35 46 if query == '*': 36 cat = queryUtility(ICatalog, name='payments_catalog') 37 results = cat.searchResults(payment_id=(None, None)) 47 searchtype, query, upper_bound = 'payment_id', None, None 38 48 else: 39 results = Query().searchResults( 40 Eq(('payments_catalog', searchtype), query)) 49 if searchtype.endswith('_id'): 50 upper_bound = query + ('Z' * 48) 51 else: 52 upper_bound = query 53 search_params = {searchtype: (query, upper_bound)} 54 results = cat.searchResults(**search_params) 41 55 return results 42 56 -
main/waeup.ikoba/trunk/src/waeup/ikoba/payments/tests/test_catalog.py
r12822 r12824 1 import decimal 1 2 from zope.catalog.interfaces import ICatalog 2 3 from zope.component import queryUtility 3 4 from zope.component.hooks import setSite 4 5 from waeup.ikoba.app import Company 5 from waeup.ikoba.payments.payment import Payment 6 from waeup.ikoba.payments.payment import Payment, PaymentItem 6 7 from waeup.ikoba.payments.testing import FakePayer, FakePayable 7 8 from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase … … 45 46 result = [x for x in result] 46 47 self.assertEqual(len(result), 1) 48 49 def test_search_payer_id_starts_with_query(self): 50 # we can find payer_ids starting with query string. 51 app = self.create_app() 52 payer1, payer2, payer3 = FakePayer(), FakePayer(), FakePayer() 53 payer1.payer_id = u'PAYER_11' 54 payer2.payer_id = u'PAYER_12' 55 payer3.payer_id = u'PAYER_20' 56 payment1 = Payment(payer=payer1, payable=FakePayable()) 57 payment2 = Payment(payer=payer2, payable=FakePayable()) 58 payment3 = Payment(payer=payer3, payable=FakePayable()) 59 app['p1'], app['p2'], app['p3'] = payment1, payment2, payment3 60 result1 = search(query='PAYER_1', searchtype='payer_id') 61 result1 = [x for x in result1] 62 self.assertEqual(len(result1), 2) 63 result2 = search(query='PAYER_2', searchtype='payer_id') 64 result2 = [x for x in result2] 65 self.assertEqual(len(result2), 1) 66 result3 = search(query='PAYER_3', searchtype='payer_id') 67 result3 = [x for x in result3] 68 self.assertEqual(len(result3), 0) 69 result4 = search(query='PAYER_11', searchtype='payer_id') 70 result4 = [x for x in result4] 71 self.assertEqual(len(result4), 1) 72 73 def test_search_amount(self): 74 # we can find given amounts starting with query string. 75 app = self.create_app() 76 payable1, payable2 = FakePayable(), FakePayable() 77 payable1.payment_items = ( 78 PaymentItem(u'Item 1', decimal.Decimal("1.0")), ) 79 payable2.payment_items = ( 80 PaymentItem(u'Item 2', decimal.Decimal("2.0")), ) 81 payment1 = Payment(payer=FakePayer(), payable=payable1) 82 payment2 = Payment(payer=FakePayer(), payable=payable2) 83 app['p1'], app['p2'] = payment1, payment2 84 result1 = search(query=decimal.Decimal("1.00"), searchtype='amount') 85 result1 = [x for x in result1] 86 self.assertEqual(len(result1), 1) 87 result2 = search(query=decimal.Decimal("2.00"), searchtype='amount') 88 result2 = [x for x in result2] 89 self.assertEqual(len(result2), 1) 90 result3 = search(query=decimal.Decimal("3.00"), searchtype='amount') 91 result3 = [x for x in result3] 92 self.assertEqual(len(result3), 0)
Note: See TracChangeset for help on using the changeset viewer.