feat: add Belichya Nora calculator and VK bot
This commit is contained in:
1 parent
cd6a594ed4
commit
c86d077f9f
20 files changed
+2002
-18
No files matched your search
@@ -0,0 +1,72 @@
|
||||
import unittest
|
||||
import sqlite3
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
from app.belki.api import ApiError, calculate_payload, inspect_bulk_payload, resolve_identity_payload
|
||||
from app.belki.history import CalculationStore
|
||||
|
||||
|
||||
class ApiTests(unittest.TestCase):
|
||||
def test_calculate_coaching_payload(self):
|
||||
response = calculate_payload(
|
||||
{
|
||||
"mode": "coaching",
|
||||
"date": "15.08",
|
||||
"skill": "ЛУ",
|
||||
"start": "00:52",
|
||||
"end": "01:52",
|
||||
"escort_name": "Дикая Вишня",
|
||||
"escort_id": 1604614,
|
||||
"kitten_name": "Котёнок",
|
||||
"kitten_id": 1676767,
|
||||
"kitten_independence": "самостоятельно",
|
||||
}
|
||||
)
|
||||
self.assertEqual(response["result"]["minutes"], 60)
|
||||
self.assertIn("Баллы белки: 12", response["message"])
|
||||
|
||||
def test_calculate_rejects_unknown_mode(self):
|
||||
with self.assertRaises(ApiError):
|
||||
calculate_payload({"mode": "unknown"})
|
||||
|
||||
def test_calculate_inspection_payload(self):
|
||||
response = calculate_payload(
|
||||
{
|
||||
"mode": "inspection",
|
||||
"character_name": "Дикая Вишня",
|
||||
"character_id": 1604614,
|
||||
"place": "дупло",
|
||||
"inspections": 6,
|
||||
"resources": [["вьюнок", -2], ["паук", 1]],
|
||||
}
|
||||
)
|
||||
self.assertIn("осмотрел(а) дупло 6 раз", response["message"])
|
||||
|
||||
def test_bulk_inspection_payload_explains_missing_fields(self):
|
||||
response = inspect_bulk_payload({"text": "/лу 15.08 11:00 11:20 | Белка [1] | Котёнок [2]"})
|
||||
self.assertEqual(response["status"], "needs_clarification")
|
||||
self.assertTrue(response["questions"])
|
||||
|
||||
def test_identity_resolution_without_directory_requests_missing_half(self):
|
||||
response = resolve_identity_payload({"character_id": 1617140})
|
||||
self.assertEqual(response["status"], "needs_input")
|
||||
self.assertIn("имя", response["message"].lower())
|
||||
|
||||
def test_calculation_store_persists_full_record(self):
|
||||
with TemporaryDirectory() as directory:
|
||||
path = f"{directory}/history.sqlite3"
|
||||
store = CalculationStore(sqlite_path=path)
|
||||
response = calculate_payload({
|
||||
"mode": "training", "escort_name": "Дикая Вишня", "escort_id": 1604614,
|
||||
"kitten_name": "Серолап", "kitten_id": 1617140,
|
||||
})
|
||||
record_id = store.save(actor_id=700, source="vk", payload={"mode": "training"}, response=response)
|
||||
self.assertGreater(record_id, 0)
|
||||
with sqlite3.connect(path) as connection:
|
||||
row = connection.execute("SELECT actor_id, mode, source, message FROM calculations").fetchone()
|
||||
self.assertEqual(row[:3], (700, "training", "vk"))
|
||||
self.assertIn("25", row[3])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user