예제 #1
0
 def test_serial(self):
     """ Convert a payment to JSON"""
     payment = Payment(order_id="1",
                       customer_id="1",
                       available=True,
                       payments_type="credit card")
     payment_json = payment.serialize()
     self.assertEqual(payment_json['order_id'], "1")
     self.assertEqual(payment_json['customer_id'], "1")
     self.assertEqual(payment_json['available'], True)
     self.assertEqual(payment_json['payments_type'], "credit card")
예제 #2
0
 def test_serialize(self):
     """ Convert a payment to JSON """
     payment = Payment(
         order_id="1",
         customer_id="1",
         available=True,
         type="credit card",
         info=self._test_credit_card_info)
     payment_json = payment.serialize()
     self.assertEqual(payment_json['order_id'], "1")
     self.assertEqual(payment_json['customer_id'], "1")
     self.assertEqual(payment_json['available'], True)
     self.assertEqual(payment_json['type'], "credit card")
     self.assertEqual(payment_json['info'], self._test_credit_card_info)
예제 #3
0
def create_payments():
    """
    Creates a Payment
    This endpoint will create a Payment based the data in the body that is posted
    """
    app.logger.info('Request to create a payments')
    check_content_type('application/json')
    payment = Payment()
    payment.deserialize(request.get_json())
    payment.save()
    message = payment.serialize()
    location_url = url_for('get_payments', payments_id=payment.id, _external=True)
    return make_response(jsonify(message), status.HTTP_201_CREATED,
                         {
                             'Location': location_url
                         })
예제 #4
0
    def post(self):
        """Creates a payment.

        This endpoint will create a payment based on the data
        posted in the body.
        """
        app.logger.info('Request to Create a Payment')  # pylint: disable=no-member
        check_content_type('application/json')
        payment = Payment()
        app.logger.debug('Payload = %s', api.payload)  # pylint: disable=no-member
        data = api.payload
        # Still use jsonschema to validate data.
        jsonschema.validate(data, PAYMENT_SCHEMA)
        payment.deserialize(data)
        payment.save()
        app.logger.info('Payment with new id [%s] saved!', payment.id)  # pylint: disable=no-member
        location_url = api.url_for(PaymentResource,
                                   payment_id=payment.id,
                                   _external=True)
        return payment.serialize(), status.HTTP_201_CREATED, {
            'Location': location_url
        }