hs: handle case where query is <= 2 characters
parent
cac9258c86
commit
b8dde03000
|
@ -21,6 +21,11 @@ def search(query):
|
||||||
except (web.ConnectionError, web.HTTPError):
|
except (web.ConnectionError, web.HTTPError):
|
||||||
raise GrumbleError("THE INTERNET IS FUCKING BROKEN. Please try again later.")
|
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'))
|
xml = lxml.etree.fromstring(r.encode('utf-8'))
|
||||||
results = xml.findall('{0}directory-entries/{0}entry'.format(NS))
|
results = xml.findall('{0}directory-entries/{0}entry'.format(NS))
|
||||||
if len(results) <= 0:
|
if len(results) <= 0:
|
||||||
|
|
|
@ -40,6 +40,13 @@ class TestHs(unittest.TestCase):
|
||||||
out = self.phenny.reply.call_args[0][0]
|
out = self.phenny.reply.call_args[0][0]
|
||||||
self.assertRegex(out, pattern)
|
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):
|
def test_none(self):
|
||||||
input = Mock(group=lambda x: 'THIS_IS_NOT_A_REAL_SEARCH_QUERY')
|
input = Mock(group=lambda x: 'THIS_IS_NOT_A_REAL_SEARCH_QUERY')
|
||||||
hs(self.phenny, input)
|
hs(self.phenny, input)
|
||||||
|
|
Loading…
Reference in New Issue