feat: ruff'ed
This commit is contained in:
+20
-47
@@ -10,22 +10,20 @@ from web.settings import ANONYMOUS_CART_ID_COOKIE_NAME
|
||||
class TestCart(TestCase, CreateProductsMixin):
|
||||
def setUp(self):
|
||||
self.product = self.create_product()
|
||||
self.user = User.objects.create_user("vader", "darth@vader.com", "ihatesand")
|
||||
self.user = User.objects.create_user('vader', 'darth@vader.com', 'ihatesand')
|
||||
|
||||
def test_anonymous_cart(self):
|
||||
assert Cart.objects.count() == 0
|
||||
response = self.client.get(reverse("web:cart_dropdown"))
|
||||
response = self.client.get(reverse('web:cart_dropdown'))
|
||||
assert response.status_code == 200
|
||||
cart = Cart.objects.all().first()
|
||||
assert cart is not None
|
||||
assert response.cookies.get(ANONYMOUS_CART_ID_COOKIE_NAME).value == str(
|
||||
cart.uuid
|
||||
)
|
||||
assert response.cookies.get(ANONYMOUS_CART_ID_COOKIE_NAME).value == str(cart.uuid)
|
||||
|
||||
def test_logged_user_without_cart(self):
|
||||
assert Cart.objects.count() == 0
|
||||
self.client.force_login(self.user)
|
||||
response = self.client.get(reverse("web:cart_dropdown"))
|
||||
response = self.client.get(reverse('web:cart_dropdown'))
|
||||
assert response.status_code == 200
|
||||
assert Cart.objects.count() == 1
|
||||
assert not response.cookies.get(ANONYMOUS_CART_ID_COOKIE_NAME)
|
||||
@@ -33,7 +31,7 @@ class TestCart(TestCase, CreateProductsMixin):
|
||||
def test_logged_user_with_cart(self):
|
||||
Cart.objects.create(user=self.user)
|
||||
self.client.force_login(self.user)
|
||||
response = self.client.get(reverse("web:cart_dropdown"))
|
||||
response = self.client.get(reverse('web:cart_dropdown'))
|
||||
assert response.status_code == 200
|
||||
assert not response.cookies.get(ANONYMOUS_CART_ID_COOKIE_NAME)
|
||||
|
||||
@@ -41,17 +39,12 @@ class TestCart(TestCase, CreateProductsMixin):
|
||||
quantity = 2
|
||||
assert Cart.objects.count() == 0
|
||||
|
||||
response = self.client.post(
|
||||
reverse("web:add_cart_item"),
|
||||
{"product": self.product.pk, "quantity": quantity},
|
||||
)
|
||||
response = self.client.post(reverse('web:add_cart_item'), {'product': self.product.pk, 'quantity': quantity})
|
||||
assert response.status_code == 201
|
||||
|
||||
cart = Cart.objects.all().first()
|
||||
assert cart is not None
|
||||
assert response.cookies.get(ANONYMOUS_CART_ID_COOKIE_NAME).value == str(
|
||||
cart.uuid
|
||||
)
|
||||
assert response.cookies.get(ANONYMOUS_CART_ID_COOKIE_NAME).value == str(cart.uuid)
|
||||
|
||||
cart_item = CartItem.objects.filter(cart=cart).first()
|
||||
assert cart_item is not None
|
||||
@@ -63,10 +56,7 @@ class TestCart(TestCase, CreateProductsMixin):
|
||||
assert Cart.objects.count() == 0
|
||||
self.client.force_login(self.user)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("web:add_cart_item"),
|
||||
{"product": self.product.pk, "quantity": quantity},
|
||||
)
|
||||
response = self.client.post(reverse('web:add_cart_item'), {'product': self.product.pk, 'quantity': quantity})
|
||||
assert response.status_code == 201
|
||||
|
||||
cart = Cart.objects.all().first()
|
||||
@@ -83,10 +73,7 @@ class TestCart(TestCase, CreateProductsMixin):
|
||||
Cart.objects.create(user=self.user)
|
||||
self.client.force_login(self.user)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("web:add_cart_item"),
|
||||
{"product": self.product.pk, "quantity": quantity},
|
||||
)
|
||||
response = self.client.post(reverse('web:add_cart_item'), {'product': self.product.pk, 'quantity': quantity})
|
||||
assert response.status_code == 201
|
||||
|
||||
cart = Cart.objects.all().first()
|
||||
@@ -103,16 +90,10 @@ class TestCart(TestCase, CreateProductsMixin):
|
||||
Cart.objects.create(user=self.user)
|
||||
self.client.force_login(self.user)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("web:add_cart_item"),
|
||||
{"product": self.product.pk, "quantity": quantity},
|
||||
)
|
||||
response = self.client.post(reverse('web:add_cart_item'), {'product': self.product.pk, 'quantity': quantity})
|
||||
assert response.status_code == 201
|
||||
|
||||
response = self.client.post(
|
||||
reverse("web:add_cart_item"),
|
||||
{"product": self.product.pk, "quantity": quantity},
|
||||
)
|
||||
response = self.client.post(reverse('web:add_cart_item'), {'product': self.product.pk, 'quantity': quantity})
|
||||
assert response.status_code == 201
|
||||
|
||||
cart = Cart.objects.all().first()
|
||||
@@ -129,17 +110,12 @@ class TestCart(TestCase, CreateProductsMixin):
|
||||
quantity = 2
|
||||
assert Cart.objects.count() == 0
|
||||
|
||||
response = self.client.post(
|
||||
reverse("web:add_cart_item"),
|
||||
{"product": self.product.pk, "quantity": quantity},
|
||||
)
|
||||
response = self.client.post(reverse('web:add_cart_item'), {'product': self.product.pk, 'quantity': quantity})
|
||||
assert response.status_code == 201
|
||||
|
||||
cart = Cart.objects.all().first()
|
||||
assert cart is not None
|
||||
assert response.cookies.get(ANONYMOUS_CART_ID_COOKIE_NAME).value == str(
|
||||
cart.uuid
|
||||
)
|
||||
assert response.cookies.get(ANONYMOUS_CART_ID_COOKIE_NAME).value == str(cart.uuid)
|
||||
|
||||
cart_item = CartItem.objects.filter(cart=cart).first()
|
||||
assert cart_item is not None
|
||||
@@ -147,8 +123,8 @@ class TestCart(TestCase, CreateProductsMixin):
|
||||
assert cart_item.quantity == quantity
|
||||
|
||||
response = self.client.post(
|
||||
reverse("web:delete_cart_item", kwargs={"pk": cart_item.pk}),
|
||||
{"product": self.product.pk, "quantity": quantity},
|
||||
reverse('web:delete_cart_item', kwargs={'pk': cart_item.pk}),
|
||||
{'product': self.product.pk, 'quantity': quantity},
|
||||
)
|
||||
assert response.status_code == 204
|
||||
assert CartItem.objects.filter(cart=cart).count() == 0
|
||||
@@ -158,10 +134,7 @@ class TestCart(TestCase, CreateProductsMixin):
|
||||
assert Cart.objects.count() == 0
|
||||
|
||||
self.client.force_login(self.user)
|
||||
response = self.client.post(
|
||||
reverse("web:add_cart_item"),
|
||||
{"product": self.product.pk, "quantity": quantity},
|
||||
)
|
||||
response = self.client.post(reverse('web:add_cart_item'), {'product': self.product.pk, 'quantity': quantity})
|
||||
assert response.status_code == 201
|
||||
|
||||
cart = Cart.objects.all().first()
|
||||
@@ -174,15 +147,15 @@ class TestCart(TestCase, CreateProductsMixin):
|
||||
assert cart_item.quantity == quantity
|
||||
|
||||
response = self.client.post(
|
||||
reverse("web:delete_cart_item", kwargs={"pk": cart_item.pk}),
|
||||
{"product": self.product.pk, "quantity": quantity},
|
||||
reverse('web:delete_cart_item', kwargs={'pk': cart_item.pk}),
|
||||
{'product': self.product.pk, 'quantity': quantity},
|
||||
)
|
||||
assert response.status_code == 204
|
||||
assert CartItem.objects.filter(cart=cart).count() == 0
|
||||
|
||||
def test_anonymous_cart_detail_component(self):
|
||||
assert Cart.objects.count() == 0
|
||||
response = self.client.get(reverse("web:cart"))
|
||||
response = self.client.get(reverse('web:cart'))
|
||||
assert response.status_code == 200
|
||||
|
||||
assert Cart.objects.count() == 1
|
||||
@@ -191,5 +164,5 @@ class TestCart(TestCase, CreateProductsMixin):
|
||||
cart = Cart.objects.create(user=self.user)
|
||||
CartItem.objects.create(cart=cart, product=self.product, quantity=1)
|
||||
self.client.force_login(self.user)
|
||||
response = self.client.get(reverse("web:cart"))
|
||||
response = self.client.get(reverse('web:cart'))
|
||||
assert response.status_code == 200
|
||||
|
||||
Reference in New Issue
Block a user