feat: added tests for cart views
This commit is contained in:
+13
-10
@@ -1,7 +1,10 @@
|
||||
from django.shortcuts import render
|
||||
from django.views.generic import TemplateView
|
||||
from shop.filters import ProductFilter
|
||||
from shop.models import Product
|
||||
from web.mixins import FilteredQuerysetMixin, PaginatedQuerysetMixin, CartMixin
|
||||
from shop.models import Product, Cart
|
||||
from web.mixins import FilteredQuerysetMixin, PaginatedQuerysetMixin
|
||||
from web.settings import ANONYMOUS_CART_ID_COOKIE_NAME
|
||||
from web.utils import get_or_create_cart
|
||||
|
||||
|
||||
class ListProducts(TemplateView, FilteredQuerysetMixin, PaginatedQuerysetMixin):
|
||||
@@ -20,16 +23,16 @@ class ListProducts(TemplateView, FilteredQuerysetMixin, PaginatedQuerysetMixin):
|
||||
}
|
||||
|
||||
|
||||
class CartDropdown(TemplateView, CartMixin):
|
||||
template_name = "components/cart/cart_navbar.html"
|
||||
def cart_dropdown(request, *args, **kwargs):
|
||||
cart, created = get_or_create_cart(request)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
cart = self.get_cart()
|
||||
response = render(request, "components/cart/cart_navbar.html", context={
|
||||
"cart": cart,
|
||||
})
|
||||
|
||||
return {
|
||||
"cart": cart,
|
||||
}
|
||||
if not request.user.is_authenticated:
|
||||
response.set_cookie(ANONYMOUS_CART_ID_COOKIE_NAME, cart.uuid)
|
||||
return response
|
||||
|
||||
|
||||
list_products = ListProducts.as_view()
|
||||
cart_dropdown = CartDropdown.as_view()
|
||||
|
||||
Reference in New Issue
Block a user