Пример #1
0
 def test_deserial(self):
     """ Convert a JSON to payment object"""
     data = {
         "order_id": "1",
         "customer_id": "1",
         "available": True,
         "payments_type": "credit card"
     }
     payment = Payment()
     payment.deserialize(data)
     self.assertEqual(data['order_id'], payment.order_id)
     self.assertEqual(data['customer_id'], payment.customer_id)
     self.assertEqual(data['available'], payment.available)
     self.assertEqual(data['payments_type'], payment.payments_type)
Пример #2
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
                         })
Пример #3
0
 def test_deserialize(self):
     """ Convert JSON to a payment object """
     data = {
         "order_id": "1",
         "customer_id": "1",
         "available": True,
         "type": "credit card",
         "info": DUMMY
     }
     payment = Payment()
     payment.deserialize(data)
     self.assertEqual(data['order_id'], payment.order_id)
     self.assertEqual(data['customer_id'], payment.customer_id)
     self.assertEqual(data['available'], payment.available)
     self.assertEqual(data['type'], payment.type)
     self.assertEqual(data['info'], payment.info)
Пример #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
        }