feat: implement Fil-A-Management Django MVP

This commit is contained in:
Jean-Luc Picode committed 2026-11-14 10:39:49 +01:00
commit 1127e7ecf4
66 files changed
+3774

No files matched your search

+83
View File
@@ -0,0 +1,83 @@
import re
import tempfile
import unittest
from concurrent.futures import ThreadPoolExecutor
from .http_support import LiveServer, WebSession, prepare_database
class RealHTTPTests(unittest.TestCase):
def setUp(self):
self.directory = tempfile.TemporaryDirectory(prefix="fam-http-")
self.env, self.password, self.manage = prepare_database(self.directory.name)
self.server = LiveServer(self.env, self.directory.name)
self.server.start()
self.addCleanup(self.directory.cleanup)
self.addCleanup(self.server.stop)
self.alice = WebSession(self.server.url)
self.bob = WebSession(self.server.url)
self.alice.login("synthetic-one", self.password)
self.bob.login("synthetic-two", self.password)
def selection(self, quantity=1, spool="spool"):
# IDs are discovered from actual rendered forms, not guessed from seed ordering.
html = self.alice.get("/bestand/hinzufuegen/")[1]
manufacturer = re.search(r'<option value="(\d+)"', html).group(1)
html = self.alice.post(
"/bestand/hinzufuegen/", {"manufacturer": manufacturer, "action": "filter"}
)[1]
product = re.search(
r'<select name="product_type".*?<option value="(\d+)"', html, re.S
).group(1)
html = self.alice.post(
"/bestand/hinzufuegen/",
{"manufacturer": manufacturer, "product_type": product, "action": "filter"},
)[1]
color = re.search(r'<select name="color".*?<option value="(\d+)"', html, re.S).group(1)
return {
"manufacturer": manufacturer,
"product_type": product,
"color": color,
"spool_type": spool,
"quantity": quantity,
}
def test_two_accounts_privacy_shared_totals_static_and_server_restart(self):
payload = self.selection(2)
self.assertEqual(self.alice.post("/bestand/hinzufuegen/", payload)[0], 200)
self.alice.post("/bestand/hinzufuegen/", payload | {"quantity": 1})
html = self.alice.get("/bestand/")[1]
self.assertIn('class="quantity">3</td>', html)
edit_url = re.search(r'href="(/bestand/\d+/bearbeiten/)"', html).group(1)
self.assertEqual(self.bob.get(edit_url)[0], 404)
self.assertNotIn('class="quantity">3</td>', self.bob.get("/bestand/")[1])
self.alice.post("/bestellung/hinzufuegen/", payload)
self.bob.post("/bestellung/hinzufuegen/", payload | {"quantity": 1})
html = self.bob.get("/bestellung/")[1]
self.assertIn('class="quantity">3</td>', html)
self.assertIn("synthetic-one: <strong>2</strong>", html)
self.assertIn("synthetic-two: <strong>1</strong>", html)
css = re.search(r'href="(/static/[^"]+\.css)"', html).group(1)
self.assertEqual(self.alice.get(css)[0], 200)
self.assertIn("text/css", self.alice.get(css)[2]["Content-Type"])
self.server.stop()
self.server.start()
self.assertIn('class="quantity">3</td>', self.alice.get("/bestand/")[1])
self.assertIn('class="quantity">3</td>', self.bob.get("/bestellung/")[1])
print(
"HTTP: separate logins, private stock, 2+1 aggregation, CSS and Gunicorn restart verified."
)
def test_parallel_additions_do_not_lose_quantities(self):
payload = self.selection()
clients = [WebSession(self.server.url) for _ in range(6)]
for client in clients:
client.login("synthetic-one", self.password)
def add(client):
return client.post("/bestand/hinzufuegen/", payload)[0]
with ThreadPoolExecutor(max_workers=6) as pool:
self.assertEqual(list(pool.map(add, clients)), [200] * 6)
self.assertIn('class="quantity">6</td>', self.alice.get("/bestand/")[1])
print("HTTP: six simultaneous additions, one position, quantity six verified.")