CI demo: metrics + Gitea Actions
This commit is contained in:
36
tests/test_discounts.py
Normal file
36
tests/test_discounts.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from app.discounts import NoDiscount, discount_for
|
||||
from app.service import Order, OrderService
|
||||
|
||||
|
||||
def make_order() -> Order:
|
||||
return Order({"чай": 300, "кофе": 700})
|
||||
|
||||
|
||||
def test_vip_discount() -> None:
|
||||
service = OrderService(discount_for("vip"))
|
||||
assert service.total(make_order()) == pytest.approx(900.0)
|
||||
|
||||
|
||||
def test_employee_discount() -> None:
|
||||
service = OrderService(discount_for("employee"))
|
||||
assert service.total(make_order()) == pytest.approx(700.0)
|
||||
|
||||
|
||||
def test_regular_has_no_discount() -> None:
|
||||
service = OrderService(discount_for("regular"))
|
||||
assert service.total(make_order()) == pytest.approx(1000.0)
|
||||
|
||||
|
||||
def test_unknown_type_falls_back_to_regular() -> None:
|
||||
assert isinstance(discount_for("unknown"), NoDiscount)
|
||||
|
||||
|
||||
def test_python_version_supported() -> None:
|
||||
# Для акта с матрицей: на Python 3.11 этот тест падает
|
||||
assert sys.version_info >= (3, 12), (
|
||||
f"нужен Python 3.12+, получено {sys.version.split()[0]}"
|
||||
)
|
||||
25
tests/test_legacy_report.py
Normal file
25
tests/test_legacy_report.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import pytest
|
||||
|
||||
from app.legacy_report import classify_order
|
||||
|
||||
CASES = [
|
||||
(None, {}, "missing"),
|
||||
({}, {}, "no_total"),
|
||||
({"total": -1}, {}, "negative"),
|
||||
({"total": 0}, {}, "empty"),
|
||||
({"total": 200000}, {}, "huge"),
|
||||
({"total": 100}, {"maintenance": True}, "maintenance"),
|
||||
({"total": 100}, {"blocked": True}, "blocked"),
|
||||
({"total": 100, "region": "eu"}, {"regions": ["us"]}, "region"),
|
||||
({"total": 100, "coupon": "X"}, {"coupons": False}, "coupon"),
|
||||
({"total": 20000}, {"limit": 10000}, "limit"),
|
||||
({"total": 100, "fraud": True, "manual_review": True}, {}, "fraud_review"),
|
||||
({"total": 100, "fraud": True}, {}, "fraud"),
|
||||
({"total": 6000, "vip": True}, {}, "vip_review"),
|
||||
({"total": 100}, {}, "ok"),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("order,cfg,expected", CASES)
|
||||
def test_classify_order(order, cfg, expected):
|
||||
assert classify_order(order, cfg) == expected
|
||||
Reference in New Issue
Block a user