def test_get_uses_class_name_if_block_settings_key_is_not_set(self): """ Test if settings service uses class name if block_settings_key attribute does not exist """ mixologist = Mixologist([]) block = mixologist.mix(_DummyBlock) self.assertEqual(settings.XBLOCK_SETTINGS, {"_DummyBlock": [1, 2, 3]}) self.assertEqual(self.settings_service.get_settings_bucket(block), [1, 2, 3])
def _load_mixed_class(category): """ Load an XBlock by category name, and apply all defined mixins """ component_class = XBlock.load_class(category, select=settings.XBLOCK_SELECT_FUNCTION) mixologist = Mixologist(settings.XBLOCK_MIXINS) return mixologist.mix(component_class)
def load_mixed_class(category): """ Load an XBlock by category name, and apply all defined mixins """ component_class = XModuleDescriptor.load_class(category) mixologist = Mixologist(settings.XBLOCK_MIXINS) return mixologist.mix(component_class)
def __init__(self, contentstore, **kwargs): super(ModuleStoreWriteBase, self).__init__(contentstore=contentstore, **kwargs) # TODO: Don't have a runtime just to generate the appropriate mixin classes (cpennington) # This is only used by partition_fields_by_scope, which is only needed because # the split mongo store is used for item creation as well as item persistence self.mixologist = Mixologist(self.xblock_mixins)
def test_multiply_mixed(self): mixalot = Mixologist([ThirdMixin, FirstMixin]) pre_mixed = mixalot.mix(self.mixologist.mix(FieldTester)) post_mixed = self.mixologist.mix(mixalot.mix(FieldTester)) assert_is(pre_mixed.fields['field'], FirstMixin.field) assert_is(post_mixed.fields['field'], ThirdMixin.field) assert_is(FieldTester, pre_mixed.unmixed_class) assert_is(FieldTester, post_mixed.unmixed_class) assert_equals(4, len(pre_mixed.__bases__)) # 1 for the original class + 3 mixin classes assert_equals(4, len(post_mixed.__bases__))
def test_multiply_mixed(self): mixalot = Mixologist([ThirdMixin, FirstMixin]) pre_mixed = mixalot.mix(self.mixologist.mix(FieldTester)) post_mixed = self.mixologist.mix(mixalot.mix(FieldTester)) assert pre_mixed.fields['field'] is FirstMixin.field assert post_mixed.fields['field'] is ThirdMixin.field assert FieldTester is pre_mixed.unmixed_class assert FieldTester is post_mixed.unmixed_class assert len(pre_mixed.__bases__) == 4 # 1 for the original class + 3 mixin classes assert len(post_mixed.__bases__) == 4
def setUp(self): self.mixologist = Mixologist([FirstMixin, SecondMixin])
def __init__(self, contentstore, **kwargs): super(ModuleStoreWriteBase, self).__init__(contentstore=contentstore, **kwargs) self.mixologist = Mixologist(self.xblock_mixins)
def test_bad_class_name(self): bad_class_name = 'xblock.test.test_runtime.NonExistentMixin' with pytest.raises( ImportError, match="Couldn't import class .*'{}'".format(bad_class_name)): Mixologist([bad_class_name])
def setup_method(self): """ Setup for each test method in this class. """ self.mixologist = Mixologist( ['xblock.test.test_runtime.FirstMixin', SecondMixin]) # pylint: disable=attribute-defined-outside-init