jewelry_inventory/tests/test_app.py
2026-03-27 12:02:41 +05:00

64 lines
2.2 KiB
Python

import sys
import unittest
from pathlib import Path
PROJECT_DIR = Path(__file__).resolve().parent
sys.path.insert(0, str(PROJECT_DIR))
import app
class JewelryInventoryTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
app.init_db(force_reset=True)
cls.client = app.app.test_client()
def test_index_route(self):
response = self.client.get("/")
self.assertEqual(response.status_code, 200)
self.assertIn(b"\xd0\x97\xd0\xb0\xd1\x8f\xd0\xb2\xd0\xba\xd0\xb8", response.data)
def test_products_route(self):
response = self.client.get("/products")
self.assertEqual(response.status_code, 200)
self.assertIn(b"\xd0\xae\xd0\xb2\xd0\xb5\xd0\xbb\xd0\xb8\xd1\x80\xd0\xbd\xd1\x8b\xd0\xb5", response.data)
def test_partners_route(self):
response = self.client.get("/partners")
self.assertEqual(response.status_code, 200)
def test_metal_types_route(self):
response = self.client.get("/metal_types")
self.assertEqual(response.status_code, 200)
def test_product_price_calculation(self):
price = app.calculate_product_price(3500, 3.5, 585, 1.2)
self.assertAlmostEqual(price, 8600.70, places=2)
def test_partner_discount_calculation(self):
self.assertEqual(app.calculate_partner_discount(400000), 0)
self.assertEqual(app.calculate_partner_discount(600000), 5)
self.assertEqual(app.calculate_partner_discount(1200000), 10)
self.assertEqual(app.calculate_partner_discount(2500000), 15)
def test_product_create(self):
response = self.client.post(
"/products/add",
data={
"metal_type_id": "1",
"sku": "TEST-001",
"name": "Тестовое кольцо",
"weight_grams": "4.0",
"complexity_factor": "1.3",
"description": "Тестовое изделие",
},
follow_redirects=True,
)
self.assertEqual(response.status_code, 200)
self.assertIn(b"\xd0\xa2\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x80 \xd1\x81\xd0\xbe\xd0\xb7\xd0\xb4\xd0\xb0\xd0\xbd", response.data)
if __name__ == "__main__":
unittest.main()