0
0
mirror of https://gitflic.ru/project/maks1ms/ocab.git synced 2024-12-24 16:44:44 +03:00
ocab/tests/test_db.py

66 lines
2.5 KiB
Python
Raw Normal View History

import unittest
from src.core.database.api import *
from src.core.database.models.base import database
create_tables(database)
class TestDatabaseAPI(unittest.TestCase):
def test_add_and_get_chat(self):
add_chat(chat_id=21, chat_role=1, chat_stats=0, chat_federation=0)
chat = get_chat(21)
self.assertIsNotNone(chat)
self.assertEqual(chat.id, 21)
self.assertEqual(chat.chat_role, 1)
def test_add_and_get_message(self):
add_message(message_id=1, message_text="Test Message", message_sender=1, answer_id=2)
message = get_message(1)
self.assertIsNotNone(message)
self.assertEqual(message.id, 1)
self.assertEqual(message.message_text, "Test Message")
def test_add_and_get_user(self):
add_user(user_id=100, user_name="TestUser", user_tag="TestTag", user_role=2, user_stats=10, user_rep=5)
user = get_user(100)
self.assertIsNotNone(user)
self.assertEqual(user.id, 100)
self.assertEqual(user.user_name, "TestUser")
def test_get_user_role(self):
add_user(user_id=101, user_name="TestUser2", user_tag="TestTag2", user_role=3, user_stats=20, user_rep=10)
user_role = get_user_role(101)
self.assertEqual(user_role, 3)
def test_change_user_name(self):
add_user(user_id=102, user_name="OldName", user_tag="TestTag3", user_role=4, user_stats=30, user_rep=15)
change_user_name(102, "NewName")
updated_user = get_user(102)
self.assertEqual(updated_user.user_name, "NewName")
# Дополнительные тесты для других функций обновления...
def test_update_user_stats(self):
add_user(user_id=103, user_name="UserStats", user_tag="TestTag4", user_role=5, user_stats=40, user_rep=20)
update_user_stats()
updated_user = get_user(103)
self.assertEqual(updated_user.user_stats, 41)
def test_update_user_rep(self):
add_user(user_id=104, user_name="UserRep", user_tag="TestTag5", user_role=6, user_stats=50, user_rep=25)
update_user_rep()
updated_user = get_user(104)
self.assertEqual(updated_user.user_rep, 26)
def test_update_chat_stats(self):
add_chat(chat_id=22, chat_role=2, chat_stats=100, chat_federation=0)
update_chat_stats()
updated_chat = get_chat(22)
self.assertEqual(updated_chat.chat_stats, 101)
# Дополнительные тесты для других функций...
if __name__ == '__main__':
unittest.main()