Pricing: clear message for non-numeric quantity (fixes #30); manual Chapter 12
Scrap-Web/pipeline/pr-main This commit looks good
Scrap-Web/pipeline/head This commit looks good

This commit is contained in:
2026-12-02 20:41:39 -05:00
parent 3cc6f3b0d4
commit 291c38bfd0
26 changed files with 551 additions and 6 deletions
+6 -3
View File
@@ -7,9 +7,12 @@ UNIT_PRICE = 12
COMMIT = os.environ.get("APP_COMMIT", "development")
QUANTITY_ERROR = "quantity must be a whole number between 1 and 1000"
def total_price(quantity):
if quantity < 1 or quantity > 1000:
raise ValueError("quantity must be between 1 and 1000")
raise ValueError(QUANTITY_ERROR)
return UNIT_PRICE * quantity
@@ -28,6 +31,6 @@ def price():
try:
quantity = int(request.args.get("quantity", "1"))
total = total_price(quantity)
except ValueError as error:
return jsonify(error=str(error)), 400
except ValueError:
return jsonify(error=QUANTITY_ERROR), 400
return jsonify(quantity=quantity, total=total, currency="USD")
+7
View File
@@ -16,6 +16,13 @@ class PricingTests(unittest.TestCase):
for value in ["0", "-1", "1001", "abc", "1.5"]:
self.assertEqual(self.client.get("/price?quantity=" + value).status_code, 400)
def test_non_numeric_quantity_message(self):
# Ticket#63003 / issue #30: no Python internals in the error
response = self.client.get("/price?quantity=abc")
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json["error"],
"quantity must be a whole number between 1 and 1000")
def test_release_identity(self):
self.assertEqual(self.client.get("/").json["version"], "v2")
self.assertEqual(self.client.get("/health").json["status"], "ok")