mirror of
https://github.com/ae-utbm/sith.git
synced 2025-10-10 00:34:41 +00:00
fix: 500 on product create view
This commit is contained in:
@@ -6,14 +6,16 @@ import pytest
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.test import Client
|
||||
from django.test import Client, TestCase
|
||||
from django.urls import reverse
|
||||
from model_bakery import baker
|
||||
from PIL import Image
|
||||
from pytest_django.asserts import assertNumQueries
|
||||
from pytest_django.asserts import assertNumQueries, assertRedirects
|
||||
|
||||
from club.models import Club
|
||||
from core.baker_recipes import board_user, subscriber_user
|
||||
from core.models import Group, User
|
||||
from counter.forms import ProductForm
|
||||
from counter.models import Product, ProductType
|
||||
|
||||
|
||||
@@ -84,3 +86,51 @@ def test_fetch_product_nb_queries(client: Client):
|
||||
# - 1 for the actual request
|
||||
# - 1 to prefetch the related buying_groups
|
||||
client.get(reverse("api:search_products_detailed"))
|
||||
|
||||
|
||||
class TestCreateProduct(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.product_type = baker.make(ProductType)
|
||||
cls.club = baker.make(Club)
|
||||
cls.data = {
|
||||
"name": "foo",
|
||||
"description": "bar",
|
||||
"product_type": cls.product_type.id,
|
||||
"club": cls.club.id,
|
||||
"code": "FOO",
|
||||
"purchase_price": 1.0,
|
||||
"selling_price": 1.0,
|
||||
"special_selling_price": 1.0,
|
||||
"limit_age": 0,
|
||||
"form-TOTAL_FORMS": 0,
|
||||
"form-INITIAL_FORMS": 0,
|
||||
}
|
||||
|
||||
def test_form(self):
|
||||
form = ProductForm(data=self.data)
|
||||
print(form.errors)
|
||||
assert form.is_valid()
|
||||
instance = form.save()
|
||||
assert instance.club == self.club
|
||||
assert instance.product_type == self.product_type
|
||||
assert instance.name == "foo"
|
||||
assert instance.selling_price == 1.0
|
||||
|
||||
def test_view(self):
|
||||
self.client.force_login(
|
||||
baker.make(
|
||||
User,
|
||||
groups=[Group.objects.get(id=settings.SITH_GROUP_COUNTER_ADMIN_ID)],
|
||||
)
|
||||
)
|
||||
url = reverse("counter:new_product")
|
||||
response = self.client.get(url)
|
||||
assert response.status_code == 200
|
||||
response = self.client.post(url, data=self.data)
|
||||
print(response.text)
|
||||
assertRedirects(response, reverse("counter:product_list"))
|
||||
product = Product.objects.last()
|
||||
assert product.name == "foo"
|
||||
assert product.club == self.club
|
||||
assert product.product_type == self.product_type
|
||||
|
Reference in New Issue
Block a user