def test_remove_bundle_on_request_with_subrequest(self): req = self.layer['request'] # create a subrequest. subreq = req.clone() subreq['PARENT_REQUEST'] = req # remove the enabled 'foo' bundle remove_bundle_on_request(req, 'foo') scripts = ScriptsView(self.layer['portal'], subreq, None) # Send resource registry in development mode # Via a fake registry to allow accessing like this: # self.registry.records['plone.resources.development'].value scripts.registry = type( 'reg', (object, ), { 'records': { 'plone.resources.development': type('val', (object, ), {'value': True})() } })() self.assertTrue(scripts.development) scripts.update() results = scripts.scripts() self.assertEqual(filter(lambda it: 'foo' in it['src'], results), [])
def test_add_resource_on_request_with_subrequest(self): """Check, if a resource added at a main request is picked up from a subrequest for creating the header scripts section. """ req = self.layer['request'] # create a subrequest. subreq = req.clone() subreq['PARENT_REQUEST'] = req # add a resource to main request add_resource_on_request(req, 'foo') scripts = ScriptsView(self.layer['portal'], subreq, None) scripts.update() results = scripts.scripts() self.assertEqual( results[-1], { 'src': 'http://nohost/plone/++resource++foo.js', 'conditionalcomment': '', 'resetrjs': False, 'bundle': 'none', }) styles = StylesView(self.layer['portal'], subreq, None) styles.update() results = styles.styles() self.assertEqual( filter(lambda it: 'foo' in it['src'], results)[0], { 'src': 'http://nohost/plone/++resource++foo.css', 'conditionalcomment': '', 'rel': 'stylesheet', 'bundle': 'none', })
def test_remove_bundle_on_request_with_subrequest(self): req = self.layer['request'] # create a subrequest. subreq = req.clone() subreq['PARENT_REQUEST'] = req # remove the enabled 'foo' bundle remove_bundle_on_request(req, 'foo') scripts = ScriptsView(self.layer['portal'], subreq, None) # Send resource registry in development mode # Via a fake registry to allow accessing like this: # self.registry.records['plone.resources.development'].value scripts.registry = type( 'reg', (object, ), {'records': { 'plone.resources.development': type( 'val', (object, ), {'value': True} )() }} )() self.assertTrue(scripts.development) scripts.update() results = scripts.scripts() self.assertEqual( filter(lambda it: 'foo' in it['src'], results), [] )
def test_add_bundle_on_request_with_subrequest(self): req = self.layer['request'] # create a subrequest. subreq = req.clone() subreq['PARENT_REQUEST'] = req # add a bundle via the main request add_bundle_on_request(req, 'foo') scripts = ScriptsView(self.layer['portal'], subreq, None) # Send resource registry in development mode # Via a fake registry to allow accessing like this: # self.registry.records['plone.resources.development'].value scripts.registry = type( 'reg', (object, ), { 'records': { 'plone.resources.development': type('val', (object, ), {'value': True})() } })() self.assertTrue(scripts.development) scripts.update() results = scripts.scripts() self.assertEqual( results[-1], { 'src': 'http://nohost/plone/++resource++foo.js?version=123', 'conditionalcomment': None, 'bundle': 'foo' })
def test_request_resources(self): add_resource_on_request(self.layer['request'], 'foo') scripts = ScriptsView(self.layer['portal'], self.layer['request'], None) scripts.update() results = scripts.scripts() self.assertEqual( results[-1], {'src': 'http://nohost/plone/++resource++foo.js', 'conditionalcomment': '', 'bundle': 'none'})
def test_scripts_viewlet(self): scripts = ScriptsView(self.layer['portal'], self.layer['request'], None) scripts.update() results = scripts.scripts() self.assertEqual( results[0], {'src': 'http://nohost/plone/++plone++static/components/jquery/dist/jquery.min.js', 'conditionalcomment': None, 'bundle': 'basic'}) self.assertEqual(len(results), 6)
def test_scripts_viewlet_anonymous(self): logout() scripts = ScriptsView(self.layer['portal'], self.layer['request'], None) scripts.update() results = scripts.scripts() self.assertEqual(results[0]['bundle'], 'production') self.assertTrue(results[0]['src'].startswith( 'http://nohost/plone/++plone++production/++unique++')) self.assertTrue(results[0]['src'].endswith('/default.js')) self.assertEqual(len(results), 1)
def test_cooking_missing_browserresource(self): registry = getUtility(IRegistry) registry['plone.resources.development'] = True bundles = registry.collectionOfInterface(IBundleRegistry, prefix="plone.bundles") bundle = bundles.add('barbar') bundle.jscompilation = '++resource++notfound/barbar-compiled.js' bundle.csscompilation = '++resource++notfound/barbar-compiled.css' bundle.compile = False bundle.merge_with = 'default' bundle = Bundle(bundle) # cookWhenChangingSettings(self.portal, bundle) scripts = ScriptsView(self.layer['portal'], self.layer['request'], None) scripts.update() results = scripts.scripts() # at least have jquery.min.js, config.js, require.js, etc. self.assertTrue(len(results) > 2)
def test_add_resource_on_request_with_subrequest(self): """Check, if a resource added at a main request is picked up from a subrequest for creating the header scripts section. """ req = self.layer['request'] # create a subrequest. subreq = req.clone() subreq['PARENT_REQUEST'] = req # add a resource to main request add_resource_on_request(req, 'foo') scripts = ScriptsView(self.layer['portal'], subreq, None) scripts.update() results = scripts.scripts() self.assertEqual( results[-1], { 'src': 'http://nohost/plone/++resource++foo.js', 'conditionalcomment': '', 'resetrjs': False, 'bundle': 'none', } ) styles = StylesView(self.layer['portal'], subreq, None) styles.update() results = styles.styles() self.assertEqual( filter(lambda it: 'foo' in it['src'], results)[0], { 'src': 'http://nohost/plone/++resource++foo.css', 'conditionalcomment': '', 'rel': 'stylesheet', 'bundle': 'none', } )
def test_add_bundle_on_request_with_subrequest(self): req = self.layer['request'] # create a subrequest. subreq = req.clone() subreq['PARENT_REQUEST'] = req # add a bundle via the main request add_bundle_on_request(req, 'foo') scripts = ScriptsView(self.layer['portal'], subreq, None) # Send resource registry in development mode # Via a fake registry to allow accessing like this: # self.registry.records['plone.resources.development'].value scripts.registry = type( 'reg', (object, ), {'records': { 'plone.resources.development': type( 'val', (object, ), {'value': True} )() }} )() self.assertTrue(scripts.development) scripts.update() results = scripts.scripts() self.assertEqual( results[-1], { 'src': 'http://nohost/plone/++resource++foo.js?version=123', 'conditionalcomment': None, 'bundle': 'foo' } )