Добавлены классы моделей данных Account, Session
This commit is contained in:
72
net/xeaf/rack/tests/models/account_model_tests.py
Normal file
72
net/xeaf/rack/tests/models/account_model_tests.py
Normal file
@@ -0,0 +1,72 @@
|
||||
# DRF Rack
|
||||
# Библиотека классов расширений для Django REST Framework
|
||||
#
|
||||
# Автор: Николай В. Анохин <n.anokhin@xeaf.net>
|
||||
# Все права защищены. Лицензия: MIT
|
||||
|
||||
"""
|
||||
Описание класса AccountModelTests
|
||||
"""
|
||||
|
||||
from django.db.utils import IntegrityError
|
||||
from django.test import TestCase
|
||||
|
||||
from net.xeaf.rack.models import AccountModel
|
||||
|
||||
|
||||
class AccountModelTests(TestCase):
|
||||
"""
|
||||
Тесты для класса AccountModel
|
||||
"""
|
||||
|
||||
def test_create_account_with_defaults(self):
|
||||
"""
|
||||
Проверяет корректное создание аккаунта с дефолтными полями
|
||||
"""
|
||||
|
||||
email = "test_user@example.com"
|
||||
|
||||
# Создаем через чистый ORM, как ты любишь, построчно
|
||||
account = AccountModel()
|
||||
account.username = email
|
||||
account.save()
|
||||
|
||||
# Проверяем контракт полей
|
||||
self.assertEqual(account.username, email)
|
||||
self.assertIsNone(account.full_name)
|
||||
self.assertIsNone(account.nick_name)
|
||||
|
||||
# Если ты исправил дефолт на dict, тест гарантирует безопасность:
|
||||
self.assertEqual(account.extra, {})
|
||||
|
||||
def test_compatibility_methods(self):
|
||||
"""
|
||||
Проверяет методы совместимости get_full_name и get_short_name
|
||||
"""
|
||||
|
||||
account = AccountModel()
|
||||
account.username = "names@example.com"
|
||||
account.full_name = "Иван Иванов"
|
||||
account.nick_name = "vanya"
|
||||
account.save()
|
||||
|
||||
self.assertEqual(account.get_full_name(), "Иван Иванов")
|
||||
self.assertEqual(account.get_short_name(), "vanya")
|
||||
|
||||
def test_username_uniqueness_constraint(self):
|
||||
"""
|
||||
Проверяет жесткое ограничение уникальности на уровне UniqueConstraint
|
||||
"""
|
||||
|
||||
duplicate_email = "duplicate@example.com"
|
||||
|
||||
# Создаем первого
|
||||
account1 = AccountModel(username=duplicate_email)
|
||||
account1.save()
|
||||
|
||||
# Попытка создать второго с тем же username должна намертво упасть в БД
|
||||
account2 = AccountModel(username=duplicate_email)
|
||||
|
||||
with self.assertRaises(IntegrityError):
|
||||
account2.save()
|
||||
|
||||
Reference in New Issue
Block a user