[TNL-3962] moving DEPRECATED_ADVANCED_COMPONENT_TYPES to dJango admin

This commit is contained in:
Ehtesham
2016-01-20 17:45:35 +05:00
parent ba2c6b79fb
commit b9c8b3308d
7 changed files with 154 additions and 24 deletions

View File

@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('xblock_django', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='xblockdisableconfig',
name='disabled_create_blocks',
field=models.TextField(default=b'', help_text='Space-separated list of XBlock types whose creation to disable in Studio.', blank=True),
),
]

View File

@@ -3,6 +3,8 @@ Models.
"""
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.db.models import TextField
from config_models.models import ConfigurationModel
@@ -10,7 +12,7 @@ from config_models.models import ConfigurationModel
class XBlockDisableConfig(ConfigurationModel):
"""
Configuration for disabling XBlocks.
Configuration for disabling and deprecating XBlocks.
"""
class Meta(ConfigurationModel.Meta):
@@ -21,6 +23,13 @@ class XBlockDisableConfig(ConfigurationModel):
help_text=_('Space-separated list of XBlocks which should not render.')
)
disabled_create_blocks = TextField(
default='', blank=True,
help_text=_(
"Space-separated list of XBlock types whose creation to disable in Studio."
)
)
@classmethod
def is_block_type_disabled(cls, block_type):
""" Return True if block_type is disabled. """
@@ -40,3 +49,26 @@ class XBlockDisableConfig(ConfigurationModel):
return ()
return config.disabled_blocks.split()
@classmethod
def disabled_create_block_types(cls):
""" Return list of deprecated XBlock types. Merges types in settings file and field. """
config = cls.current()
xblock_types = config.disabled_create_blocks.split() if config.enabled else []
# Merge settings list with one in the admin config;
if hasattr(settings, 'DEPRECATED_ADVANCED_COMPONENT_TYPES'):
xblock_types.extend(
xblock_type for xblock_type in settings.DEPRECATED_ADVANCED_COMPONENT_TYPES
if xblock_type not in xblock_types
)
return xblock_types
def __unicode__(self):
config = XBlockDisableConfig.current()
return u"Disabled xblocks = {disabled_xblocks}\nDeprecated xblocks = {disabled_create_block_types}".format(
disabled_xblocks=config.disabled_blocks,
disabled_create_block_types=config.disabled_create_block_types
)

View File

@@ -0,0 +1,58 @@
"""
Tests for deprecated xblocks in XBlockDisableConfig.
"""
import ddt
from mock import patch
from django.test import TestCase
from xblock_django.models import XBlockDisableConfig
@ddt.ddt
class XBlockDisableConfigTestCase(TestCase):
"""
Tests for the DjangoXBlockUserService.
"""
def setUp(self):
super(XBlockDisableConfigTestCase, self).setUp()
# Initialize the deprecated modules settings with empty list
XBlockDisableConfig.objects.create(
disabled_blocks='', enabled=True
)
@ddt.data(
('poll', ['poll']),
('poll survey annotatable textannotation', ['poll', 'survey', 'annotatable', 'textannotation']),
('', [])
)
@ddt.unpack
def test_deprecated_blocks_splitting(self, xblocks, expected_result):
"""
Tests that it correctly splits the xblocks defined in field.
"""
XBlockDisableConfig.objects.create(
disabled_create_blocks=xblocks, enabled=True
)
self.assertEqual(
XBlockDisableConfig.disabled_create_block_types(), expected_result
)
@patch('django.conf.settings.DEPRECATED_ADVANCED_COMPONENT_TYPES', ['poll', 'survey'])
def test_deprecated_blocks_file(self):
"""
Tests that deprecated modules contain entries from settings file DEPRECATED_ADVANCED_COMPONENT_TYPES
"""
self.assertEqual(XBlockDisableConfig.disabled_create_block_types(), ['poll', 'survey'])
@patch('django.conf.settings.DEPRECATED_ADVANCED_COMPONENT_TYPES', ['poll', 'survey'])
def test_deprecated_blocks_file_and_config(self):
"""
Tests that deprecated types defined in both settings and config model are read.
"""
XBlockDisableConfig.objects.create(
disabled_create_blocks='annotatable', enabled=True
)
self.assertEqual(XBlockDisableConfig.disabled_create_block_types(), ['annotatable', 'poll', 'survey'])