def testAccessWebRoot(self): """ Requests the webroot and tests the existence of several elements in the returned html """ # Check webroot default settings defaultEmailAddress = self.model('setting').getDefault(SettingKey.CONTACT_EMAIL_ADDRESS) defaultBrandName = self.model('setting').getDefault(SettingKey.BRAND_NAME) resp = self.request(path='/', method='GET', isJson=False, prefix='') self.assertStatus(resp, 200) body = self.getBody(resp) self.assertIn(WebrootBase._escapeJavascript(defaultEmailAddress), body) self.assertIn('<title>%s</title>' % defaultBrandName, body) self.assertIn('girder_app.min.js', body) self.assertIn('girder_lib.min.js', body) # Change webroot settings self.model('setting').set(SettingKey.CONTACT_EMAIL_ADDRESS, '*****@*****.**') self.model('setting').set(SettingKey.BRAND_NAME, 'FooBar') resp = self.request(path='/', method='GET', isJson=False, prefix='') self.assertStatus(resp, 200) body = self.getBody(resp) self.assertIn(WebrootBase._escapeJavascript('*****@*****.**'), body) self.assertIn('<title>FooBar</title>', body) # Remove webroot settings self.model('setting').unset(SettingKey.CONTACT_EMAIL_ADDRESS) self.model('setting').unset(SettingKey.BRAND_NAME) resp = self.request(path='/', method='GET', isJson=False, prefix='') self.assertStatus(resp, 200) body = self.getBody(resp) self.assertIn(WebrootBase._escapeJavascript(defaultEmailAddress), body) self.assertIn('<title>%s</title>' % defaultBrandName, body)
def testAccessWebRoot(server, db): """ Requests the webroot and tests the existence of several elements in the returned html """ # Check webroot default settings defaultEmailAddress = Setting().getDefault(SettingKey.CONTACT_EMAIL_ADDRESS) defaultBrandName = Setting().getDefault(SettingKey.BRAND_NAME) resp = server.request(path='/', method='GET', isJson=False, prefix='') assertStatusOk(resp) body = getResponseBody(resp) assert WebrootBase._escapeJavascript(defaultEmailAddress) in body assert '<title>%s</title>' % defaultBrandName in body assert 'girder_app.min.js' in body assert 'girder_lib.min.js' in body # Change webroot settings Setting().set(SettingKey.CONTACT_EMAIL_ADDRESS, '*****@*****.**') Setting().set(SettingKey.BRAND_NAME, 'FooBar') resp = server.request(path='/', method='GET', isJson=False, prefix='') assertStatusOk(resp) body = getResponseBody(resp) assert WebrootBase._escapeJavascript('*****@*****.**') in body assert '<title>FooBar</title>' in body # Remove webroot settings Setting().unset(SettingKey.CONTACT_EMAIL_ADDRESS) Setting().unset(SettingKey.BRAND_NAME) resp = server.request(path='/', method='GET', isJson=False, prefix='') assertStatusOk(resp) body = getResponseBody(resp) assert WebrootBase._escapeJavascript(defaultEmailAddress) in body assert '<title>%s</title>' % defaultBrandName in body
def testEscapeJavascript(): # Don't escape alphanumeric characters alphaNumString = 'abcxyz0189ABCXYZ' assert WebrootBase._escapeJavascript(alphaNumString) == alphaNumString # Do escape everything else dangerString = 'ab\'"<;>\\YZ' assert WebrootBase._escapeJavascript(dangerString) == \ 'ab\\u0027\\u0022\\u003C\\u003B\\u003E\\u005CYZ'
def testWebRootTemplateFilename(): """ Test WebrootBase.templateFilename attribute after initialization and after setting a custom template path. """ webroot = WebrootBase(templatePath='/girder/base_template.mako') assert webroot.templateFilename == 'base_template.mako' webroot.setTemplatePath('/plugin/custom_template.mako') assert webroot.templateFilename == 'custom_template.mako'
def testEscapeJavascript(self): # Don't escape alphanumeric characters alphaNumString = 'abcxyz0189ABCXYZ' self.assertEqual( WebrootBase._escapeJavascript(alphaNumString), alphaNumString ) # Do escape everything else dangerString = 'ab\'"<;>\\YZ' self.assertEqual( WebrootBase._escapeJavascript(dangerString), 'ab\\u0027\\u0022\\u003C\\u003B\\u003E\\u005CYZ' )
def testEscapeJavascript(self): # Don't escape alphanumeric characters alphaNumString = 'abcxyz0189ABCXYZ' self.assertEqual( WebrootBase._escapeJavascript(alphaNumString), alphaNumString ) # Do escape everything else dangerString = 'ab\'"<;>\\YZ' self.assertEqual( WebrootBase._escapeJavascript(dangerString), 'ab\\u0027\\u0022\\u003C\\u003B\\u003E\\u005CYZ' )
def load(self, info): getPlugin('gravatar').load(info) getPlugin('jobs').load(info) getPlugin('worker').load(info) getPlugin('thumbnails').load(info) mail_utils.addTemplateDirectory(os.path.join(_HERE, 'mail_templates')) ModelImporter.registerModel('challenge', Challenge, 'covalic') ModelImporter.registerModel('phase', Phase, 'covalic') ModelImporter.registerModel('submission', Submission, 'covalic') resource.allowedSearchTypes.add('challenge.covalic') info['apiRoot'].challenge = ChallengeResource() info['apiRoot'].challenge_phase = PhaseResource() info['apiRoot'].covalic_submission = SubmissionResource() webroot = WebrootBase(os.path.join(_HERE, 'webroot.mako')) webroot.updateHtmlVars({ 'pluginCss': [ plugin for plugin in loadedPlugins() if os.path.exists(os.path.join( STATIC_ROOT_DIR, 'built', 'plugins', plugin, 'plugin.min.css')) ], 'pluginJs': [ plugin for plugin in loadedPlugins() if os.path.exists(os.path.join( STATIC_ROOT_DIR, 'built', 'plugins', plugin, 'plugin.min.js')) ] }) registerPluginWebroot(webroot, 'covalic') events.bind('jobs.job.update', 'covalic', onJobUpdate) events.bind('model.setting.validate', 'covalic', validateSettings) events.bind('model.challenge_challenge.save.after', 'covalic', challengeSaved) events.bind('model.challenge_phase.save.after', 'covalic', onPhaseSave) events.bind('model.user.save.after', 'covalic', onUserSave)
def load(info): # set the title of the HTML pages info['serverRoot'].updateHtmlVars({'title': 'ISIC Archive'}) # add event listeners events.bind('rest.get.describe/:resource.after', 'onDescribeResource', onDescribeResource) events.bind('model.job.save', 'onJobSave', onJobSave) # add custom model searching resource.allowedSearchTypes.update({ 'image.isic_archive', 'study.isic_archive', }) # register licenses for template usage mail_utils.addTemplateDirectory(os.path.join(info['pluginRootDir'], 'server', 'license_templates'), prepend=True) externalWebroot = WebrootBase( os.path.join(info['pluginRootDir'], 'server', 'webroot.mako')) externalWebroot.updateHtmlVars({ 'apiRoot': '/api/v1', 'staticRoot': '/static', 'title': 'ISIC Archive' }) registerPluginWebroot(externalWebroot, info['name']) integrationWebroot = WebrootBase( os.path.join(info['pluginRootDir'], 'server', 'webroot_integration.mako')) integrationWebroot.updateHtmlVars(externalWebroot.vars) registerPluginWebroot(integrationWebroot, info['name'] + '_integration') # add static file serving info['config']['/uda'] = { 'tools.staticdir.on': 'True', 'tools.staticdir.dir': os.path.join(info['pluginRootDir'], 'custom') } # add dynamic root routes # root endpoints -> where a user may go and expect a UI class Root(object): pass legacyWebroot = Root() legacyWebroot.segment = staticFile( os.path.join(info['pluginRootDir'], 'custom', 'phase1.html')) registerPluginWebroot(legacyWebroot, 'markup') # create all necessary users, groups, collections, etc provisionDatabase() # add api routes # remove docs for default Girder API, to simplify page clearRouteDocs() # Customize API docs template baseTemplateFilename = info['apiRoot'].templateFilename info['apiRoot'].updateHtmlVars( {'baseTemplateFilename': baseTemplateFilename}) templatePath = os.path.join(info['pluginRootDir'], 'server', 'isic_api_docs.mako') info['apiRoot'].setTemplatePath(templatePath) # TODO: nest these under a "/isic" path? info['apiRoot'].annotation = api.AnnotationResource() info['apiRoot'].dataset = api.DatasetResource() info['apiRoot'].image = api.ImageResource() info['apiRoot'].redirects = api.RedirectsResource() info['apiRoot'].segmentation = api.SegmentationResource() info['apiRoot'].study = api.StudyResource() info['apiRoot'].task = api.TaskResource() api.attachUserApi(info['apiRoot'].user)