hs: handle case where query is <= 2 characters

master
mutantmonkey 2013-09-07 15:58:47 -07:00
parent cac9258c86
commit b8dde03000
2 changed files with 12 additions and 0 deletions

View File

@ -21,6 +21,11 @@ def search(query):
except (web.ConnectionError, web.HTTPError):
raise GrumbleError("THE INTERNET IS FUCKING BROKEN. Please try again later.")
# apparently the failure mode if you search for <3 characters is a blank
# XML page...
if len(r) <= 0:
return False
xml = lxml.etree.fromstring(r.encode('utf-8'))
results = xml.findall('{0}directory-entries/{0}entry'.format(NS))
if len(results) <= 0:

View File

@ -40,6 +40,13 @@ class TestHs(unittest.TestCase):
out = self.phenny.reply.call_args[0][0]
self.assertRegex(out, pattern)
def test_2char(self):
input = Mock(group=lambda x: 'hs')
hs(self.phenny, input)
out = self.phenny.reply.call_args[0][0]
self.phenny.reply.assert_called_once_with("No results found")
def test_none(self):
input = Mock(group=lambda x: 'THIS_IS_NOT_A_REAL_SEARCH_QUERY')
hs(self.phenny, input)