ShrinkUrl: Remove goo.gl (buggy) and fix tests.

This commit is contained in:
Valentin Lorentz 2015-04-19 12:56:39 +02:00
parent d8aa4f3181
commit f293cfaeda
3 changed files with 8 additions and 46 deletions

View File

@ -42,11 +42,11 @@ def configure(advanced):
conf.supybot.plugins.ShrinkUrl.shrinkSnarfer.setValue(True)
class ShrinkService(registry.OnlySomeStrings):
"""Valid values include 'tiny', 'goo', 'ur1', and 'x0'."""
validStrings = ('tiny', 'goo', 'ur1', 'x0')
"""Valid values include 'tiny', 'ur1', and 'x0'."""
validStrings = ('tiny', 'ur1', 'x0')
class ShrinkCycle(registry.SpaceSeparatedListOfStrings):
"""Valid values include 'ln', 'tiny', 'goo', 'ur1', and 'x0'."""
"""Valid values include 'ln', 'tiny', 'ur1', and 'x0'."""
Value = ShrinkService
def __init__(self, *args, **kwargs):

View File

@ -198,39 +198,6 @@ class ShrinkUrl(callbacks.PluginRegexp):
irc.errorPossibleBug(str(e))
tiny = thread(wrap(tiny, ['httpUrl']))
_gooApi = 'https://www.googleapis.com/urlshortener/v1/url'
@retry
def _getGooUrl(self, url):
try:
return self.db.get('goo', url)
except KeyError:
headers = utils.web.defaultHeaders.copy()
headers['content-type'] = 'application/json'
data = json.dumps({'longUrl': url})
text = utils.web.getUrl(self._gooApi, data=data, headers=headers)
if sys.version_info[0] >= 3 and isinstance(text, bytes):
text = text.decode()
googl = json.loads(text)['id']
if googl:
self.db.set('goo', url, googl)
return googl
else:
raise ShrinkError(text)
def goo(self, irc, msg, args, url):
"""<url>
Returns an goo.gl version of <url>.
"""
try:
goourl = self._getGooUrl(url)
m = irc.reply(goourl)
if m is not None:
m.tag('shrunken')
except ShrinkError as e:
irc.error(str(e))
goo = thread(wrap(goo, ['httpUrl']))
_ur1Api = 'http://ur1.ca/'
_ur1Regexp = re.compile(r'<a href="(?P<url>[^"]+)">')
@retry

View File

@ -39,11 +39,9 @@ class ShrinkUrlTestCase(ChannelPluginTestCase):
'term=all+your+base+are+belong+to+us'
tests = {'tiny': [(sfUrl, r'http://tinyurl.com/b7wyvfz'),
(udUrl, r'http://tinyurl.com/u479')],
'goo': [(sfUrl, r'http://goo.gl/3c59N'),
(udUrl, r'http://goo.gl/ocTga')],
'ur1': [(sfUrl, r'http://ur1.ca/9xl25'),
'ur1': [(sfUrl, r'http://ur1.ca/ceqh8'),
(udUrl, r'http://ur1.ca/9xl9k')],
'x0': [(sfUrl, r'http://x0.no/0l2j'),
'x0': [(sfUrl, r'http://x0.no/a53s'),
(udUrl, r'http://x0.no/0l2k')]
}
if network:
@ -60,12 +58,12 @@ class ShrinkUrlTestCase(ChannelPluginTestCase):
origsnarfer = snarfer()
try:
self.assertNotError(
'config plugins.ShrinkUrl.serviceRotation goo x0')
'config plugins.ShrinkUrl.serviceRotation tiny x0')
self.assertError(
'config plugins.ShrinkUrl.serviceRotation goo x1')
'config plugins.ShrinkUrl.serviceRotation tiny x1')
snarfer.setValue(True)
self.assertSnarfRegexp(self.udUrl, r'.*%s.* \(at' %
self.tests['goo'][1][1])
self.tests['tiny'][1][1])
self.assertSnarfRegexp(self.udUrl, r'.*%s.* \(at' %
self.tests['x0'][1][1])
finally:
@ -89,9 +87,6 @@ class ShrinkUrlTestCase(ChannelPluginTestCase):
def testTinysnarf(self):
self._snarf('tiny')
def testGoosnarf(self):
self._snarf('goo')
def testUr1snarf(self):
self._snarf('ur1')