示例#1
0
文件: default.py 项目: tantalor/emend
def get(handler, response):
  # redirect to emendapp.com
  if not is_dev() and environ.get('HTTP_HOST') == 'emend.appspot.com':
    return handler.redirect('http://www.emendapp.com?'+environ['QUERY_STRING'])
  # get params
  response.url = handler.request.get('url')
  response.original = handler.request.get('original')
  response.proposal = handler.request.get('proposal') or response.original
  response.original_eq_proposal = response.proposal == response.original
  # get a suggestion
  if response.original:
    try:
      response.suggestion = suggest(response.original)
    except KeyError, e:
      logging.warn('Missing credentials: %s', e)
示例#2
0
 def test_no_suggestion(self):
     self.assertEquals(suggest(query=u"nothing to suggest"), None)
示例#3
0
 def test_combination(self):
     query = u"it's a ant"
     expected = u"its an ant"
     suggestion = suggest(query=query)
     self.assertEquals(suggestion, expected)
示例#4
0
 def test_a_vowel_sound(self):
     query = u"a ant"
     expected = u"an ant"
     suggestion = suggest(query=query)
     self.assertEquals(suggestion, expected)
示例#5
0
 def test_apostrophe_s_unicode(self):
     query = u"in my 20’s"
     expected = u"in my 20s"
     suggestion = suggest(query=query)
     self.assertEquals(suggestion, expected)
示例#6
0
 def test_spelling(self):
     query = u"Lunar Reconnoissance Orbiter"
     expected = u"Lunar Reconnaissance Orbiter"
     suggestion = suggest(query=query)
     self.assertEquals(suggestion, expected)
示例#7
0
 def test_ascii_fails(self):
     self.failUnlessRaises(TypeError, lambda: suggest("ascii"))