import logging
from decimal import Decimal

from django.test import TestCase, Client, RequestFactory
from django.urls import reverse
from django.conf import settings
from measurement.measures import Weight
from paypalcheckoutsdk.orders import OrdersCreateRequest, OrdersCaptureRequest
from paypalcheckoutsdk.core import PayPalHttpClient, SandboxEnvironment

from accounts.models import User, Address
from core.models import Product, Order, Coupon
from core import CoffeeGrind
from dashboard.forms import (
    CouponForm,
    OrderLineFulfillForm,
    OrderTrackingForm,
    ProductPhotoForm,
)
from dashboard.views import (
    DashboardHomeView,
    DashboardConfigView,
    ShippingMethodCreateView,
    ShippingMethodDetailView,
    CouponListView,
    CouponCreateView,
    CouponDetailView,
    CouponUpdateView,
    CouponDeleteView,
    OrderListView,
    OrderDetailView,
    OrderFulfillView,
    OrderTrackingView,
    ProductListView,
    ProductDetailView,
    ProductUpdateView,
    ProductCreateView,
    ProductDeleteView,
    ProductPhotoCreateView,
    ProductPhotoDeleteView,
    CustomerListView,
    CustomerDetailView,
    CustomerUpdateView
)

logger = logging.getLogger(__name__)


class OrderCancelViewTests(TestCase):
    fixtures = [
        'accounts.json',
        'coupons.json',
        'products.json',
        'orders.json'
    ]

    @classmethod
    def setUpTestData(cls):
        cls.admin_user = User.objects.get(pk=1)

    def setUp(self):
        self.client = Client()
        self.client.force_login(self.admin_user)

    def test_view_url_exists_at_desired_location(self):
        response = self.client.get('/dashboard/orders/1/cancel/')
        self.assertEqual(response.status_code, 200)

    def test_view_url_accesible_by_name(self):
        response = self.client.get(
            reverse('dashboard:order-cancel', kwargs={'pk': 1})
        )
        self.assertEqual(response.status_code, 200)

    def test_view_uses_correct_template(self):
        response = self.client.get(
            reverse('dashboard:order-cancel', kwargs={'pk': 1})
        )
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'dashboard/order_cancel_form.html')
