def test_search_payment_history_with_tz(session): """Assert that the search payment history is working.""" payment_account = factory_payment_account() payment_created_on = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) payment_created_on = payment_created_on.astimezone(pytz.utc) payment = factory_payment(payment_status_code='CREATED', created_on=payment_created_on) payment_account.save() payment.save() invoice = factory_invoice(payment, payment_account) invoice.save() factory_invoice_reference(invoice.id).save() auth_account_id = PaymentAccount.find_by_id(payment_account.account_id).auth_account_id results = Payment_service.search_purchase_history(auth_account_id=auth_account_id, search_filter={}, limit=1, page=1) assert results is not None assert results.get('items') is not None assert results.get('total') == 1 # Add one more payment payment_created_on = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) payment_created_on = payment_created_on.astimezone(pytz.utc) payment = factory_payment(payment_status_code='CREATED', created_on=payment_created_on) payment_account.save() payment.save() invoice = factory_invoice(payment, payment_account) invoice.save() factory_invoice_reference(invoice.id).save() results = Payment_service.search_purchase_history(auth_account_id=auth_account_id, search_filter={}, limit=1, page=1) assert results is not None assert results.get('items') is not None assert results.get('total') == 2
def test_search_payment_history(session): """Assert that the search payment history is working.""" payment_account = factory_payment_account() payment = factory_payment(payment_status_code='CREATED') payment_account.save() payment.save() invoice = factory_invoice(payment, payment_account) invoice.save() factory_invoice_reference(invoice.id).save() auth_account_id = PaymentAccount.find_by_id( payment_account.account_id).auth_account_id results = Payment_service.search_purchase_history( auth_account_id=auth_account_id, search_filter={}, limit=1, page=1) assert results is not None assert results.get('items') is not None assert results.get('total') == 1 # Add one more payment payment = factory_payment(payment_status_code='CREATED') payment_account.save() payment.save() invoice = factory_invoice(payment, payment_account) invoice.save() factory_invoice_reference(invoice.id).save() results = Payment_service.search_purchase_history( auth_account_id=auth_account_id, search_filter={}, limit=1, page=1) assert results is not None assert results.get('items') is not None assert results.get('total') == 2 # Search by different filter search_filter = {'status': 'CREATED'} results = Payment_service.search_purchase_history( auth_account_id=auth_account_id, search_filter=search_filter, limit=1, page=1) assert results is not None assert results.get('items') is not None assert results.get('total') == 2 # Search by different filter search_filter = {'status': 'COMPLETED'} results = Payment_service.search_purchase_history( auth_account_id=auth_account_id, search_filter=search_filter, limit=1, page=1) assert results is not None assert results.get('items') is not None assert results.get('total') == 0 # Search by different filter search_filter = {'folioNumber': '1234567890'} results = Payment_service.search_purchase_history( auth_account_id=auth_account_id, search_filter=search_filter, limit=1, page=1) assert results is not None assert results.get('items') is not None assert results.get('total') == 2 # Search by different filter search_filter = {'businessIdentifier': invoice.business_identifier} results = Payment_service.search_purchase_history( auth_account_id=auth_account_id, search_filter=search_filter, limit=1, page=1) assert results is not None assert results.get('items') is not None assert results.get('total') == 2 # Search by different filter search_filter = { 'dateFilter': { 'createdFrom': datetime.now().strftime('%m/%d/%Y'), 'createdTo': datetime.now().strftime('%m/%d/%Y') } } results = Payment_service.search_purchase_history( auth_account_id=auth_account_id, search_filter=search_filter, limit=1, page=1) assert results is not None assert results.get('items') is not None assert results.get('total') == 2 # Search by different filter search_filter = {'weekFilter': {'index': 2}} results = Payment_service.search_purchase_history( auth_account_id=auth_account_id, search_filter=search_filter, limit=1, page=1) assert results is not None assert results.get('items') is not None assert results.get('total') == 0 # Search by different filter search_filter = { 'monthFilter': { 'month': datetime.now().month, 'year': datetime.now().year } } results = Payment_service.search_purchase_history( auth_account_id=auth_account_id, search_filter=search_filter, limit=1, page=1) assert results is not None assert results.get('items') is not None assert results.get('total') == 2 # Search by different filter search_filter = {'createdBy': payment.created_name} results = Payment_service.search_purchase_history( auth_account_id=auth_account_id, search_filter=search_filter, limit=1, page=1) assert results is not None assert results.get('items') is not None assert results.get('total') == 2