Beispiel #1
0
    def test_delete_payment(self):
        payment = Payment()
        payment.merchant_name = "American Express"
        payment.account_number = "111-1111-1111"
        payment.expiration_date = "2024-12-31"
        payment.create_date = datetime.date.today()
        payment.customer_id = 1
        payment.save()

        self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token)
        response = self.client.delete(f"/paymenttypes/{payment.id}")
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        response = self.client.get(f"/paymenttypes/{payment.id}")
        self.assertEqual(response.status_code,
                         status.HTTP_500_INTERNAL_SERVER_ERROR)
    def create(self, request):
        """Handle POST operations

        Returns:
            Response -- JSON serialized payment instance
        """
        new_payment = Payment()
        new_payment.merchant_name = request.data["merchant_name"]
        new_payment.account_number = request.data["account_number"]
        new_payment.expiration_date = request.data["expiration_date"]
        new_payment.create_date = request.data["create_date"]
        customer = Customer.objects.get(user=request.auth.user)
        new_payment.customer = customer
        new_payment.save()

        serializer = PaymentSerializer(new_payment,
                                       context={'request': request})

        return Response(serializer.data, status=status.HTTP_201_CREATED)