60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
# DRF Rack
|
|
# Библиотека классов расширений для Django REST Framework
|
|
#
|
|
# Автор: Николай В. Анохин <n.anokhin@xeaf.net>
|
|
# Все права защищены. Лицензия: MIT
|
|
|
|
"""
|
|
Описание класса DescriptionMixinTests
|
|
"""
|
|
|
|
from django.db import connection
|
|
from django.db import models
|
|
from django.test import TransactionTestCase
|
|
|
|
from net.xeaf.rack.models.mixins import DescriptionMixin
|
|
|
|
|
|
class DescriptionMixinTests(TransactionTestCase):
|
|
"""
|
|
Тесты для миксина DescriptionMixin
|
|
"""
|
|
|
|
def setUp(self):
|
|
"""
|
|
Создаем тестовую модель и таблицу для каждого теста
|
|
"""
|
|
|
|
with connection.cursor() as cursor:
|
|
cursor.execute('PRAGMA foreign_keys = OFF;')
|
|
|
|
class TestDescriptionModel(DescriptionMixin):
|
|
name = models.CharField(max_length=100)
|
|
|
|
class Meta:
|
|
app_label = 'test'
|
|
db_table = 'test_slug_mixin'
|
|
|
|
self.TestModel = TestDescriptionModel
|
|
|
|
with connection.schema_editor() as editor:
|
|
editor.create_model(TestDescriptionModel)
|
|
|
|
def tearDown(self):
|
|
"""
|
|
Удаляем таблицу после каждого теста
|
|
"""
|
|
|
|
with connection.schema_editor() as editor:
|
|
editor.delete_model(self.TestModel)
|
|
|
|
with connection.cursor() as cursor:
|
|
cursor.execute('PRAGMA foreign_keys = ON;')
|
|
|
|
def test_description_field_exists(self):
|
|
"""
|
|
Проверяем, что поле description добавлено в модель
|
|
"""
|
|
|
|
self.assertTrue(hasattr(self.TestModel, 'description'))
|