comfy/artel/store/tests/test_views.py

99 wiersze
3.4 KiB
Python
Czysty Zwykły widok Historia

2023-07-20 15:49:12 +00:00
from django.test import TestCase
2023-07-22 16:53:18 +00:00
from django.shortcuts import reverse
from store.models import (
2023-08-15 11:36:11 +00:00
ProductTemplateParam,
ProductTemplateParamValue,
TemplateParamValueChoices
2023-07-22 16:53:18 +00:00
)
from store.tests.factories import (
ProductTemplateFactory,
ProductCategoryFactory,
ProductFactory,
2023-08-15 11:36:11 +00:00
ProductTemplateParamValueFactory
2023-07-22 16:53:18 +00:00
)
2023-07-20 15:49:12 +00:00
class ConfigureProductViewTestCase(TestCase):
def setUp(self):
2023-07-22 16:53:18 +00:00
super().setUp()
self.category = ProductCategoryFactory()
self.product_template = ProductTemplateFactory(category=self.category)
# create template params and values for those params
2023-08-15 11:36:11 +00:00
self.param1 = ProductTemplateParam.objects.create(
2023-08-15 19:00:16 +00:00
key="Mocowanie", template=self.product_template,
2023-08-15 11:36:11 +00:00
param_type=TemplateParamValueChoices.STRING
2023-07-22 16:53:18 +00:00
)
2023-08-15 11:36:11 +00:00
self.param1_value1 = ProductTemplateParamValueFactory(param=self.param1)
self.param1_value2 = ProductTemplateParamValueFactory(param=self.param1)
self.param2 = ProductTemplateParam.objects.create(
2023-08-15 19:00:16 +00:00
key="Format", template=self.product_template,
2023-08-15 11:36:11 +00:00
param_type=TemplateParamValueChoices.STRING
2023-07-22 16:53:18 +00:00
)
2023-08-15 11:36:11 +00:00
self.param2_value1 = ProductTemplateParamValueFactory(param=self.param2)
self.param2_value2 = ProductTemplateParamValueFactory(param=self.param2)
2023-07-22 16:53:18 +00:00
# create product variant
self.variant1 = ProductFactory(
template=self.product_template
)
self.variant1.params.set([self.param1_value1, self.param2_value1])
self.variant1.save()
self.variant2 = ProductFactory(
template=self.product_template,
)
self.variant2.params.set([self.param1_value2, self.param2_value2])
self.variant2.save()
def test_get_success(self):
response = self.client.get(
reverse("product-configure", args=[self.product_template.pk]),
)
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "store/configure_product.html")
def test_get_failure_wrong_pk(self):
response = self.client.get(
reverse("product-configure", args=[12312]),
)
self.assertEqual(response.status_code, 404)
def test_post_success(self):
data = {
self.param1.key: [str(self.param1_value1.pk)],
self.param2.key: [str(self.param2_value1.pk)]
}
response = self.client.post(
reverse("product-configure", args=[self.product_template.pk]),
data=data
)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, reverse("configure-product-summary", args=[self.variant1.pk]))
def test_post_failure_not_existing_template(self):
data = {
self.param1.key: [str(self.param1_value1.pk)],
self.param2.key: [str(self.param2_value1.pk)]
}
response = self.client.post(
reverse("product-configure", args=[2137]),
data=data
)
self.assertEqual(response.status_code, 404)
def test_post_not_existing_config(self):
data = {
self.param1.key: [str(self.param1_value2.pk)],
self.param2.key: [str(self.param2_value1.pk)]
}
response = self.client.post(
reverse("product-configure", args=[self.product_template.pk]),
data=data
)
self.assertEqual(response.status_code, 302)
2023-07-20 15:49:12 +00:00
2023-07-22 16:53:18 +00:00
class ConfigureProductSummaryViewTestCase(TestCase):
...