Admin fixes

This commit is contained in:
nyan404 committed 2026-08-16 21:03:25 +03:00
1 parent 6db39f0d51
commit a7f6fc0fc8
18 files changed
+285 -59

No files matched your search

+2 -2
View File
@@ -37,11 +37,11 @@ class ApiTests(unittest.TestCase):
"character_id": 1604614,
"place": "дупло",
"inspections": 6,
"resources": [["вьюнок", -2], ["паук", 1]],
"resources": [["вьюнок", 2], ["паук", 1]],
}
)
self.assertIn("осмотрел(-а) дупло 6 раз", response["message"])
self.assertEqual(response["result"]["points"], 17)
self.assertEqual(response["result"]["points"], 21)
def test_bulk_inspection_payload_explains_missing_fields(self):
response = inspect_bulk_payload({"text": "/лу 15.08 11:00 11:20 | Белка [1] | Котёнок [2]"})
+20 -4
View File
@@ -64,9 +64,21 @@ class CalculationTests(unittest.TestCase):
),
)
)
self.assertEqual(result.escort_points, 24)
self.assertEqual(result.escort_points, 31.05)
self.assertEqual(result.kitten_points, 24)
def test_additional_wards_use_multipliers_instead_of_full_sum(self):
base = CoachingSession("15.08", "ЛУ", "11:00", "12:00", "Белка", 1, "Первый", 2)
session = CoachingSession(
"15.08", "ЛУ", "11:00", "12:00", "Белка", 1, "Первый", 2,
extra_kittens=(("Второй", 3, "самостоятельно"), ("Третий", 4, "самостоятельно")),
)
self.assertEqual(calculate_coaching(base).escort_points, 12)
result = calculate_coaching(session)
self.assertEqual(result.kitten_count, 3)
self.assertEqual(result.escort_multiplier, 1.725)
self.assertEqual(result.escort_points, 20.7)
def test_training_is_fixed(self):
self.assertEqual(calculate_training(TrainingSession("Белка", 1, "Котёнок", 2)).points, 25)
@@ -105,15 +117,15 @@ class ReportTests(unittest.TestCase):
character_id=1604614,
place="дупло",
inspections=6,
resources=(("вьюнок", -2), ("паук", 1)),
resources=(("вьюнок", 2), ("паук", 1)),
)
)
self.assertIn("осмотрел(-а) дупло 6 раз", text)
self.assertIn("#осмотр", text)
self.assertIn("-2 вьюнок.", text)
self.assertIn("+2 вьюнок.", text)
self.assertIn("+1 паук.", text)
self.assertNotIn("Скриншот", text)
self.assertIn("Баллы осмотра: 17 баллы.", text)
self.assertIn("Баллы осмотра: 21 баллы.", text)
def test_inspection_points_include_attempts_and_resource_values(self):
report = InspectionReport(
@@ -124,6 +136,10 @@ class ReportTests(unittest.TestCase):
self.assertEqual(calculate_inspection(report).points, 11)
self.assertIn("Баллы осмотра: 11 баллы.", render_inspection(report))
def test_inspection_rejects_negative_resources(self):
with self.assertRaises(ValueError):
InspectionReport("Белка", 1, "дупло", 1, (("вьюнок", -1),))
def test_inspection_resource_aliases_and_typos(self):
report = InspectionReport(
character_name="Белка", character_id=1, place="дупло", inspections=0,
+16 -2
View File
@@ -9,11 +9,11 @@ class CalculationHistoryTests(unittest.TestCase):
def test_admin_rows_sort_by_kitten_id_and_name(self) -> None:
with tempfile.TemporaryDirectory() as directory:
store = CalculationStore(sqlite_path=Path(directory) / "history.sqlite3")
for kitten_id, kitten_name in ((30, "Тучка"), (10, "Янтарь"), (20, "Белка")):
for escort_id, kitten_id, kitten_name in ((30, 30, "Тучка"), (10, 10, "Янтарь"), (20, 20, "Белка")):
store.save(
actor_id=99,
source="vk",
payload={"mode": "coaching", "kitten_id": kitten_id, "kitten_name": kitten_name},
payload={"mode": "coaching", "escort_id": escort_id, "escort_name": f"Кот {escort_id}", "kitten_id": kitten_id, "kitten_name": kitten_name},
response={"mode": "coaching", "message": f"расчёт {kitten_id}", "result": {"points": 1}},
)
@@ -24,6 +24,20 @@ class CalculationHistoryTests(unittest.TestCase):
self.assertEqual(by_name[0]["actor_id"], 99)
self.assertEqual(by_name[0]["result"]["points"], 1)
store.save(
actor_id=100,
source="web",
payload={"mode": "coaching", "escort_id": 5, "escort_name": "Альфа", "kitten_id": 99},
response={"mode": "coaching", "message": "расчёт 99", "result": {"points": 1}},
)
by_escort = store.list_calculations(sort_by="escort_id", descending=False)
self.assertEqual([row["input"].get("escort_id") for row in by_escort[:3]], [5, 10, 20])
record_id = by_name[0]["id"]
self.assertTrue(store.delete_calculation(record_id))
self.assertFalse(store.delete_calculation(record_id))
self.assertNotIn(record_id, [row["id"] for row in store.list_calculations()])
if __name__ == "__main__":
unittest.main()
+6
View File
@@ -20,6 +20,12 @@ class VkBotTests(unittest.TestCase):
self.assertEqual(command["escort_id"], 1604614)
self.assertEqual(command["kitten_id"], 1617140)
def test_parse_coaching_command_with_additional_wards(self):
command = parse_text_command(
"/лу 15.08 11:00 11:20 | Белка [1] | Первый [2] | сам | доп. котята: Второй [3], Третий [4]"
)
self.assertEqual(command["extra_kittens"], (("Второй", 3, "самостоятельно"), ("Третий", 4, "самостоятельно")))
def test_parse_help(self):
self.assertEqual(parse_text_command("/help"), {"mode": "help"})
self.assertIn("/лу", HELP_TEXT)
+12 -2
View File
@@ -123,9 +123,9 @@ class VkConversationTests(unittest.TestCase):
dialog.handle(106, "дупло")
dialog.handle(106, "6")
dialog.handle(106, "Серолап [1617140]")
self.assertIn("скриншот", dialog.handle(106, "-1 вьюнок, + 3 паук").lower())
self.assertIn("скриншот", dialog.handle(106, "+1 вьюнок, + 3 паук").lower())
confirmation = self.add_screenshot(dialog, 106)
self.assertIn("вьюнок=-1", confirmation)
self.assertIn("вьюнок=1", confirmation)
self.assertIn("паук=3", confirmation)
def test_queued_photo_is_saved_in_confirmed_state(self):
@@ -138,6 +138,16 @@ class VkConversationTests(unittest.TestCase):
self.assertIn("подтверд", confirmation.lower())
self.assertEqual(dialog._states[107]["attachments"][0]["url"], "https://example.test/photo.jpg")
def test_six_photos_are_kept_on_active_report(self):
dialog = BelkiDialog()
dialog.handle(109, "/урок")
dialog.handle(109, "Белка [1]")
dialog.handle(109, "Котёнок [2]")
dialog.queue_attachments(109, [{"type": "photo", "attachment": f"photo1_{index}", "url": f"https://example.test/{index}.jpg"} for index in range(6)])
confirmation = dialog.handle(109, "готово")
self.assertIn("подтверд", confirmation.lower())
self.assertEqual(len(dialog._states[109]["attachments"]), 6)
def test_photo_is_mirrored_before_history_save(self):
mirrored = []