import logging
from django.test import TestCase, Client, RequestFactory
from django.urls import reverse
from django.conf import settings

from paypalcheckoutsdk.orders import OrdersCreateRequest, OrdersCaptureRequest
from paypalcheckoutsdk.core import PayPalHttpClient, SandboxEnvironment

from accounts.models import User, Address
from core.models import Product, Order

from .views import OrderCreateView
from .cart import Cart

logger = logging.getLogger(__name__)

class CartTest(TestCase):
    def setUp(self):
        self.client = Client()

        self.customer = User.objects.create_user(
            username='Peter Templer', email='peter@testing.com', password='peterspassword321'
        )
        self.product = Product.objects.create(
            name='Dante\'s Tornado',
            description='Coffee',
            sku='23987',
            price=13.4,
            weight=10,
            visible_in_listings=True
        )
        self.order = Order.objects.create(
            customer=self.customer,
            total_net_amount=13.4
        )

        self.client.force_login(self.customer)

    def test_post_checkout_form(self):
        url = reverse('storefront:order-create')
        response = self.client.get(url)
        self.assertTemplateUsed(response, 'storefront/order_form.html')

        request = response.wsgi_request
        cart = Cart(request)
        cart.add(
            product=self.product,
            quantity=1,
            update_quantity=False
        )
        logger.info(f'Body data:\n{body_data}\n')


        params = {
            'email': 'nathanchapman@hey.com',
            'first_name': 'Nathan',
            'last_name': 'Chapman',
            'total_net_amount': 26.80
        }

        response = self.client.post(url, params)
