48 lines
2.8 KiB
Python
48 lines
2.8 KiB
Python
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from app.belki.applications import ApplicationError, ApplicationStore, validate_application
|
|
from app.belki.identity import IdentityDirectory
|
|
from app.belki.vk_bot import ApplicationDialog
|
|
|
|
|
|
class ApplicationTests(unittest.TestCase):
|
|
def test_kitten_requires_activity_screenshot(self) -> None:
|
|
with self.assertRaisesRegex(ApplicationError, "скриншот активности"):
|
|
validate_application({"type": "kitten", "name": "Бельчоночек", "character_id": 1676767})
|
|
|
|
def test_flying_squirrel_requires_previous_practice_comment(self) -> None:
|
|
with self.assertRaisesRegex(ApplicationError, "прошлой практики"):
|
|
validate_application({"type": "flying_squirrel", "name": "Муся", "character_id": 1337, "practiced_before": True})
|
|
|
|
def test_feather_donation_is_saved_and_accepted(self) -> None:
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
store = ApplicationStore(sqlite_path=Path(directory) / "applications.sqlite3")
|
|
application = validate_application({
|
|
"type": "feather_donation", "name": "Белка", "character_id": 58775,
|
|
"feathers": [{"amount": 2, "color": "синие", "source": "личные запасы"}, {"amount": 1, "color": "чёрное", "source": "осмотр дупла"}],
|
|
})
|
|
application_id = store.create(application=application, actor_id=10, reply_peer_id=10, source="vk")
|
|
self.assertEqual(store.list(status="pending")[0]["application"]["feathers"][0]["color"], "синие")
|
|
accepted = store.accept(application_id)
|
|
self.assertEqual(accepted["status"], "accepted")
|
|
self.assertEqual(store.pending_notifications()[0]["reply_peer_id"], 10)
|
|
store.mark_notified(application_id)
|
|
self.assertEqual(store.pending_notifications(), [])
|
|
|
|
def test_vk_kitten_application_uses_profile_and_saves(self) -> None:
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
store = ApplicationStore(sqlite_path=Path(directory) / "applications.sqlite3")
|
|
identities = IdentityDirectory(db_path=Path(directory) / "identities.sqlite3")
|
|
identities.remember_profile(actor_id=55, name="Бельчоночек", character_id=1676767)
|
|
dialog = ApplicationDialog(identities, store)
|
|
self.assertIn("скриншот активности", dialog.handle(55, 55, "/бельчонок").lower())
|
|
dialog.queue_attachments(55, [{"type": "photo", "url": "https://example.test/activity.jpg"}])
|
|
self.assertIn("отправлена", dialog.handle(55, 55, "готово").lower())
|
|
self.assertEqual(store.list()[0]["application"]["type"], "kitten")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|