130 lines
4.8 KiB
Python
130 lines
4.8 KiB
Python
import unittest
|
||
|
||
from app.belki.domain import (
|
||
CoachingSession,
|
||
InspectionReport,
|
||
TrainingSession,
|
||
calculate_coaching,
|
||
calculate_inspection,
|
||
calculate_training,
|
||
format_clock,
|
||
parse_clock,
|
||
)
|
||
from app.belki.reports import render_coaching, render_inspection, render_training
|
||
|
||
|
||
class ClockTests(unittest.TestCase):
|
||
def test_duration_supports_midnight(self):
|
||
self.assertEqual(parse_clock("23:55"), 23 * 60 + 55)
|
||
self.assertEqual(format_clock(parse_clock("23:05")), "23:05")
|
||
self.assertEqual(
|
||
CoachingSession.duration_minutes("23:55", "00:10"),
|
||
15,
|
||
)
|
||
|
||
def test_invalid_clock_is_rejected(self):
|
||
with self.assertRaises(ValueError):
|
||
parse_clock("5:5")
|
||
|
||
|
||
class CalculationTests(unittest.TestCase):
|
||
def test_self_sufficient_kitten(self):
|
||
result = calculate_coaching(
|
||
CoachingSession(
|
||
date="15.08",
|
||
skill="ЛУ",
|
||
start="00:52",
|
||
end="01:52",
|
||
escort_name="Дикая Вишня",
|
||
escort_id=1604614,
|
||
kitten_name="Котёнок",
|
||
kitten_id=1676767,
|
||
kitten_independence="самостоятельно",
|
||
)
|
||
)
|
||
self.assertEqual(result.minutes, 60)
|
||
self.assertEqual(result.escort_points, 12)
|
||
self.assertEqual(result.kitten_points, 24)
|
||
|
||
def test_non_self_kitten_and_extra_companion(self):
|
||
result = calculate_coaching(
|
||
CoachingSession(
|
||
date="15.08",
|
||
skill="ЗУ",
|
||
start="11:00",
|
||
end="12:00",
|
||
escort_name="Белка",
|
||
escort_id=1,
|
||
kitten_name="Первый",
|
||
kitten_id=2,
|
||
kitten_independence="несамостоятельно",
|
||
extra_kittens=(
|
||
("Второй", 3, "несамостоятельно"),
|
||
("Третий", 4, "самостоятельно"),
|
||
),
|
||
)
|
||
)
|
||
self.assertEqual(result.escort_points, 24)
|
||
self.assertEqual(result.kitten_points, 24)
|
||
|
||
def test_training_is_fixed(self):
|
||
self.assertEqual(calculate_training(TrainingSession("Белка", 1, "Котёнок", 2)).points, 25)
|
||
|
||
|
||
class ReportTests(unittest.TestCase):
|
||
def test_coaching_report_contains_new_fields_without_screenshot_placeholder(self):
|
||
session = CoachingSession(
|
||
date="15.08",
|
||
skill="ЛУ",
|
||
start="11:00",
|
||
end="11:20",
|
||
escort_name="Дикая Вишня",
|
||
escort_id=1604614,
|
||
kitten_name="Серолап",
|
||
kitten_id=1617140,
|
||
kitten_independence="несамостоятельно",
|
||
)
|
||
text = render_coaching(session, calculate_coaching(session))
|
||
self.assertIn("#лазание", text)
|
||
self.assertIn("Дикая Вишня [1604614], помог(-ла) Серолап [1617140] прокачать ЛУ.", text)
|
||
self.assertIn("Время: 11:00 – 11:20 [20 минут].", text)
|
||
self.assertIn("Баллы белки: 6 баллы.", text)
|
||
self.assertIn("Баллы бельчонка: 8 баллы.", text)
|
||
self.assertNotIn("Скриншот", text)
|
||
self.assertNotIn("истории", text)
|
||
|
||
def test_training_report_is_separate(self):
|
||
text = render_training(TrainingSession("Белка", 1, "Котёнок", 2))
|
||
self.assertIn("#урок", text)
|
||
self.assertIn("провел(-ла) урок", text)
|
||
|
||
def test_inspection_report_lists_zero_and_resources(self):
|
||
text = render_inspection(
|
||
InspectionReport(
|
||
character_name="Дикая Вишня",
|
||
character_id=1604614,
|
||
place="дупло",
|
||
inspections=6,
|
||
resources=(("вьюнок", -2), ("паук", 1)),
|
||
)
|
||
)
|
||
self.assertIn("осмотрел(-а) дупло 6 раз", text)
|
||
self.assertIn("#осмотр", text)
|
||
self.assertIn("-2 вьюнок.", text)
|
||
self.assertIn("+1 паук.", text)
|
||
self.assertNotIn("Скриншот", text)
|
||
self.assertIn("Баллы осмотра: 17 баллы.", text)
|
||
|
||
def test_inspection_points_include_attempts_and_resource_values(self):
|
||
report = InspectionReport(
|
||
character_name="Дикая Вишня", character_id=1604614,
|
||
place="дупло", inspections=2,
|
||
resources=(("паутина", 1), ("надпись", 1)),
|
||
)
|
||
self.assertEqual(calculate_inspection(report).points, 11)
|
||
self.assertIn("Баллы осмотра: 11 баллы.", render_inspection(report))
|
||
|
||
|
||
if __name__ == "__main__":
|
||
unittest.main()
|