def test_resources_are_ordered_by_slot_order(self): registry = SCSSRegistry() for slotname in ('policy', 'variables', 'addon', 'theme', 'top'): registry.add_resource(SCSSFileResource('ftw.theming.tests', 'resources/foo.scss', slot=slotname)) self.assertEquals( ['top', 'variables', 'addon', 'theme', 'policy'], slots(registry.get_resources(CONTEXT, REQUEST)))
def test_resource_factories_returning_None_are_skipped(self): registry = SCSSRegistry() @registry.add_resource @provider(ISCSSResourceFactory) def null_resource_factory(context, request): return None self.assertEquals([], registry.get_resources(CONTEXT, REQUEST)) self.assertEquals([], registry.get_resources(CONTEXT, REQUEST, include_unavailable=True))
def test_get_raw_dynamic_resources(self): """The get_raw_dynamic_resources method returns all dynamic resources without ordering or filtering. This is much more efficient and can be used for fast cache calculation. """ foo = SCSSFileResource('ftw.theming.tests', 'resources/foo.scss') bar = DynamicSCSSResource('bar') registry = SCSSRegistry() registry.add_resource(foo) registry.add_resource(bar) self.assertEquals([bar], registry.get_raw_dynamic_resources(None, None))
def test_resource_order_is_kept_within_slot(self): registry = SCSSRegistry() registry.add_resource(SCSSFileResource('ftw.theming.tests', 'resources/baz.scss')) registry.add_resource(SCSSFileResource('ftw.theming.tests', 'resources/foo.scss')) registry.add_resource(SCSSFileResource('ftw.theming.tests', 'resources/bar.scss')) self.assertEquals( ['resources/baz.scss', 'resources/foo.scss', 'resources/bar.scss'], paths(registry.get_resources(CONTEXT, REQUEST)))
def test_conflicting_order(self): registry = SCSSRegistry() registry.add_resource(SCSSFileResource('ftw.theming.tests', 'resources/foo.scss', after='resources/bar.scss')) registry.add_resource(SCSSFileResource('ftw.theming.tests', 'resources/bar.scss', after='resources/foo.scss')) registry.add_resource(SCSSFileResource('ftw.theming.tests', 'resources/baz.scss')) with self.assertRaises(CyclicResourceOrder) as cm: registry.get_resources(CONTEXT, REQUEST) self.assertEquals( "Cyclic resource order: [['ftw.theming.tests:resources/bar.scss', " "'ftw.theming.tests:resources/foo.scss']]", str(cm.exception))
def test_calls_registered_resource_factories(self): foo = SCSSFileResource('ftw.theming.tests', 'resources/foo.scss') dynamic = SCSSResource('dynamic-scss', slot='addon', source=u'$foreground = black;') bar = SCSSFileResource('ftw.theming.tests', 'resources/baz.scss') @provider(ISCSSResourceFactory) def dynamic_resource_factory(context, request): return dynamic registry = SCSSRegistry() registry.add_resource(foo) registry.add_resource(dynamic_resource_factory) registry.add_resource(bar) self.assertEquals([foo, dynamic, bar], registry.get_resources(CONTEXT, REQUEST))
def test_include_unavailable_resources(self): registry = SCSSRegistry() registry.add_resource(SCSSFileResource('ftw.theming.tests', 'resources/foo.scss')) registry.add_resource(SCSSFileResource('ftw.theming.tests', 'resources/bar.scss', profile='bar:default')) self.assertEquals( ['resources/foo.scss'], paths(registry.get_resources(CONTEXT, REQUEST, ProfileInfoStub()))) self.assertEquals( ['resources/foo.scss', 'resources/bar.scss'], paths(registry.get_resources(CONTEXT, REQUEST, ProfileInfoStub(), include_unavailable=True)))
def test_add_resources(self): foo = SCSSFileResource('ftw.theming.tests', 'resources/foo.scss') registry = SCSSRegistry() registry.add_resource(foo) self.assertEquals([foo], registry.get_resources(CONTEXT, REQUEST))