def testgetMessagesByKey(self): messageManager = messagemanager.MessageManager( open( os.path.join(grok.app.GROK_HOME, 'resources/messages/us/messages.json')).read()) messageOut = messageManager.getMessagesByKey('site') self.assertDictEqual(messageOut, self.messageManager_data['site'])
def testGetMessagesForTemplate(self): messageManager = messagemanager.MessageManager( open( os.path.join(grok.app.GROK_HOME, 'resources/messages/us/messages.json')).read()) messageOut = messageManager.getMessagesForTemplate('pages/terms.html') self.assertDictEqual(messageOut, {})
def testgetMessagesByKey(self): """ Test extracting values explicitly by message key """ messageManager = messagemanager.MessageManager( open(os.path.join(grok.app.GROK_HOME, 'resources/messages/us/messages.json')).read() ) messageOut = messageManager.getMessagesByKey('site') messages = json.load(open(os.path.join(grok.app.GROK_HOME, 'resources/messages/us/messages.json'))) self.assertDictEqual(messageOut, messages["site"])
def POST(self): # pylint: disable=R0201,C0103 """ Handles calls from clients for messages. Expects to received batched requests, keyed by the name of the template used to identify responses. """ global messageManager # pylint: disable=W0603 data = web.input() messagesOut = {} if grok.app.DEBUG_LEVEL > 0: # When debugging, read the file and create new MessageManager on # every request so we can change messages.json on the fly. with open( os.path.join(grok.app.GROK_HOME, "resources/messages/us/messages.json")) as f: messageManager = messagemanager.MessageManager(f.read()) # Make sure we have the latest version of configuration grok.app.config.loadConfig() for templateKey in data: templateLocation = data[templateKey] if templateKey == "explicit": # The templateKey is either an id or the string "explicit", which means # that the client wants to identify the key directly, not by template, # which is easy enough. for templateId in templateLocation.split(","): messagesOut[templateId] = messageManager.getMessagesByKey( templateId) else: # To get the right relative lookup path for messages.json, we"ll # remove known template paths. baseUrl = grok.app.config.get("web", "base_url") path = templateLocation\ .replace(baseUrl + "/static/js/program/templates/", "") msgs = messageManager.getMessagesForTemplate(path) messagesOut[templateKey] = msgs web.header("Content-Type", "application/json; charset=UTF-8", True) return encodeJson(messagesOut)
"/_models", models_api.app, "/_notifications", notifications_api.app, "/_settings", settings_api.app, "/_support", support_api.app, "/_update", update_api.app, "/_wufoo", wufoo_api.app, ) messageManager = messagemanager.MessageManager( open( os.path.join(grok.app.GROK_HOME, "resources/messages/us/messages.json")).read()) # Get the build sha to display in web ui for easy debugging try: buildSha = open(os.path.join(grok.app.GROK_HOME, "static/grok.sha")).read() except IOError: try: buildSha = check_output(["git", "rev-parse", "--verify", "HEAD"]) except CalledProcessError: buildSha = "0" def _getInstanceMetadata(): """ Get and cache metadata about the instance this Grok server is running on