Добавлен класс DescriptionMixin
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
from .created_at_mixin import CreatedAtMixin
|
||||
from .deleted_at_mixin import DeletedAtMixin
|
||||
from .description_mixin import DescriptionMixin
|
||||
from .expired_at_mixin import ExpiresAtMixin
|
||||
from .slug_mixin import SlugMixin
|
||||
from .updated_at_mixin import UpdatedAtMixin
|
||||
|
||||
34
net/xeaf/rack/models/mixins/description_mixin.py
Normal file
34
net/xeaf/rack/models/mixins/description_mixin.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# DRF Rack
|
||||
# Библиотека классов расширений для Django REST Framework
|
||||
#
|
||||
# Автор: Николай В. Анохин <n.anokhin@xeaf.net>
|
||||
# Все права защищены. Лицензия: MIT
|
||||
|
||||
"""
|
||||
Описание класса DescriptionMixin
|
||||
"""
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class DescriptionMixin(models.Model):
|
||||
"""
|
||||
Добавляет к модели свойство Описание
|
||||
"""
|
||||
|
||||
description = models.TextField(
|
||||
max_length=2048,
|
||||
editable=True,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("rack.mixin.description"),
|
||||
)
|
||||
""" Описание """
|
||||
|
||||
class Meta:
|
||||
"""
|
||||
Конфигурация класс
|
||||
"""
|
||||
|
||||
abstract = True
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
from .created_at_mixin_tests import CreatedAtMixinTests
|
||||
from .deleted_at_mixin_tests import DeletedAtMixinTests
|
||||
from .description_mixin_tests import DescriptionMixinTests
|
||||
from .expired_at_mixin_tests import ExpiresAtMixinTests
|
||||
from .slug_mixin_tests import SlugMixinTests
|
||||
from .updated_at_mixin_tests import UpdatedAtMixinTests
|
||||
|
||||
59
net/xeaf/rack/tests/models/mixins/description_mixin_tests.py
Normal file
59
net/xeaf/rack/tests/models/mixins/description_mixin_tests.py
Normal file
@@ -0,0 +1,59 @@
|
||||
# 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'))
|
||||
Reference in New Issue
Block a user