示例#1
0
 def test_find_by_customer(self):
     """ Find Payments by customer id """
     self._add_two_test_payments()
     payments = Payment.find_by_customer(1)
     self.assertIsNot(payments, None)
     self._assert_equal_test_payment_1(payments[0])
     payments = Payment.find_by_customer(2)
     self.assertIsNot(payments, None)
     self._assert_equal_test_payment_2(payments[0])
示例#2
0
 def test_find_by_customer(self):
     """ Find Payments by customer id"""
     Payment(order_id="1",
             customer_id="2",
             available=True,
             payments_type="credit card").save()
     Payment(order_id="3",
             customer_id="4",
             available=False,
             payments_type="paypal").save()
     payment_in_db = Payment.find_by_customer(2)
     self.assertIsNot(payment_in_db, None)
     self.assertEqual(payment_in_db[0].order_id, 1)
     self.assertEqual(payment_in_db[0].customer_id, 2)
     self.assertEqual(payment_in_db[0].available, True)
     self.assertEqual(payment_in_db[0].payments_type, "credit card")
     payment_in_db = Payment.find_by_customer(4)
     self.assertIsNot(payment_in_db, None)
     self.assertEqual(payment_in_db[0].order_id, 3)
     self.assertEqual(payment_in_db[0].customer_id, 4)
     self.assertEqual(payment_in_db[0].available, False)
     self.assertEqual(payment_in_db[0].payments_type, "paypal")
示例#3
0
def list_payments():
    """ Returns all of the Payments """
    app.logger.info('Request for payments list')
    payments = []
    customer_id = request.args.get('customer_id')
    order_id = request.args.get('order_id')
    if customer_id:
        app.logger.info('Request for payments list with customer_id : %s', customer_id)
        payments = Payment.find_by_customer(customer_id)
    elif order_id:
        app.logger.info('Request for payments list with order_id : %s', order_id)
        payments = Payment.find_by_order(order_id)
    else:
        payments = Payment.all()

    results = [payment.serialize() for payment in payments]
    return make_response(jsonify(results), status.HTTP_200_OK)